Skip to content

Commit

Permalink
[feature/Inhabas#228] 타입 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 committed Feb 16, 2024
1 parent 5e822d3 commit 78ff80e
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public String getContent() {
@Builder
public ContestBoard(
ContestType contestType,
ContestField contestField,
Long contestField,
String title,
String content,
String association,
Expand All @@ -82,7 +82,7 @@ public ContestBoard(
LocalDate dateContestEnd) {

this.contestType = contestType;
this.contestField = contestField;
this.contestField = new ContestField(contestField);
this.title = new Title(title);
this.content = new Content(content);
this.association = new Association(association);
Expand All @@ -107,15 +107,15 @@ public void updateFiles(List<BoardFile> files) {

// 공모전 정보 수정
public void updateContest(
ContestField contestField,
Long contestField,
String title,
String content,
String association,
String topic,
LocalDate dateContestStart,
LocalDate dateContestEnd) {

this.contestField = contestField;
this.contestField = new ContestField(contestField);
this.title = new Title(title);
this.content = new Content(content);
this.association = new Association(association);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class ContestField extends BaseEntity {
@Column(name = "ID")
protected Long id;

public ContestField(Long id) {
this.id = id;
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.inhabas.api.domain.contest.domain.ContestField;
import com.inhabas.api.domain.file.dto.FileDownloadDto;
import io.swagger.v3.oas.annotations.media.Schema;

Expand All @@ -24,7 +23,7 @@ public class ContestBoardDetailDto {

@NotNull @Positive private Long id;

@NotBlank private ContestField contestField;
@NotBlank private Long contestField;

@NotBlank private String title;

Expand Down Expand Up @@ -57,7 +56,7 @@ public class ContestBoardDetailDto {
@Builder
public ContestBoardDetailDto(
Long id,
ContestField contestField,
Long contestField,
String title,
String content,
String writerName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.inhabas.api.domain.contest.domain.ContestField;
import com.inhabas.api.domain.file.dto.FileDownloadDto;

// 공모전 게시판 전체 조회
Expand All @@ -18,7 +17,7 @@
public class ContestBoardDto {
// 공모전 게시판 id
private Long id;
private ContestField contestField;
private Long contestField;
private String title;
private String topic;
private String association;
Expand All @@ -37,7 +36,7 @@ public class ContestBoardDto {
@Builder
public ContestBoardDto(
Long id,
ContestField contestField,
Long contestField,
String title,
String topic,
String association,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.springframework.web.multipart.MultipartFile;

import com.inhabas.api.domain.contest.domain.ContestField;
import com.inhabas.api.domain.contest.domain.valueObject.ContestType;
import org.hibernate.validator.constraints.Length;

Expand All @@ -28,7 +27,7 @@ public class SaveContestBoardDto {
private ContestType contestType;

@NotNull(message = "공모전 분야를 선택해주세요.")
private ContestField contestField;
private Long contestField;

@NotBlank(message = "제목을 입력하세요.")
@Length(max = 100, message = "제목은 최대 100자입니다.")
Expand Down Expand Up @@ -56,7 +55,7 @@ public class SaveContestBoardDto {

@Builder
public SaveContestBoardDto(
ContestField contestField,
Long contestField,
String title,
String content,
String association,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public interface ContestBoardRepositoryCustom {

List<ContestBoard> findAllByContestTypeAndFieldLike(
ContestType contestType, Long contestFieldId, String search);
ContestType contestType, Long contestField, String search);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public List<OrderSpecifier<?>> getAllOrderSpecifiers(Pageable pageable) {
}
// 공모전 검색 및 필터링 기능
public List<ContestBoard> findAllByContestTypeAndFieldLike(
ContestType contestType, Long contestFieldId, String search) {
ContestType contestType, Long contestField, String search) {
BooleanExpression target =
contestTypeEq(contestType)
.and(contestFieldEq(contestFieldId))
.and(contestFieldEq(contestField))
.and(
titleLike(search)
.or(contentLike(search))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface ContestBoardService {

List<ContestBoardDto> getContestBoardsByType(
ContestType contestType, Long contestFieldId, String search);
ContestType contestType, Long contestField, String search);

Long writeContestBoard(
Long memberId, SaveContestBoardDto saveContestBoardDto, ContestType contestType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ public class ContestBoardServiceImpl implements ContestBoardService {
@Override
@Transactional(readOnly = true)
public List<ContestBoardDto> getContestBoardsByType(
ContestType contestType, Long contestFieldId, String search) {
ContestType contestType, Long contestField, String search) {

if (search == null || search.trim().isEmpty()) {
search = "";
}

List<ContestBoard> contestBoardList =
contestBoardRepository.findAllByContestTypeAndFieldLike(
contestType, contestFieldId, search);
contestBoardRepository.findAllByContestTypeAndFieldLike(contestType, contestField, search);

return contestBoardList.stream()
.map(
Expand All @@ -69,7 +68,7 @@ public List<ContestBoardDto> getContestBoardsByType(

return ContestBoardDto.builder()
.id(contestBoard.getId())
.contestField(contestBoard.getContestField())
.contestField(contestBoard.getContestField().getId())
.title(contestBoard.getTitle())
.association(contestBoard.getAssociation())
.topic(contestBoard.getTopic())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.inhabas.api.domain.contest.dto.ContestBoardDetailDto;
import com.inhabas.api.domain.contest.dto.ContestBoardDto;
import com.inhabas.api.domain.contest.dto.SaveContestBoardDto;
import com.inhabas.api.domain.contest.repository.ContestFieldRepository;
import com.inhabas.api.domain.contest.usecase.ContestBoardService;
import com.inhabas.api.global.dto.PageInfoDto;
import com.inhabas.api.global.dto.PagedMemberResponseDto;
Expand Down Expand Up @@ -83,9 +84,9 @@ public class ContestBoardController {
"@boardSecurityChecker.checkMenuAccess(18, T(com.inhabas.api.domain.board.usecase.BoardSecurityChecker).READ_BOARD_LIST)")
public ResponseEntity<PagedMemberResponseDto<ContestBoardDto>> getContestBoard(
@PathVariable("contestType") ContestType contestType,
@Parameter(description = "공모전 분야 ID", example = "1")
@RequestParam(name = "field", required = false)
Long contestFieldId,
@Parameter(description = "공모전 분야", example = "1")
@RequestParam(name = "contestField", required = false)
Long contestField,
@Parameter(description = "페이지", example = "1")
@RequestParam(name = "page", defaultValue = "1")
int page,
Expand All @@ -96,10 +97,9 @@ public ResponseEntity<PagedMemberResponseDto<ContestBoardDto>> getContestBoard(
@RequestParam(name = "search", defaultValue = "")
String search) {

// Page 1부터 시작
Pageable pageable = PageRequest.of(page - 1, size);
Pageable pageable = PageRequest.of(page, size);
List<ContestBoardDto> allDtos =
contestBoardService.getContestBoardsByType(contestType, contestFieldId, search);
contestBoardService.getContestBoardsByType(contestType, contestField, search);
List<ContestBoardDto> pagedDtos = PageUtil.getPagedDtoList(pageable, allDtos);

PageImpl<ContestBoardDto> ContestBoardDtoPage =
Expand All @@ -109,6 +109,8 @@ public ResponseEntity<PagedMemberResponseDto<ContestBoardDto>> getContestBoard(
return ResponseEntity.ok(new PagedMemberResponseDto<>(pageInfoDto, pagedDtos));
}

private final ContestFieldRepository contestFieldRepository;

@Operation(summary = "공모전 게시판 글 생성", description = "공모전 게시판 글 생성 (활동회원 이상)")
@ApiResponses(
value = {
Expand Down Expand Up @@ -140,7 +142,7 @@ public ResponseEntity<PagedMemberResponseDto<ContestBoardDto>> getContestBoard(
public ResponseEntity<Void> writeContestBoard(
@Authenticated Long memberId,
@PathVariable("contestType") ContestType contestType,
@RequestPart("contestFieldId") Long contestFieldId,
@RequestPart("contestField") Long contestField,
@RequestPart("title") String title,
@RequestPart("content") String content,
@RequestPart("association") String association,
Expand All @@ -151,7 +153,7 @@ public ResponseEntity<Void> writeContestBoard(

SaveContestBoardDto saveContestBoardDto =
new SaveContestBoardDto(
contestFieldId,
contestField,
title,
content,
association,
Expand Down Expand Up @@ -244,7 +246,7 @@ public ResponseEntity<ContestBoardDto> updateContestBoard(
@Authenticated Long memberId,
@PathVariable("contestType") ContestType contestType,
@PathVariable Long boardId,
@RequestPart("contestFieldId") Long contestFieldId,
@RequestPart("contestField") Long contestField,
@RequestPart("title") String title,
@RequestPart("content") String content,
@RequestPart("topic") String topic,
Expand All @@ -255,7 +257,7 @@ public ResponseEntity<ContestBoardDto> updateContestBoard(

SaveContestBoardDto saveContestBoardDto =
new SaveContestBoardDto(
contestFieldId,
contestField,
title,
content,
topic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void close() {
public void FieldsAreNullError() {
// given
SaveContestBoardDto saveContestBoardDto =
new SaveContestBoardDto(null, null, null, null, null, null, null);
new SaveContestBoardDto(null, null, null, null, null, null, null, null);

// when
Set<ConstraintViolation<SaveContestBoardDto>> violations =
Expand All @@ -62,7 +62,7 @@ public void FieldsAreNullError() {
public void FieldsAreBlankedError() {
// given
SaveContestBoardDto saveContestBoardDto =
new SaveContestBoardDto(" ", " ", " ", " ", null, null, null);
new SaveContestBoardDto(null, " ", " ", " ", " ", null, null, null);

// when
Set<ConstraintViolation<SaveContestBoardDto>> violations =
Expand All @@ -88,6 +88,7 @@ public void InputsAreExceededError() {
// given
SaveContestBoardDto saveContestBoardDto =
new SaveContestBoardDto(
1L,
"title".repeat(20) + ".",
"content! Cucumber paste has to have a sun-dried, chilled sauerkraut component.",
"Assoc".repeat(20) + ".",
Expand Down Expand Up @@ -115,6 +116,7 @@ public void DeadlineIsOutdatedError() {
// given
SaveContestBoardDto saveContestBoardDto =
new SaveContestBoardDto(
1L,
"title",
"content",
"association",
Expand Down

0 comments on commit 78ff80e

Please sign in to comment.