From 028f8c77181874e24c313423e4dbe250c2718355 Mon Sep 17 00:00:00 2001 From: seeun <78543382+isprogrammingfun@users.noreply.github.com> Date: Sun, 13 Aug 2023 19:09:52 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20=ED=9A=8C=EA=B3=A0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=ED=86=B5=ED=95=A9=EA=B3=BC=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=EB=90=9C=20=EB=A1=9C=EC=A7=81=EB=93=A4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#582)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [refactor] 회고탭 API 응답에 retrospectId 추가 * [refactor] 일반 회고 조회, 검색 시 회고 조회 API 통합 * [refactor] 회고수정, 삭제 API 수정 * [refactor] 문서 변경, 관련 수정할 지점 수정 * [refactor] readOnly True 제거 --- .../controller/RetrospectController.java | 28 ++---- .../retrospect/dto/req/ReqDeleteRetroDto.java | 12 +-- .../retrospect/dto/req/ReqEditRetroDto.java | 9 +- .../retrospect/dto/req/ReqGetRetroDto.java | 14 +-- .../retrospect/dto/req/ReqSearchRetroDto.java | 13 --- .../retrospect/dto/resp/RespGetInfoDto.java | 10 ++- .../retrospect/dto/resp/RespGetRetroDto.java | 12 +-- .../dto/resp/RespGetSearchRetroDto.java | 45 ---------- .../RetrospectCustomRepository.java | 4 - .../RetrospectCustomRepositoryImpl.java | 15 ---- .../retrospect/RetrospectRepository.java | 2 + .../retrospect/service/RetrospectService.java | 46 +++++----- src/main/resources/static/docs/Alarm-API.html | 2 +- src/main/resources/static/docs/Auth-API.html | 2 +- src/main/resources/static/docs/Diary-API.html | 2 +- .../resources/static/docs/MyPage-API.html | 2 +- .../resources/static/docs/OnBoarding-API.html | 2 +- src/main/resources/static/docs/Overview.html | 2 +- .../resources/static/docs/Retrospect-API.html | 89 ++++++------------- .../resources/static/docs/Search-API.html | 2 +- .../resources/static/docs/Sponsor-API.html | 2 +- src/main/resources/static/docs/api.html | 89 ++++++------------- .../controller/RetrospectControllerTest.java | 42 +++------ 23 files changed, 129 insertions(+), 317 deletions(-) delete mode 100644 src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqSearchRetroDto.java delete mode 100644 src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetSearchRetroDto.java diff --git a/src/main/java/com/nanal/backend/domain/retrospect/controller/RetrospectController.java b/src/main/java/com/nanal/backend/domain/retrospect/controller/RetrospectController.java index 66866a82..7b1c60ce 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/controller/RetrospectController.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/controller/RetrospectController.java @@ -62,32 +62,12 @@ public CommonResponse saveRetrospect(@AuthenticationPrincipal User user, * 수정일 : */ @GetMapping("/retrospect/view") - public CommonResponse getRetrospect(@AuthenticationPrincipal User user, - @Valid ReqGetRetroDto reqGetRetroDto, + public CommonResponse getRetrospect(@Valid ReqGetRetroDto reqGetRetroDto, BindingResult bindingResult) { - - if(bindingResult.hasErrors()) throw new BindingResultException(bindingResult.getFieldErrors()); - - // 요청 날짜 기반으로 회고 조회 - RespGetRetroDto respGetRetroDto = retrospectService.getRetro(user.getSocialId(), reqGetRetroDto); - - return new CommonResponse<>(respGetRetroDto); - } - - /** - * 회고 조회 (검색) - * [GET] /retrospect/search - * 작성자 : 장세은 - * 수정일 : - */ - @GetMapping("/retrospect/search") - public CommonResponse getRetrospectBySearch(@Valid ReqSearchRetroDto reqSearchRetroDto, - BindingResult bindingResult) { - if(bindingResult.hasErrors()) throw new BindingResultException(bindingResult.getFieldErrors()); // 요청 날짜 기반으로 회고 조회 - RespGetSearchRetroDto respGetSearchRetroDto = retrospectService.getRetroBySearch(reqSearchRetroDto); + RespGetRetroDto respGetSearchRetroDto = retrospectService.getRetro(reqGetRetroDto); return new CommonResponse<>(respGetSearchRetroDto); } @@ -184,7 +164,9 @@ public CommonResponse checkExistRetrospect(@AuthenticationPrincipal User user */ @DeleteMapping("/retrospect") public CommonResponse deleteDiary(@AuthenticationPrincipal User user, - @Valid @RequestBody ReqDeleteRetroDto reqDeleteRetroDto) { + @Valid ReqDeleteRetroDto reqDeleteRetroDto, BindingResult bindingResult) { + + if(bindingResult.hasErrors()) throw new BindingResultException(bindingResult.getFieldErrors()); // 요청 날짜 기반으로 회고 삭제 retrospectService.deleteRetro(user.getSocialId(), reqDeleteRetroDto); diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqDeleteRetroDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqDeleteRetroDto.java index 51e3a0d9..7c831296 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqDeleteRetroDto.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqDeleteRetroDto.java @@ -14,14 +14,6 @@ @AllArgsConstructor @Data public class ReqDeleteRetroDto { - @NotNull(message = "fromDate 값이 올바르지 않습니다.") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private LocalDateTime fromDate; - - @NotNull(message = "toDate 값이 올바르지 않습니다.") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private LocalDateTime toDate; - - @NotNull(message = "week 은 비어있을 수 없습니다.") - private Integer week; + @NotNull(message = "retrospectId은 비어있을 수 없습니다.") + private Long retrospectId; } diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqEditRetroDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqEditRetroDto.java index 043cc8dc..e5920e60 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqEditRetroDto.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqEditRetroDto.java @@ -3,12 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.format.annotation.DateTimeFormat; + import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import java.time.LocalDateTime; + @NoArgsConstructor @AllArgsConstructor @Data @@ -18,9 +18,10 @@ public class ReqEditRetroDto { @Size(min = 1, max = 300, message="answer 는 최소 1개, 최대 300개의 문자만 입력 가능합니다.") private String answer; - @NotNull(message = "week은 비어있을 수 없습니다.") - private Integer week; + @NotNull(message = "retrospectId은 비어있을 수 없습니다.") + private Long retrospectId; @NotNull(message = "index는 비어있을 수 없습니다.") private Integer index; + } \ No newline at end of file diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqGetRetroDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqGetRetroDto.java index fbadf7f2..5c0e6cd0 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqGetRetroDto.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqGetRetroDto.java @@ -1,23 +1,13 @@ package com.nanal.backend.domain.retrospect.dto.req; import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; @Data public class ReqGetRetroDto { - @NotNull(message = "fromDate 값이 올바르지 않습니다.") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private LocalDateTime fromDate; + @NotNull(message = "retrospectId은 비어있을 수 없습니다.") + private Long retrospectId; - @NotNull(message = "toDate 값이 올바르지 않습니다.") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private LocalDateTime toDate; - - @NotNull(message = "week 은 비어있을 수 없습니다.") - private Integer week; } diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqSearchRetroDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqSearchRetroDto.java deleted file mode 100644 index d69c7f15..00000000 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/req/ReqSearchRetroDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.nanal.backend.domain.retrospect.dto.req; - -import lombok.Data; - -import javax.validation.constraints.NotNull; - -@Data -public class ReqSearchRetroDto { - - @NotNull(message = "retrospectId은 비어있을 수 없습니다.") - private Long retrospectId; - -} diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetInfoDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetInfoDto.java index 9d47443f..9ba612fb 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetInfoDto.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetInfoDto.java @@ -21,7 +21,10 @@ public class RespGetInfoDto { String nickname; //회고 목적 @NotBlank(message = "list는 비어있을 수 없습니다.") - List existRetrospect; + List retrospectGoal; + + @NotBlank(message = "retrospectId는 비어있을 수 없습니다.") + List retrospectId; //다음 회고까지 남은 날짜 @NotBlank(message = "다음 회고까지 남은 날짜는 비어있을 수 없습니다.") @@ -36,10 +39,11 @@ public class RespGetInfoDto { //키워드 분류하고, 주차별로 나누기 List keywordList; - public static RespGetInfoDto createRespGetInfoDto(String nickname, List existRetrospect, int betweenDate, boolean countRetrospect, List respGetClassifiedKeywordDtos){ + public static RespGetInfoDto createRespGetInfoDto(String nickname, List retrospectGoal, List retrospectId, int betweenDate, boolean countRetrospect, List respGetClassifiedKeywordDtos){ RespGetInfoDto respGetInfoDto = RespGetInfoDto.builder() .nickname(nickname) - .existRetrospect(existRetrospect) + .retrospectGoal(retrospectGoal) + .retrospectId(retrospectId) .betweenDate(betweenDate) .countRetrospect(countRetrospect) .keywordList(respGetClassifiedKeywordDtos) diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetRetroDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetRetroDto.java index 00e1d96e..a2e3a4f2 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetRetroDto.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetRetroDto.java @@ -2,15 +2,12 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.nanal.backend.domain.retrospect.entity.Retrospect; -import com.nanal.backend.domain.retrospect.entity.RetrospectContent; -import com.nanal.backend.domain.retrospect.entity.RetrospectKeyword; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -26,7 +23,9 @@ public class RespGetRetroDto { private List keywords; - public static RespGetRetroDto createRespGetRetroDto(Retrospect selectRetrospect) { + private Integer week; + + public static RespGetRetroDto createRespGetRetroDto(Retrospect selectRetrospect, Integer week) { List retrospectKeywordList = selectRetrospect.getRetrospectKeywords().stream() .map(retrospectKeyword -> new RetrospectKeywordDto(retrospectKeyword)) .collect(Collectors.toList()); @@ -35,11 +34,12 @@ public static RespGetRetroDto createRespGetRetroDto(Retrospect selectRetrospect) .map(retrospectContent -> new RetrospectContentDto(retrospectContent)) .collect(Collectors.toList()); - RespGetRetroDto respGetRetroDto = RespGetRetroDto.builder() + RespGetRetroDto respGetSearchRetroDto = RespGetRetroDto.builder() .writeDate(selectRetrospect.getWriteDate()) .contents(retrospectContentList) .keywords(retrospectKeywordList) + .week(week) .build(); - return respGetRetroDto; + return respGetSearchRetroDto; } } diff --git a/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetSearchRetroDto.java b/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetSearchRetroDto.java deleted file mode 100644 index 787996ad..00000000 --- a/src/main/java/com/nanal/backend/domain/retrospect/dto/resp/RespGetSearchRetroDto.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.nanal.backend.domain.retrospect.dto.resp; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.nanal.backend.domain.retrospect.entity.Retrospect; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.stream.Collectors; - -@Builder -@AllArgsConstructor -@NoArgsConstructor -@Data -public class RespGetSearchRetroDto { - @JsonFormat(pattern = "yyyy-MM-dd") - private LocalDateTime writeDate; - - private List contents; - - private List keywords; - - private Integer week; - - public static RespGetSearchRetroDto createRespGetSearchRetroDto(Retrospect selectRetrospect, Integer week) { - List retrospectKeywordList = selectRetrospect.getRetrospectKeywords().stream() - .map(retrospectKeyword -> new RetrospectKeywordDto(retrospectKeyword)) - .collect(Collectors.toList()); - - List retrospectContentList = selectRetrospect.getRetrospectContents().stream() - .map(retrospectContent -> new RetrospectContentDto(retrospectContent)) - .collect(Collectors.toList()); - - RespGetSearchRetroDto respGetSearchRetroDto = RespGetSearchRetroDto.builder() - .writeDate(selectRetrospect.getWriteDate()) - .contents(retrospectContentList) - .keywords(retrospectKeywordList) - .week(week) - .build(); - return respGetSearchRetroDto; - } -} diff --git a/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepository.java b/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepository.java index b4c03a9d..9a6deb47 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepository.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepository.java @@ -17,10 +17,6 @@ public interface RetrospectCustomRepository { void checkRetroCount(Long memberId, LocalDateTime fromDate, LocalDateTime toDate); - Retrospect getRetrospect(Long memberId, LocalDateTime fromDate, LocalDateTime toDate, Integer week); - - List getRetrospectGoal(Long memberId, LocalDateTime fromDate, LocalDateTime toDate); - List findRetrospectList(Long memberId, LocalDateTime fromDate, LocalDateTime toDate); Optional findRetrospectByMemberAndWriteDate(Long memberId, LocalDateTime startDate, LocalDateTime endDate); diff --git a/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepositoryImpl.java b/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepositoryImpl.java index 1ee7e19f..dac70ea6 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepositoryImpl.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectCustomRepositoryImpl.java @@ -55,21 +55,6 @@ public void checkRetroCount(Long memberId, LocalDateTime fromDate, LocalDateTime if(retrospects.size() >= 5) throw RetrospectAllDoneException.EXCEPTION; } - @Override - public Retrospect getRetrospect(Long memberId, LocalDateTime fromDate, LocalDateTime toDate, Integer week) { - List retrospects = findRetrospectListByMemberAndWriteDate(memberId, fromDate, toDate); - - if(retrospects.size() <= week) throw RetrospectNotFoundException.EXCEPTION; - else return retrospects.get(week); - } - - @Override - public List getRetrospectGoal(Long memberId, LocalDateTime fromDate, LocalDateTime toDate) { - List goals = findRetrospectListByMemberAndWriteDate(memberId, fromDate, toDate); - return goals.stream() - .map(Retrospect::getGoal) - .collect(Collectors.toList()); - } @Override public List findRetrospectList(Long memberId, LocalDateTime fromDate, LocalDateTime toDate) { diff --git a/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectRepository.java b/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectRepository.java index 743ae4d7..72ae50c5 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectRepository.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/repository/retrospect/RetrospectRepository.java @@ -21,6 +21,8 @@ public interface RetrospectRepository extends JpaRepository, R @Query(value = "SELECT * FROM retrospect re WHERE re.member_id = :memberId", nativeQuery = true) List findListByMember(Long memberId); + @Query(value = "SELECT * FROM retrospect re WHERE re.member_id = :memberId And re.retrospect_id = :retrospectId", nativeQuery = true) + Retrospect findRetrospectByMemberAndRetrospectId(Long memberId, Long retrospectId); @Query(value = "SELECT COUNT(*) + 1 FROM retrospect re WHERE re.write_date < :writeDate AND write_date > :startOfMonth", nativeQuery = true) int getWeekSequence(LocalDateTime writeDate, LocalDateTime startOfMonth); diff --git a/src/main/java/com/nanal/backend/domain/retrospect/service/RetrospectService.java b/src/main/java/com/nanal/backend/domain/retrospect/service/RetrospectService.java index cbcbf947..65eab0e8 100644 --- a/src/main/java/com/nanal/backend/domain/retrospect/service/RetrospectService.java +++ b/src/main/java/com/nanal/backend/domain/retrospect/service/RetrospectService.java @@ -51,7 +51,6 @@ public class RetrospectService { private static final int FREQUENCY_LOW = 1; @Counted("retrospect.api.count") - @Transactional(readOnly = true) public RespGetInfoDto getInfo(String socialId, ReqGetInfoDto reqGetInfoDto) { // socialId 로 유저 조회 Member member = memberRepository.findBySocialId(socialId).orElseThrow(() -> MemberAuthException.EXCEPTION); @@ -65,7 +64,7 @@ public void saveRetrospect(String socialId, ReqSaveRetroDto reqSaveRetroDto) { // socialId 로 유저 조회 Member member = memberRepository.findBySocialId(socialId).orElseThrow(() -> MemberAuthException.EXCEPTION); - //회고 작성 가능성 검증 +// //회고 작성 가능성 검증 checkRetrospectWritable(member, reqSaveRetroDto.getCurrentDate(), reqSaveRetroDto.getContents()); // 회고 Entity 생성 @@ -77,29 +76,15 @@ public void saveRetrospect(String socialId, ReqSaveRetroDto reqSaveRetroDto) { //회고 저장 후 일주일 일기 리스트 editstatus 변경 changeDiaryEditStatus(member, reqSaveRetroDto); } - @Counted("retrospect.api.count") - @Transactional(readOnly = true) - public RespGetRetroDto getRetro(String socialId, ReqGetRetroDto reqGetRetroDto) { - // socialId 로 유저 조회 - Member member = memberRepository.findBySocialId(socialId).orElseThrow(() -> MemberAuthException.EXCEPTION); - - //조회할 회고 찾기 - Retrospect selectRetrospect = retrospectRepository.getRetrospect(member.getMemberId(), reqGetRetroDto.getFromDate(), - reqGetRetroDto.getToDate(), reqGetRetroDto.getWeek()); - - // 몇번째 회고인지 조회한 후, 회고 리스트로 반환값 생성 - return RespGetRetroDto.createRespGetRetroDto(selectRetrospect); - } - // 기존 회고 조회를 이 API와 통합할 예정 @Counted("retrospect.api.count") - public RespGetSearchRetroDto getRetroBySearch(ReqSearchRetroDto reqSearchRetroDto) { + public RespGetRetroDto getRetro(ReqGetRetroDto reqSearchRetroDto) { //조회할 회고 찾기 Retrospect selectRetrospect = retrospectRepository.findById(reqSearchRetroDto.getRetrospectId()).orElseThrow(() -> RetrospectNotFoundException.EXCEPTION); // 몇 주차인지 계산 Integer week = countWeek(selectRetrospect.getWriteDate()); // 몇번째 회고인지 조회한 후, 회고 리스트로 반환값 생성 - return RespGetSearchRetroDto.createRespGetSearchRetroDto(selectRetrospect, week); + return RespGetRetroDto.createRespGetRetroDto(selectRetrospect, week); } @Counted("retrospect.api.count") @@ -113,8 +98,7 @@ public void editRetrospect(String socialId, ReqEditRetroDto reqEditRetroDto) { checkWriteTime(member, currentDate); //조회할 회고 찾기 - Retrospect selectRetrospect = retrospectRepository.getRetrospect(member.getMemberId(), currentDate.toLocalDate().atStartOfDay().withDayOfMonth(1), - currentDate.toLocalDate().atStartOfDay().withDayOfMonth(LocalDate.now().lengthOfMonth()), reqEditRetroDto.getWeek()); + Retrospect selectRetrospect = retrospectRepository.findRetrospectByMemberAndRetrospectId(member.getMemberId(), reqEditRetroDto.getRetrospectId()); selectRetrospect.changeAnswer(reqEditRetroDto); } @@ -201,7 +185,7 @@ public void deleteRetro(String socialId, ReqDeleteRetroDto reqDeleteRetroDto) { // socialId 로 유저 조회 Member member = memberRepository.findBySocialId(socialId).orElseThrow(() -> MemberAuthException.EXCEPTION); // 삭제할 회고 가져오기 - Retrospect deleteRetro = retrospectRepository.getRetrospect(member.getMemberId(), reqDeleteRetroDto.getFromDate(), reqDeleteRetroDto.getToDate(), reqDeleteRetroDto.getWeek()); + Retrospect deleteRetro = retrospectRepository.findRetrospectByMemberAndRetrospectId(member.getMemberId(), reqDeleteRetroDto.getRetrospectId()); // 기존 회고 삭제 delete(member, deleteRetro); } @@ -209,8 +193,10 @@ public void deleteRetro(String socialId, ReqDeleteRetroDto reqDeleteRetroDto) { //===편의 메서드===// private RespGetInfoDto getRespGetInfoDto (ReqGetInfoDto reqGetInfoDto, Member member) { LocalDateTime currentDate = LocalDateTime.now(); - // 선택한 월에 있는 회고 기록 ( 어떤 회고 목적을 선택했는가 ) - List existRetrospect = retrospectRepository.getRetrospectGoal(member.getMemberId(), reqGetInfoDto.getFromDate(), reqGetInfoDto.getToDate()); + // 선택한 월에 있는 회고 기록 ( 어떤 회고 목적을 선택했는가, 회고 Id ) + List existRetrospect = retrospectRepository.findRetrospectListByMemberAndWriteDate(member.getMemberId(), reqGetInfoDto.getFromDate(), reqGetInfoDto.getToDate()); + List retrospectGoal = getRetrospectGoal(existRetrospect); + List retrospectId = getRetrospectId(existRetrospect); //회고 개수가 5개인지 5개 아니면 true, 이상이면 false boolean isRetroNumberNotFive = retrospectRepository.checkRetroNotOverFive(member.getMemberId(), reqGetInfoDto.getFromDate(), reqGetInfoDto.getToDate()); // 회고 요일까지 남은 날짜 @@ -220,7 +206,7 @@ private RespGetInfoDto getRespGetInfoDto (ReqGetInfoDto reqGetInfoDto, Member me // 회고 주제별로 분류 후 주차별로 분류 List respGetClassifiedKeywordDtos = getKeyword(member, reqGetInfoDto.getFromDate(), reqGetInfoDto.getToDate()); - return RespGetInfoDto.createRespGetInfoDto(member.getNickname(),existRetrospect, betweenDate, isRetroNumberNotFive, respGetClassifiedKeywordDtos); + return RespGetInfoDto.createRespGetInfoDto(member.getNickname(),retrospectGoal, retrospectId, betweenDate, isRetroNumberNotFive, respGetClassifiedKeywordDtos); } // 회고 주차 반환 private Integer countWeek(LocalDateTime writeDate) { @@ -456,4 +442,16 @@ private void delete(Member member, Retrospect retrospect) { retrospectRepository.delete(retrospect); } } + + private List getRetrospectGoal(List retrospects) { + return retrospects.stream() + .map(Retrospect::getGoal) + .collect(Collectors.toList()); + } + + private List getRetrospectId(List retrospects) { + return retrospects.stream() + .map(Retrospect::getRetrospectId) + .collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/src/main/resources/static/docs/Alarm-API.html b/src/main/resources/static/docs/Alarm-API.html index 981656ca..1045ceb6 100644 --- a/src/main/resources/static/docs/Alarm-API.html +++ b/src/main/resources/static/docs/Alarm-API.html @@ -648,7 +648,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Auth-API.html b/src/main/resources/static/docs/Auth-API.html index 65f07196..40c13361 100644 --- a/src/main/resources/static/docs/Auth-API.html +++ b/src/main/resources/static/docs/Auth-API.html @@ -1029,7 +1029,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Diary-API.html b/src/main/resources/static/docs/Diary-API.html index c69b01cd..520c3c9b 100644 --- a/src/main/resources/static/docs/Diary-API.html +++ b/src/main/resources/static/docs/Diary-API.html @@ -1305,7 +1305,7 @@

