From 78ff80e608ddc81a9e2559ca671856b9c14bd187 Mon Sep 17 00:00:00 2001 From: skytin1004 Date: Fri, 16 Feb 2024 11:03:15 +0900 Subject: [PATCH] =?UTF-8?q?[feature/Inhabas#228]=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/contest/domain/ContestBoard.java | 8 +++---- .../domain/contest/domain/ContestField.java | 4 ++++ .../contest/dto/ContestBoardDetailDto.java | 5 ++--- .../domain/contest/dto/ContestBoardDto.java | 5 ++--- .../contest/dto/SaveContestBoardDto.java | 5 ++--- .../ContestBoardRepositoryCustom.java | 2 +- .../ContestBoardRepositoryImpl.java | 4 ++-- .../contest/usecase/ContestBoardService.java | 2 +- .../usecase/ContestBoardServiceImpl.java | 7 +++--- .../api/web/ContestBoardController.java | 22 ++++++++++--------- .../dto/SaveContestBoardDtoTest.java | 6 +++-- 11 files changed, 37 insertions(+), 33 deletions(-) diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java index da74b009..1d5f97d1 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestBoard.java @@ -73,7 +73,7 @@ public String getContent() { @Builder public ContestBoard( ContestType contestType, - ContestField contestField, + Long contestField, String title, String content, String association, @@ -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); @@ -107,7 +107,7 @@ public void updateFiles(List files) { // 공모전 정보 수정 public void updateContest( - ContestField contestField, + Long contestField, String title, String content, String association, @@ -115,7 +115,7 @@ public void updateContest( 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); diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestField.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestField.java index 3fbc7ca0..8b5c04a5 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestField.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/domain/ContestField.java @@ -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; } diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDto.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDto.java index 9014ee4f..754f132d 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDetailDto.java @@ -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; @@ -24,7 +23,7 @@ public class ContestBoardDetailDto { @NotNull @Positive private Long id; - @NotBlank private ContestField contestField; + @NotBlank private Long contestField; @NotBlank private String title; @@ -57,7 +56,7 @@ public class ContestBoardDetailDto { @Builder public ContestBoardDetailDto( Long id, - ContestField contestField, + Long contestField, String title, String content, String writerName, diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDto.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDto.java index 59fcd3da..ed147a45 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/ContestBoardDto.java @@ -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; // 공모전 게시판 전체 조회 @@ -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; @@ -37,7 +36,7 @@ public class ContestBoardDto { @Builder public ContestBoardDto( Long id, - ContestField contestField, + Long contestField, String title, String topic, String association, diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java index 2431f0d1..d76142b9 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java @@ -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; @@ -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자입니다.") @@ -56,7 +55,7 @@ public class SaveContestBoardDto { @Builder public SaveContestBoardDto( - ContestField contestField, + Long contestField, String title, String content, String association, diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryCustom.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryCustom.java index a2e156d3..96530e8b 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryCustom.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryCustom.java @@ -8,5 +8,5 @@ public interface ContestBoardRepositoryCustom { List findAllByContestTypeAndFieldLike( - ContestType contestType, Long contestFieldId, String search); + ContestType contestType, Long contestField, String search); } diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java index 0c57b695..b8ae6c25 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/repository/ContestBoardRepositoryImpl.java @@ -57,10 +57,10 @@ public List> getAllOrderSpecifiers(Pageable pageable) { } // 공모전 검색 및 필터링 기능 public List 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)) diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardService.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardService.java index f524da9a..f549fa89 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardService.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardService.java @@ -10,7 +10,7 @@ public interface ContestBoardService { List getContestBoardsByType( - ContestType contestType, Long contestFieldId, String search); + ContestType contestType, Long contestField, String search); Long writeContestBoard( Long memberId, SaveContestBoardDto saveContestBoardDto, ContestType contestType); diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImpl.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImpl.java index c0e0c2dc..4495a5de 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImpl.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/usecase/ContestBoardServiceImpl.java @@ -51,15 +51,14 @@ public class ContestBoardServiceImpl implements ContestBoardService { @Override @Transactional(readOnly = true) public List getContestBoardsByType( - ContestType contestType, Long contestFieldId, String search) { + ContestType contestType, Long contestField, String search) { if (search == null || search.trim().isEmpty()) { search = ""; } List contestBoardList = - contestBoardRepository.findAllByContestTypeAndFieldLike( - contestType, contestFieldId, search); + contestBoardRepository.findAllByContestTypeAndFieldLike(contestType, contestField, search); return contestBoardList.stream() .map( @@ -69,7 +68,7 @@ public List getContestBoardsByType( return ContestBoardDto.builder() .id(contestBoard.getId()) - .contestField(contestBoard.getContestField()) + .contestField(contestBoard.getContestField().getId()) .title(contestBoard.getTitle()) .association(contestBoard.getAssociation()) .topic(contestBoard.getTopic()) diff --git a/resource-server/src/main/java/com/inhabas/api/web/ContestBoardController.java b/resource-server/src/main/java/com/inhabas/api/web/ContestBoardController.java index 3265882c..9cb7817c 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/ContestBoardController.java +++ b/resource-server/src/main/java/com/inhabas/api/web/ContestBoardController.java @@ -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; @@ -83,9 +84,9 @@ public class ContestBoardController { "@boardSecurityChecker.checkMenuAccess(18, T(com.inhabas.api.domain.board.usecase.BoardSecurityChecker).READ_BOARD_LIST)") public ResponseEntity> 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, @@ -96,10 +97,9 @@ public ResponseEntity> getContestBoard( @RequestParam(name = "search", defaultValue = "") String search) { - // Page 1부터 시작 - Pageable pageable = PageRequest.of(page - 1, size); + Pageable pageable = PageRequest.of(page, size); List allDtos = - contestBoardService.getContestBoardsByType(contestType, contestFieldId, search); + contestBoardService.getContestBoardsByType(contestType, contestField, search); List pagedDtos = PageUtil.getPagedDtoList(pageable, allDtos); PageImpl ContestBoardDtoPage = @@ -109,6 +109,8 @@ public ResponseEntity> getContestBoard( return ResponseEntity.ok(new PagedMemberResponseDto<>(pageInfoDto, pagedDtos)); } + private final ContestFieldRepository contestFieldRepository; + @Operation(summary = "공모전 게시판 글 생성", description = "공모전 게시판 글 생성 (활동회원 이상)") @ApiResponses( value = { @@ -140,7 +142,7 @@ public ResponseEntity> getContestBoard( public ResponseEntity 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, @@ -151,7 +153,7 @@ public ResponseEntity writeContestBoard( SaveContestBoardDto saveContestBoardDto = new SaveContestBoardDto( - contestFieldId, + contestField, title, content, association, @@ -244,7 +246,7 @@ public ResponseEntity 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, @@ -255,7 +257,7 @@ public ResponseEntity updateContestBoard( SaveContestBoardDto saveContestBoardDto = new SaveContestBoardDto( - contestFieldId, + contestField, title, content, topic, diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contestBoard/dto/SaveContestBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contestBoard/dto/SaveContestBoardDtoTest.java index eb14f4ed..2ef7c955 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contestBoard/dto/SaveContestBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contestBoard/dto/SaveContestBoardDtoTest.java @@ -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> violations = @@ -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> violations = @@ -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) + ".", @@ -115,6 +116,7 @@ public void DeadlineIsOutdatedError() { // given SaveContestBoardDto saveContestBoardDto = new SaveContestBoardDto( + 1L, "title", "content", "association",