Response fields

diff --git a/src/main/resources/static/docs/MyPage-API.html b/src/main/resources/static/docs/MyPage-API.html index 96d0118a..93aacafd 100644 --- a/src/main/resources/static/docs/MyPage-API.html +++ b/src/main/resources/static/docs/MyPage-API.html @@ -1275,7 +1275,7 @@

Response fields

diff --git a/src/main/resources/static/docs/OnBoarding-API.html b/src/main/resources/static/docs/OnBoarding-API.html index 85e2cc6d..90bff449 100644 --- a/src/main/resources/static/docs/OnBoarding-API.html +++ b/src/main/resources/static/docs/OnBoarding-API.html @@ -542,7 +542,7 @@

Response fields diff --git a/src/main/resources/static/docs/Overview.html b/src/main/resources/static/docs/Overview.html index 0cc994e8..3300dc25 100644 --- a/src/main/resources/static/docs/Overview.html +++ b/src/main/resources/static/docs/Overview.html @@ -659,7 +659,7 @@

Retrospect Status Codes

diff --git a/src/main/resources/static/docs/Retrospect-API.html b/src/main/resources/static/docs/Retrospect-API.html index ca179ced..43c7152c 100644 --- a/src/main/resources/static/docs/Retrospect-API.html +++ b/src/main/resources/static/docs/Retrospect-API.html @@ -508,7 +508,7 @@

HTTP response

HTTP/1.1 200 OK
 Content-Type: application/json;charset=UTF-8
-Content-Length: 1188
+Content-Length: 1219
 
 {
   "isSuccess" : true,
@@ -516,7 +516,8 @@ 

HTTP response

"message" : "요청에 성공하였습니다.", "result" : { "nickname" : "사용자 닉네임", - "existRetrospect" : [ "자아탐색", "성취확인" ], + "retrospectGoal" : [ "자아탐색", "성취확인" ], + "retrospectId" : [ 1, 2 ], "betweenDate" : 6, "countRetrospect" : true, "keywordList" : [ { @@ -597,11 +598,16 @@

Response fields

사용자 닉네임

-

result.existRetrospect

+

result.retrospectGoal

Array

회고 목적

+

result.retrospectId

+

Array

+

회고 ID

+ +

result.betweenDate

Number

다음 회고까지 남은 날

@@ -793,7 +799,7 @@

Retrospect 회고 조회

HTTP request

-
GET /retrospect/view?fromDate=2023-04-01T00%3A00%3A00&toDate=2023-01-30T00%3A00%3A00&week=0 HTTP/1.1
+
GET /retrospect/view?retrospectId=1 HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Token: ACCESS_TOKEN
 Host: localhost:8080
@@ -836,16 +842,8 @@

Request parameters

-

fromDate

-

처음 날짜

- - -

toDate

-

마지막 날짜

- - -

week

-

회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)

+

retrospectId

+

회고 ID

@@ -856,7 +854,7 @@

HTTP response

HTTP/1.1 200 OK
 Content-Type: application/json;charset=UTF-8
-Content-Length: 995
+Content-Length: 1012
 
 {
   "isSuccess" : true,
@@ -883,7 +881,8 @@ 

HTTP response

}, { "classify" : "돌아보니, 다른 의미로 다가온 기억", "keyword" : "키워드3" - } ] + } ], + "week" : 1 } }
@@ -945,6 +944,11 @@

Response fields

String

분류된 키워드

+ +

result.week

+

Number

+

주차

+
@@ -959,12 +963,12 @@

HTTP request

PUT /retrospect HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Token: ACCESS_TOKEN
-Content-Length: 64
+Content-Length: 72
 Host: localhost:8080
 
 {
   "answer" : "수정답변",
-  "week" : 0,
+  "retrospectId" : 1,
   "index" : 0
 }
@@ -1013,9 +1017,9 @@

Request fields

수정된 회고 질문에 대한 답변

-

week

+

retrospectId

Number

-

회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)

+

회고 ID

index

@@ -1891,17 +1895,10 @@

Retrospect 회고 삭제

HTTP request

-
DELETE /retrospect HTTP/1.1
+
DELETE /retrospect?retrospectId=1 HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Token: ACCESS_TOKEN
-Content-Length: 94
-Host: localhost:8080
-
-{
-  "fromDate" : "2023-04-01T00:00:00",
-  "toDate" : "2023-04-30T00:00:00",
-  "week" : 0
-}
+Host: localhost:8080
@@ -1928,37 +1925,7 @@

Request headers

Request fields

- ----- - - - - - - - - - - - - - - - - - - - - - - - - -
PathTypeDescription

fromDate

String

처음 날짜

toDate

String

마지막 날짜

week

Number

회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)

+

HTTP response

@@ -2017,7 +1984,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Search-API.html b/src/main/resources/static/docs/Search-API.html index 54e56f69..82e3a28d 100644 --- a/src/main/resources/static/docs/Search-API.html +++ b/src/main/resources/static/docs/Search-API.html @@ -789,7 +789,7 @@

Response fields

diff --git a/src/main/resources/static/docs/Sponsor-API.html b/src/main/resources/static/docs/Sponsor-API.html index 19e2673c..abd920d1 100644 --- a/src/main/resources/static/docs/Sponsor-API.html +++ b/src/main/resources/static/docs/Sponsor-API.html @@ -563,7 +563,7 @@ diff --git a/src/main/resources/static/docs/api.html b/src/main/resources/static/docs/api.html index eb961b13..028c6178 100644 --- a/src/main/resources/static/docs/api.html +++ b/src/main/resources/static/docs/api.html @@ -3386,7 +3386,7 @@

HTTP/1.1 200 OK
 Content-Type: application/json;charset=UTF-8
-Content-Length: 1188
+Content-Length: 1219
 
 {
   "isSuccess" : true,
@@ -3394,7 +3394,8 @@ 

사용자 닉네임

-

result.existRetrospect

+

result.retrospectGoal

Array

회고 목적

+

result.retrospectId

+

Array

+

회고 ID

+ +

result.betweenDate

Number

다음 회고까지 남은 날

@@ -3671,7 +3677,7 @@

HTTP request

@@ -3837,12 +3841,12 @@

PUT /retrospect HTTP/1.1 Content-Type: application/json;charset=UTF-8 Token: ACCESS_TOKEN -Content-Length: 64 +Content-Length: 72 Host: localhost:8080 { "answer" : "수정답변", - "week" : 0, + "retrospectId" : 1, "index" : 0 }

@@ -3891,9 +3895,9 @@

수정된 회고 질문에 대한 답변

-

week

+

retrospectId

Number

-

회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)

+

회고 ID

index

@@ -4769,17 +4773,10 @@

HTTP request

-
DELETE /retrospect HTTP/1.1
+
DELETE /retrospect?retrospectId=1 HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Token: ACCESS_TOKEN
-Content-Length: 94
-Host: localhost:8080
-
-{
-  "fromDate" : "2023-04-01T00:00:00",
-  "toDate" : "2023-04-30T00:00:00",
-  "week" : 0
-}
+Host: localhost:8080
@@ -4806,37 +4803,7 @@

Request fields

- ----- - - - - - - - - - - - - - - - - - - - - - - - - -
PathTypeDescription

fromDate

String

처음 날짜

toDate

String

마지막 날짜

week

Number

회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)

+ diff --git a/src/test/java/com/nanal/backend/domain/retrospect/controller/RetrospectControllerTest.java b/src/test/java/com/nanal/backend/domain/retrospect/controller/RetrospectControllerTest.java index 54e6ecb6..cb54a520 100644 --- a/src/test/java/com/nanal/backend/domain/retrospect/controller/RetrospectControllerTest.java +++ b/src/test/java/com/nanal/backend/domain/retrospect/controller/RetrospectControllerTest.java @@ -88,7 +88,7 @@ public class RetrospectControllerTest extends CommonControllerTest { new RespGetClassifiedKeywordDto(classifyDtos3, "돌아보니, 다른 의미로 다가온 기억") )); - RespGetInfoDto respGetInfoDto = new RespGetInfoDto("사용자 닉네임", new ArrayList<>(Arrays.asList("자아탐색", "성취확인")), 6, true, respGetClassifiedKeywordDtos); + RespGetInfoDto respGetInfoDto = new RespGetInfoDto("사용자 닉네임", new ArrayList<>(Arrays.asList("자아탐색", "성취확인")), new ArrayList<>(Arrays.asList(1L,2L)), 6, true, respGetClassifiedKeywordDtos); given(retrospectService.getInfo(any(), any())).willReturn(respGetInfoDto); //when @@ -117,7 +117,8 @@ public class RetrospectControllerTest extends CommonControllerTest { fieldWithPath("code").description("상태 코드"), fieldWithPath("message").description("결과 메시지"), fieldWithPath("result.nickname").description("사용자 닉네임"), - fieldWithPath("result.existRetrospect").description("회고 목적"), + fieldWithPath("result.retrospectGoal").description("회고 목적"), + fieldWithPath("result.retrospectId").description("회고 ID"), fieldWithPath("result.betweenDate").description("다음 회고까지 남은 날"), fieldWithPath("result.countRetrospect").description("회고 개수 체크. 5개 이상일 시, false 보내 줌"), fieldWithPath("result.keywordList[].val").description("키워드 분류 주제"), @@ -175,25 +176,20 @@ public class RetrospectControllerTest extends CommonControllerTest { @Test public void 회고_조회() throws Exception { //given - String fromDate = "2023-04-01T00:00:00"; - String toDate = "2023-01-30T00:00:00"; - int week = 0; List retrospectContentDtos = new ArrayList<>(Arrays.asList(new RetrospectContentDto("이번주 나의 모습은 어땠나요?", "답변1"), new RetrospectContentDto("다른 내 모습도 들려줄래요? 이번주에 찾은 의외의 내 모습이 있다면요?", "답변2"), new RetrospectContentDto("다음주에도 유지하고 싶은 나의 모습이 있을까요? 혹은 새롭게 찾고 싶은 나의 모습이 있다면 무엇인가요?", "답변3"))); List retrospectKeywordDtos = new ArrayList<>(Arrays.asList(new RetrospectKeywordDto("그때 그대로 의미있었던 행복한 기억", "키워드1"), new RetrospectKeywordDto("나를 힘들게 했지만 도움이 된 기억", "키워드2"), new RetrospectKeywordDto("돌아보니, 다른 의미로 다가온 기억", "키워드3"))); - RespGetRetroDto respGetRetroDto = new RespGetRetroDto(LocalDateTime.parse("2023-01-18T00:00:00"), retrospectContentDtos, retrospectKeywordDtos); - given(retrospectService.getRetro(any(), any())).willReturn(respGetRetroDto); + RespGetRetroDto respGetRetroDto = new RespGetRetroDto(LocalDateTime.parse("2023-01-18T00:00:00"), retrospectContentDtos, retrospectKeywordDtos,1); + given(retrospectService.getRetro(any())).willReturn(respGetRetroDto); //when ResultActions actions = mockMvc.perform( get("/retrospect/view") .header("Token", "ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) - .param("fromDate", fromDate) - .param("toDate", toDate) - .param("week", String.valueOf(week)) + .param("retrospectId", String.valueOf(1L)) ); //then @@ -205,9 +201,7 @@ public class RetrospectControllerTest extends CommonControllerTest { headerWithName("Token").description("접근 토큰") ), requestParameters( - parameterWithName("fromDate").description("처음 날짜"), - parameterWithName("toDate").description("마지막 날짜"), - parameterWithName("week").description("회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)") + parameterWithName("retrospectId").description("회고 ID") ), responseFields( fieldWithPath("isSuccess").description("성공 여부"), @@ -217,7 +211,8 @@ public class RetrospectControllerTest extends CommonControllerTest { fieldWithPath("result.contents[].question").description("회고 목적별 질문"), fieldWithPath("result.contents[].answer").description("질문에 대한 답변"), fieldWithPath("result.keywords[].classify").description("회고 과정에서 키워드 분류 기준(감정 분리수거 기능)"), - fieldWithPath("result.keywords[].keyword").description("분류된 키워드") + fieldWithPath("result.keywords[].keyword").description("분류된 키워드"), + fieldWithPath("result.week").description("주차") ) ) ); @@ -226,7 +221,7 @@ public class RetrospectControllerTest extends CommonControllerTest { @Test public void 회고_수정() throws Exception { //given - ReqEditRetroDto reqEditRetroDto = new ReqEditRetroDto("수정답변", 0, 0); + ReqEditRetroDto reqEditRetroDto = new ReqEditRetroDto("수정답변", 1L, 0); willDoNothing().given(retrospectService).editRetrospect(any(), any()); //when @@ -247,7 +242,7 @@ public class RetrospectControllerTest extends CommonControllerTest { ), requestFields( fieldWithPath("answer").description("수정된 회고 질문에 대한 답변"), - fieldWithPath("week").description("회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)"), + fieldWithPath("retrospectId").description("회고 ID"), fieldWithPath("index").description("수정할 회고 질문 (index로 되어있어서 첫번째 질문은 0, 두번째 질문은 1 이런 식으로 보내야 함)") ), responseFields( @@ -554,13 +549,6 @@ public class RetrospectControllerTest extends CommonControllerTest { @Test public void 회고_삭제() throws Exception { //given - String fromDate = "2023-04-01T00:00:00"; - String toDate = "2023-04-30T00:00:00"; - int week = 0; - - ReqDeleteRetroDto input = new ReqDeleteRetroDto(LocalDateTime.parse(fromDate), LocalDateTime.parse(toDate), week); - String body = objectMapper.writeValueAsString(input); - willDoNothing().given(retrospectService).deleteRetro(any(), any()); //when @@ -568,7 +556,7 @@ public class RetrospectControllerTest extends CommonControllerTest { delete("/retrospect") .header("Token", "ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) - .content(body) + .param("retrospectId", String.valueOf(1L)) ); //then @@ -579,10 +567,8 @@ public class RetrospectControllerTest extends CommonControllerTest { requestHeaders( headerWithName("Token").description("접근 토큰") ), - requestFields( - fieldWithPath("fromDate").description("처음 날짜"), - fieldWithPath("toDate").description("마지막 날짜"), - fieldWithPath("week").description("회고 주차 (index로 되어있어서 1주 차는 0, 2주 차는 1 이런 식으로 보내야 함)") + requestParameters( + parameterWithName("retrospectId").description("회고 ID") ), responseFields( fieldWithPath("isSuccess").description("성공 여부"),