From 91528468dd56a9cb04106d2b2316e5a7fa3ffa5c Mon Sep 17 00:00:00 2001 From: Ohjintaek <116645747+Ohjintaek@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:41:40 +0900 Subject: [PATCH] =?UTF-8?q?[feat/CK-242]=20=EB=A1=9C=EB=93=9C=EB=A7=B5=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=B6=80=EB=B6=84=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=EC=9D=84=20?= =?UTF-8?q?=ED=95=9C=EB=8B=A4=20(#206)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: roadmap 관련 코드 패키지 분리 * refactor: RoadmapCreateService에서 goalRoom 의존성 제거 * refactor: RoadmapReadService에서 goalRoom 의존성 제거 * refactor: RoadmapScheduler에서 goalRoom 의존성 제거 및 테스트코드 패키지 분리 * refactor: Roadmap에서 발생한 예외는 RoaadmapException을 던지도록 수정 * refactor: RoadmapSaveArgumentResolver 의존성 역전 * test: 테스트 코드 수정 * chore: build.gradle 수정 (jacoco 테스트 커버리지) * refactor: roadmap과 roadmapReview에서 member 직접 참조를 삭제 * chore: ScrollResponseMapper common으로 이관 * refactor: 로드맵 삭제 시 하위 골룸 삭제 방식 변경 (OnDelete 옵션 사용) * chore: 패키지 경로 수정 * refactor: dto 패키지 분리 * refactor: Event 객체에서 도메인 직접 전달 제거 * refactor: RoadmapNode에서 RoadmapContent 의존 제거 * refactor: Roadmap과 RoadmapContent, RoadmapReview간 의존 관계 제거 * refactor: Roadmap 생성 시 태그, RoadmapContent 생성 시 노드들을 필수로 넣도록 수정 * test: RoadmapNodes 테스트코드 추가 * refactor: 불필요한 클래스 삭제 * fix: 데이터베이스 무결성 오류 수정 * refactor: 로드맵 삭제 시 연관된 리뷰 삭제를 이벤트로 발행 * refactor: 불필요한 이벤트 호출 제거 --- .../auth/controller/AuthController.java | 4 +- .../auth/infra/NaverOauthNetworkService.java | 2 +- .../RefreshTokenRepositoryImpl.java | 4 +- .../co/kirikiri/auth/service/AuthService.java | 2 +- .../auth/service/JwtTokenProvider.java | 6 +- .../auth/service/NaverOauthService.java | 10 +- .../auth/service/OauthNetworkService.java | 2 +- .../common/aop/ExceptionConvertAop.java | 2 +- .../kirikiri/common/config/RedisConfig.java | 2 +- .../co/kirikiri/common/config/WebConfig.java | 4 +- .../controller/GlobalExceptionHandler.java | 2 +- .../common/infra/AmazonS3FileService.java | 6 +- .../common/infra/CloudFrontService.java | 4 +- .../mapper/ScrollResponseMapper.java | 2 +- .../common/service/CacheKeyGenerator.java | 4 +- .../kirikiri/common/service/FileService.java | 2 +- .../controller/GoalRoomController.java | 4 +- .../domain/goalroom/BaseGoalRoomMember.java | 9 +- .../co/kirikiri/domain/goalroom/GoalRoom.java | 35 +- .../domain/goalroom/GoalRoomMembers.java | 6 +- .../goalroom/GoalRoomPendingMember.java | 2 +- .../goalroom/GoalRoomPendingMembers.java | 6 +- .../domain/goalroom/GoalRoomRoadmapNode.java | 7 +- .../domain/goalroom/GoalRoomRoadmapNodes.java | 4 +- .../kirikiri/domain/goalroom/vo/Period.java | 4 +- .../domain/roadmap/RoadmapContents.java | 42 -- .../domain/roadmap/RoadmapReviews.java | 24 - .../member/controller/MemberController.java | 2 +- .../member/domain/EncryptedPassword.java | 4 +- .../kirikiri/member/domain/vo/Identifier.java | 2 +- .../kirikiri/member/domain/vo/Nickname.java | 2 +- .../member/service/MemberService.java | 4 +- .../QuerydslRepositorySupporter.java | 2 +- .../GoalRoomMemberJdbcRepositoryImpl.java | 2 +- .../GoalRoomMemberQueryRepositoryImpl.java | 4 +- .../goalroom/GoalRoomMemberRepository.java | 4 +- .../GoalRoomPendingMemberRepository.java | 4 +- .../goalroom/GoalRoomQueryRepository.java | 11 +- .../goalroom/GoalRoomQueryRepositoryImpl.java | 24 +- .../goalroom/GoalRoomRepository.java | 4 +- .../roadmap/RoadmapContentRepository.java | 18 - .../roadmap/RoadmapNodeRepository.java | 11 - .../roadmap/RoadmapRepository.java | 8 - .../roadmap/RoadmapReviewQueryRepository.java | 12 - .../roadmap/RoadmapReviewRepository.java | 12 - .../controller/RoadmapController.java | 34 +- .../roadmap => roadmap/domain}/Roadmap.java | 76 +-- .../domain}/RoadmapCategory.java | 4 +- .../domain}/RoadmapContent.java | 46 +- .../domain}/RoadmapDifficulty.java | 2 +- .../domain}/RoadmapNode.java | 32 +- .../domain}/RoadmapNodeImage.java | 2 +- .../domain}/RoadmapNodeImages.java | 6 +- .../domain}/RoadmapNodes.java | 24 +- .../domain}/RoadmapReview.java | 41 +- .../domain}/RoadmapStatus.java | 2 +- .../domain}/RoadmapTag.java | 4 +- .../domain}/RoadmapTags.java | 12 +- .../domain}/exception/RoadmapException.java | 2 +- .../domain}/vo/RoadmapTagName.java | 8 +- .../RoadmapCategoryRepository.java | 4 +- .../persistence/RoadmapContentRepository.java | 15 + .../persistence}/RoadmapQueryRepository.java | 20 +- .../RoadmapQueryRepositoryImpl.java | 75 ++- .../persistence/RoadmapRepository.java | 11 + .../RoadmapReviewQueryRepository.java | 11 + .../RoadmapReviewQueryRepositoryImpl.java | 22 +- .../persistence/RoadmapReviewRepository.java | 12 + .../persistence/dto/RoadmapOrderType.java | 2 +- .../dto/RoadmapSearchCreatorNickname.java | 2 +- .../persistence/dto/RoadmapSearchDto.java | 2 +- .../persistence/dto/RoadmapSearchTagName.java | 6 +- .../persistence/dto/RoadmapSearchTitle.java | 6 +- .../resolver/RoadmapSaveArgumentResolver.java | 6 + .../RoadmapSaveArgumentResolverImpl.java} | 12 +- .../service}/RoadmapCreateEventListener.java | 29 +- .../service}/RoadmapCreateService.java | 156 +++--- .../service/RoadmapGoalRoomService.java | 21 + .../service}/RoadmapReadService.java | 151 +++-- .../RoadmapReviewDeleteEventListener.java | 19 + .../service/dto}/RoadmapCategoryDto.java | 2 +- .../service/dto}/RoadmapContentDto.java | 2 +- .../service/dto}/RoadmapDto.java | 2 +- .../service/dto}/RoadmapForListDto.java | 2 +- .../service/dto}/RoadmapForListScrollDto.java | 2 +- .../dto}/RoadmapGoalRoomNumberDto.java | 2 +- .../dto}/RoadmapGoalRoomsOrderTypeDto.java | 2 +- .../service/dto}/RoadmapNodeDto.java | 2 +- .../service/dto}/RoadmapNodeSaveDto.java | 2 +- .../roadmap/service/dto/RoadmapReviewDto.java | 9 + .../service/dto}/RoadmapReviewReadDto.java | 2 +- .../service/dto}/RoadmapSaveDto.java | 4 +- .../service/dto}/RoadmapTagDto.java | 2 +- .../service/dto}/RoadmapTagSaveDto.java | 2 +- .../request/RoadmapCategorySaveRequest.java | 2 +- .../dto}/request/RoadmapDifficultyType.java | 2 +- .../dto}/request/RoadmapNodeSaveRequest.java | 2 +- .../dto}/request/RoadmapOrderTypeRequest.java | 2 +- .../request/RoadmapReviewSaveRequest.java | 2 +- .../dto}/request/RoadmapSaveRequest.java | 2 +- .../dto}/request/RoadmapSearchRequest.java | 2 +- .../dto}/request/RoadmapTagSaveRequest.java | 2 +- .../dto}/response/MemberRoadmapResponse.java | 2 +- .../dto}/response/MemberRoadmapResponses.java | 2 +- .../response/RoadmapCategoryResponse.java | 2 +- .../dto}/response/RoadmapContentResponse.java | 2 +- .../dto}/response/RoadmapForListResponse.java | 2 +- .../response/RoadmapForListResponses.java | 2 +- .../response/RoadmapGoalRoomResponse.java | 5 +- .../response/RoadmapGoalRoomResponses.java | 2 +- .../dto}/response/RoadmapNodeResponse.java | 2 +- .../dto}/response/RoadmapResponse.java | 2 +- .../dto}/response/RoadmapReviewResponse.java | 2 +- .../dto}/response/RoadmapTagResponse.java | 2 +- .../service/event/RoadmapCreateEvent.java | 10 + .../service/event/RoadmapDeleteEvent.java | 7 + .../service/mapper/RoadmapMapper.java | 78 +-- .../service/scheduler/RoadmapScheduler.java | 46 ++ .../service/RandomNumberGenerator.java | 2 +- .../service/UUIDFilePathGenerator.java | 2 +- .../service/dto/roadmap/RoadmapReviewDto.java | 11 - .../service/event/RoadmapCreateEvent.java | 11 - .../goalroom/GoalRoomCreateService.java | 28 +- .../service/goalroom/GoalRoomReadService.java | 10 +- .../goalroom/RoadmapGoalRoomServiceImpl.java | 103 ++++ .../service/mapper/GoalRoomMapper.java | 16 +- .../service/scheduler/GoalRoomScheduler.java | 4 +- .../service/scheduler/RoadmapScheduler.java | 56 -- .../kirikiri/src/main/resources/properties | 2 +- .../auth/controller/AuthCreateApiTest.java | 8 +- .../RefreshTokenRepositoryTest.java | 17 +- ...berIdentifierArgumentResolverImplTest.java | 2 +- .../auth/service/AuthServiceTest.java | 2 +- .../auth/service/JwtTokenProviderTest.java | 2 +- .../service/NaverOauthNetworkServiceTest.java | 8 +- .../auth/service/NaverOauthServiceTest.java | 6 +- .../common/service/CacheKeyGeneratorTest.java | 2 +- .../controller/GoalRoomCreateApiTest.java | 31 +- .../controller/GoalRoomReadApiTest.java | 10 +- .../helper/ControllerTestHelper.java | 2 +- .../goalroom/GoalRoomPendingMemberTest.java | 6 +- .../goalroom/GoalRoomPendingMembersTest.java | 8 +- .../goalroom/GoalRoomRoadmapNodeTest.java | 4 +- .../goalroom/GoalRoomRoadmapNodesTest.java | 8 +- .../domain/goalroom/GoalRoomTest.java | 76 +-- .../domain/goalroom/GoalRoomToDoTest.java | 2 +- .../domain/roadmap/RoadmapContentTest.java | 89 --- .../domain/roadmap/RoadmapContentsTest.java | 27 - .../domain/roadmap/RoadmapNodesTest.java | 41 -- .../kirikiri/domain/roadmap/RoadmapTest.java | 99 ---- .../infra/AmazonS3FileServiceTest.java | 6 +- .../kirikiri/infra/CloudFrontServiceTest.java | 4 +- .../AuthenticationIntegrationTest.java | 2 +- .../GoalRoomCreateIntegrationTest.java | 37 +- .../GoalRoomReadIntegrationTest.java | 41 +- .../GoalRoomSchedulerIntegrationTest.java | 16 +- .../MemberReadIntegrationTest.java | 8 +- .../RoadmapCreateIntegrationTest.java | 25 +- .../RoadmapReadIntegrationTest.java | 33 +- .../RoadmapReadOrderIntegrationTest.java | 36 +- .../RoadmapReviewCreateIntegrationTest.java | 23 +- .../RoadmapReviewReadIntegrationTest.java | 19 +- .../RoadmapSchedulerIntegrationTest.java | 19 +- .../RoadmapSearchIntegrationTest.java | 17 +- .../fixture/GoalRoomAPIFixture.java | 14 +- .../integration/fixture/MemberAPIFixture.java | 4 +- .../fixture/RoadmapAPIFixture.java | 14 +- .../helper/InitIntegrationTest.java | 10 +- .../integration/helper/IntegrationTest.java | 7 +- .../integration/helper/TestFileService.java | 2 +- .../helper/TestTransactionService.java | 16 +- .../controller/MemberCreateApiTest.java | 4 +- .../persistence/MemberRepositoryTest.java | 2 +- .../member/service/MemberServiceTest.java | 6 +- .../goalroom/CheckFeedRepositoryTest.java | 144 +++-- .../GoalRoomMemberRepositoryTest.java | 194 +++---- .../GoalRoomPendingMemberRepositoryTest.java | 180 +++--- .../goalroom/GoalRoomRepositoryTest.java | 131 +++-- .../GoalRoomToDoCheckRepositoryTest.java | 49 +- .../persistence/helper/RepositoryTest.java | 8 +- .../controller/RoadmapCreateApiTest.java | 44 +- .../controller/RoadmapReadApiTest.java | 52 +- .../domain}/RoadmapCategoryTest.java | 4 +- .../roadmap/domain/RoadmapContentTest.java | 29 + .../roadmap/domain/RoadmapContentsTest.java | 22 + .../domain}/RoadmapNodeImagesTest.java | 6 +- .../domain}/RoadmapNodeTest.java | 4 +- .../roadmap/domain/RoadmapNodesTest.java | 78 +++ .../domain}/RoadmapReviewTest.java | 32 +- .../domain}/RoadmapTagsTest.java | 8 +- .../kirikiri/roadmap/domain/RoadmapTest.java | 59 ++ .../domain}/vo/RoadmapTagNameTest.java | 4 +- .../RoadmapContentRepositoryTest.java | 66 ++- .../persistence}/RoadmapRepositoryTest.java | 171 +++--- .../RoadmapReviewRepositoryTest.java | 93 +--- .../dto/RoadmapSearchTagNameTest.java | 6 +- .../dto/RoadmapSearchTitleTest.java | 6 +- .../RoadmapSaveArgumentResolverImplTest.java} | 12 +- .../RoadmapCreateEventListenerTest.java | 118 ++-- .../service/RoadmapCreateServiceTest.java | 135 ++--- .../service/RoadmapReadServiceTest.java | 261 ++++----- .../roadmap/service/RoadmapSchedulerTest.java | 107 ++++ .../service/GoalRoomCreateServiceTest.java | 521 +++++++----------- .../service/GoalRoomReadServiceTest.java | 288 +++++----- .../service/GoalRoomSchedulerTest.java | 67 +-- .../service/RoadmapSchedulerTest.java | 173 ------ 206 files changed, 2383 insertions(+), 3178 deletions(-) rename backend/kirikiri/src/main/java/co/kirikiri/{service => common}/mapper/ScrollResponseMapper.java (93%) delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/controller/RoadmapController.java (86%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/Roadmap.java (65%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapCategory.java (91%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapContent.java (59%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapDifficulty.java (74%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapNode.java (74%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapNodeImage.java (97%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapNodeImages.java (93%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapNodes.java (78%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapReview.java (69%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapStatus.java (61%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapTag.java (93%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapTags.java (93%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/exception/RoadmapException.java (81%) rename backend/kirikiri/src/main/java/co/kirikiri/{domain/roadmap => roadmap/domain}/vo/RoadmapTagName.java (88%) rename backend/kirikiri/src/main/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapCategoryRepository.java (72%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java rename backend/kirikiri/src/main/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapQueryRepository.java (63%) rename backend/kirikiri/src/main/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapQueryRepositoryImpl.java (79%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java rename backend/kirikiri/src/main/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapReviewQueryRepositoryImpl.java (62%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapOrderType.java (67%) rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapSearchCreatorNickname.java (85%) rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapSearchDto.java (95%) rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapSearchTagName.java (80%) rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapSearchTitle.java (81%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolver.java rename backend/kirikiri/src/main/java/co/kirikiri/{common/resolver/RoadmapSaveArgumentResolver.java => roadmap/resolver/RoadmapSaveArgumentResolverImpl.java} (93%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/roadmap => roadmap/service}/RoadmapCreateEventListener.java (81%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/roadmap => roadmap/service}/RoadmapCreateService.java (55%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java rename backend/kirikiri/src/main/java/co/kirikiri/{service/roadmap => roadmap/service}/RoadmapReadService.java (69%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReviewDeleteEventListener.java rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapCategoryDto.java (65%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapContentDto.java (77%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapDto.java (91%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapForListDto.java (91%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapForListScrollDto.java (76%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapGoalRoomNumberDto.java (79%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapGoalRoomsOrderTypeDto.java (86%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapNodeDto.java (79%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapNodeSaveDto.java (83%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/dto/RoadmapReviewDto.java rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapReviewReadDto.java (85%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapSaveDto.java (75%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapTagDto.java (64%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/RoadmapTagSaveDto.java (59%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapCategorySaveRequest.java (80%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapDifficultyType.java (69%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapNodeSaveRequest.java (93%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapOrderTypeRequest.java (87%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapReviewSaveRequest.java (80%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapSaveRequest.java (95%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapSearchRequest.java (71%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/request/RoadmapTagSaveRequest.java (57%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/MemberRoadmapResponse.java (82%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/MemberRoadmapResponses.java (73%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapCategoryResponse.java (62%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapContentResponse.java (75%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapForListResponse.java (90%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapForListResponses.java (74%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapGoalRoomResponse.java (75%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapGoalRoomResponses.java (74%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapNodeResponse.java (76%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapResponse.java (92%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapReviewResponse.java (84%) rename backend/kirikiri/src/main/java/co/kirikiri/{service/dto/roadmap => roadmap/service/dto}/response/RoadmapTagResponse.java (61%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/event/RoadmapCreateEvent.java create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/event/RoadmapDeleteEvent.java rename backend/kirikiri/src/main/java/co/kirikiri/{ => roadmap}/service/mapper/RoadmapMapper.java (81%) create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java create mode 100644 backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/RoadmapGoalRoomServiceImpl.java delete mode 100644 backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java delete mode 100644 backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java delete mode 100644 backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java delete mode 100644 backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java delete mode 100644 backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/controller/RoadmapCreateApiTest.java (96%) rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/controller/RoadmapReadApiTest.java (96%) rename backend/kirikiri/src/test/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapCategoryTest.java (92%) create mode 100644 backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java create mode 100644 backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java rename backend/kirikiri/src/test/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapNodeImagesTest.java (97%) rename backend/kirikiri/src/test/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapNodeTest.java (91%) create mode 100644 backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java rename backend/kirikiri/src/test/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapReviewTest.java (54%) rename backend/kirikiri/src/test/java/co/kirikiri/{domain/roadmap => roadmap/domain}/RoadmapTagsTest.java (93%) create mode 100644 backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java rename backend/kirikiri/src/test/java/co/kirikiri/{domain/roadmap => roadmap/domain}/vo/RoadmapTagNameTest.java (94%) rename backend/kirikiri/src/test/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapContentRepositoryTest.java (58%) rename backend/kirikiri/src/test/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapRepositoryTest.java (82%) rename backend/kirikiri/src/test/java/co/kirikiri/{persistence/roadmap => roadmap/persistence}/RoadmapReviewRepositoryTest.java (59%) rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapSearchTagNameTest.java (89%) rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/persistence/dto/RoadmapSearchTitleTest.java (89%) rename backend/kirikiri/src/test/java/co/kirikiri/{common/resolver/RoadmapSaveArgumentResolverTest.java => roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java} (93%) rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/service/RoadmapCreateEventListenerTest.java (62%) rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/service/RoadmapCreateServiceTest.java (73%) rename backend/kirikiri/src/test/java/co/kirikiri/{ => roadmap}/service/RoadmapReadServiceTest.java (75%) create mode 100644 backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java delete mode 100644 backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java index 546a7dca7..694bdcfe0 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java @@ -2,12 +2,11 @@ import co.kirikiri.auth.service.AuthService; import co.kirikiri.auth.service.NaverOauthService; -import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import jakarta.validation.Valid; -import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -16,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.Map; @RestController @RequestMapping("/auth") diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java index c5e29670b..adc4eb647 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java @@ -1,7 +1,6 @@ package co.kirikiri.auth.infra; import co.kirikiri.auth.service.OauthNetworkService; -import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpEntity; @@ -10,6 +9,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; +import java.util.Map; @Service @RequiredArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java index f6985f6e2..97d97397c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java @@ -1,10 +1,10 @@ package co.kirikiri.auth.persistence; -import java.util.Optional; -import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Repository; +import java.util.Optional; +import java.util.concurrent.TimeUnit; @Repository public class RefreshTokenRepositoryImpl implements RefreshTokenRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java index 74c13ba6a..1b75cd523 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java @@ -12,10 +12,10 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Password; import co.kirikiri.member.persistence.MemberRepository; -import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Map; @Service @Transactional(readOnly = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java index 77087e048..bbef381b6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java @@ -7,6 +7,9 @@ import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import javax.crypto.SecretKey; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.ZoneId; @@ -14,9 +17,6 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import javax.crypto.SecretKey; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; @Component public class JwtTokenProvider implements TokenProvider { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java index 578c01d97..fe2c5811e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java @@ -3,23 +3,23 @@ import co.kirikiri.auth.service.dto.NaverMemberProfileDto; import co.kirikiri.auth.service.dto.NaverMemberProfileResponseDto; import co.kirikiri.auth.service.dto.NaverOauthTokenDto; -import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.auth.service.mapper.OauthMapper; import co.kirikiri.member.domain.Member; import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.member.service.MemberService; import co.kirikiri.member.service.dto.OauthMemberJoinDto; import co.kirikiri.member.service.dto.request.GenderType; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Map; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigInteger; +import java.security.SecureRandom; +import java.util.Map; +import java.util.Optional; @Service @Transactional(readOnly = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java index c02d8da92..e013660d6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java @@ -1,7 +1,7 @@ package co.kirikiri.auth.service; -import java.util.Map; import org.springframework.http.ResponseEntity; +import java.util.Map; public interface OauthNetworkService { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java b/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java index 532f9d2b3..00366e6bf 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java @@ -1,8 +1,8 @@ package co.kirikiri.common.aop; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.common.exception.domain.DomainException; import co.kirikiri.common.exception.ServerException; +import co.kirikiri.common.exception.domain.DomainException; import co.kirikiri.common.exception.domain.UnexpectedDomainException; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java b/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java index e49a413d9..ad4109bc5 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import java.time.Duration; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; @@ -16,6 +15,7 @@ import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; +import java.time.Duration; @Configuration @EnableCaching diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/config/WebConfig.java b/backend/kirikiri/src/main/java/co/kirikiri/common/config/WebConfig.java index 4b19bc9a9..abeebf372 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/config/WebConfig.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/config/WebConfig.java @@ -2,13 +2,13 @@ import co.kirikiri.common.interceptor.AuthInterceptor; import co.kirikiri.common.resolver.MemberIdentifierArgumentResolver; -import co.kirikiri.common.resolver.RoadmapSaveArgumentResolver; -import java.util.List; +import co.kirikiri.roadmap.resolver.RoadmapSaveArgumentResolver; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.List; @Configuration @RequiredArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/controller/GlobalExceptionHandler.java b/backend/kirikiri/src/main/java/co/kirikiri/common/controller/GlobalExceptionHandler.java index a6298e5b0..24aa239ee 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/controller/GlobalExceptionHandler.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/controller/GlobalExceptionHandler.java @@ -8,7 +8,6 @@ import co.kirikiri.common.exception.ServerException; import co.kirikiri.service.dto.ErrorResponse; import com.fasterxml.jackson.databind.exc.InvalidFormatException; -import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -16,6 +15,7 @@ import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import java.util.List; @RestControllerAdvice public class GlobalExceptionHandler { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java index 729fca5a6..072106573 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java @@ -7,13 +7,13 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; import com.amazonaws.services.s3.model.ObjectMetadata; -import java.io.InputStream; -import java.net.URL; -import java.util.Date; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; +import java.io.InputStream; +import java.net.URL; +import java.util.Date; @Service @RequiredArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java index fc0cea738..984a01ca6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java @@ -1,11 +1,11 @@ package co.kirikiri.common.infra; import co.kirikiri.common.exception.ServerException; -import java.net.MalformedURLException; -import java.net.URL; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; +import java.net.MalformedURLException; +import java.net.URL; @Service @RequiredArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/ScrollResponseMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/common/mapper/ScrollResponseMapper.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/service/mapper/ScrollResponseMapper.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/mapper/ScrollResponseMapper.java index c9d3b4c64..3bee95b34 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/ScrollResponseMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/mapper/ScrollResponseMapper.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.mapper; +package co.kirikiri.common.mapper; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java index 1915970c3..79ffb2cfc 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java @@ -1,10 +1,10 @@ package co.kirikiri.common.service; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.stereotype.Component; import java.lang.reflect.Method; import java.util.Arrays; import java.util.stream.Collectors; -import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.stereotype.Component; @Component public class CacheKeyGenerator implements KeyGenerator { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/service/FileService.java b/backend/kirikiri/src/main/java/co/kirikiri/common/service/FileService.java index af231d532..8965f8f26 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/service/FileService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/service/FileService.java @@ -1,8 +1,8 @@ package co.kirikiri.common.service; import co.kirikiri.service.dto.FileInformation; -import java.net.URL; import org.springframework.http.HttpMethod; +import java.net.URL; public interface FileService { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/controller/GoalRoomController.java b/backend/kirikiri/src/main/java/co/kirikiri/controller/GoalRoomController.java index deb0984b8..896caec93 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/controller/GoalRoomController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/controller/GoalRoomController.java @@ -19,8 +19,6 @@ import co.kirikiri.service.goalroom.GoalRoomCreateService; import co.kirikiri.service.goalroom.GoalRoomReadService; import jakarta.validation.Valid; -import java.net.URI; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -33,6 +31,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.net.URI; +import java.util.List; @RestController @RequestMapping("/goal-rooms") diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/BaseGoalRoomMember.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/BaseGoalRoomMember.java index deffacf45..aa79e2006 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/BaseGoalRoomMember.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/BaseGoalRoomMember.java @@ -10,12 +10,14 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PrePersist; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import org.springframework.data.annotation.CreatedDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Objects; @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -31,6 +33,7 @@ public abstract class BaseGoalRoomMember extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "goal_room_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) @QueryInit(value = {"roadmapContent.roadmap"}) protected GoalRoom goalRoom; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoom.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoom.java index 6b150b6b5..08e586002 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoom.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoom.java @@ -4,8 +4,8 @@ import co.kirikiri.domain.goalroom.exception.GoalRoomException; import co.kirikiri.domain.goalroom.vo.GoalRoomName; import co.kirikiri.domain.goalroom.vo.LimitedMemberCount; -import co.kirikiri.domain.roadmap.RoadmapContent; import co.kirikiri.member.domain.Member; +import co.kirikiri.roadmap.domain.RoadmapContent; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -14,51 +14,44 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) public class GoalRoom extends BaseUpdatedTimeEntity { private static final int DATE_OFFSET = 1; - + @Embedded + private final GoalRoomPendingMembers goalRoomPendingMembers = new GoalRoomPendingMembers(); + @Embedded + private final GoalRoomMembers goalRoomMembers = new GoalRoomMembers(); + @Embedded + private final GoalRoomToDos goalRoomToDos = new GoalRoomToDos(); + @Embedded + private final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes(); @Embedded private GoalRoomName name; - @Embedded private LimitedMemberCount limitedMemberCount; - @Enumerated(value = EnumType.STRING) private GoalRoomStatus status = GoalRoomStatus.RECRUITING; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "roadmap_content_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) private RoadmapContent roadmapContent; - @Column(nullable = false) private LocalDate startDate; - @Column(nullable = false) private LocalDate endDate; - @Embedded - private final GoalRoomPendingMembers goalRoomPendingMembers = new GoalRoomPendingMembers(); - - @Embedded - private final GoalRoomMembers goalRoomMembers = new GoalRoomMembers(); - - @Embedded - private final GoalRoomToDos goalRoomToDos = new GoalRoomToDos(); - - @Embedded - private final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes(); - public GoalRoom(final GoalRoomName name, final LimitedMemberCount limitedMemberCount, final RoadmapContent roadmapContent, final Member member) { this(null, name, limitedMemberCount, roadmapContent, member); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomMembers.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomMembers.java index fac858681..286badcd2 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomMembers.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomMembers.java @@ -6,13 +6,13 @@ import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Optional; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.BatchSize; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMember.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMember.java index 0dec485f5..821dc3b2d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMember.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMember.java @@ -2,9 +2,9 @@ import co.kirikiri.member.domain.Member; import jakarta.persistence.Entity; -import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembers.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembers.java index 8f3299cc5..fbd3b2028 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembers.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembers.java @@ -6,13 +6,13 @@ import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Optional; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.BatchSize; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNode.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNode.java index d67d27d4d..1f60cc2b0 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNode.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNode.java @@ -3,15 +3,17 @@ import co.kirikiri.common.entity.BaseEntity; import co.kirikiri.domain.goalroom.exception.GoalRoomException; import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNode; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import java.time.LocalDate; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; +import java.time.LocalDate; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -26,6 +28,7 @@ public class GoalRoomRoadmapNode extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "roadmap_node_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) private RoadmapNode roadmapNode; public GoalRoomRoadmapNode(final Period period, final Integer checkCount, final RoadmapNode roadmapNode) { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodes.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodes.java index 83401f80d..3a70b4d72 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodes.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodes.java @@ -6,6 +6,8 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -13,8 +15,6 @@ import java.util.List; import java.util.Optional; import java.util.stream.IntStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/vo/Period.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/vo/Period.java index 881202f46..a9b8f6d37 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/vo/Period.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/domain/goalroom/vo/Period.java @@ -3,10 +3,10 @@ import co.kirikiri.domain.goalroom.exception.GoalRoomException; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java deleted file mode 100644 index 4677640f2..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java +++ /dev/null @@ -1,42 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; -import jakarta.persistence.Embeddable; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@Embeddable -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class RoadmapContents { - - @OneToMany(fetch = FetchType.LAZY, - cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, - mappedBy = "roadmap") - @Column(nullable = false) - private final List values = new ArrayList<>(); - - public RoadmapContents(final List contents) { - this.values.addAll(contents); - } - - public void add(final RoadmapContent content) { - this.values.add(content); - } - - public Optional findLastRoadmapContent() { - if (values.isEmpty()) { - return Optional.empty(); - } - return Optional.of(values.get(values.size() - 1)); - } - - public List getValues() { - return values; - } -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java deleted file mode 100644 index 706c14b6f..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java +++ /dev/null @@ -1,24 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Embeddable; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import java.util.ArrayList; -import java.util.List; - -@Embeddable -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class RoadmapReviews { - - @OneToMany(fetch = FetchType.LAZY, - cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, - orphanRemoval = true, mappedBy = "roadmap") - private List values = new ArrayList<>(); - - public void add(final RoadmapReview review) { - this.values.add(review); - } -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java b/backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java index 7fecb051b..936c00bfc 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java @@ -7,7 +7,6 @@ import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; import co.kirikiri.member.service.dto.response.MemberInformationResponse; import jakarta.validation.Valid; -import java.net.URI; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -16,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.net.URI; @RestController @RequestMapping("/members") diff --git a/backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java index c7967ad11..266fb000b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java @@ -2,13 +2,13 @@ import co.kirikiri.common.exception.domain.UnexpectedDomainException; import co.kirikiri.member.domain.vo.Password; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Base64; import java.util.Objects; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class EncryptedPassword { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java index 01a29de9a..c16c2a1ba 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java @@ -2,9 +2,9 @@ import co.kirikiri.member.domain.exception.MemberException; import jakarta.persistence.Column; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Objects; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Identifier { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java index b8befd501..c65353bee 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java @@ -2,8 +2,8 @@ import co.kirikiri.member.domain.exception.MemberException; import jakarta.persistence.Column; -import java.util.Objects; import lombok.NoArgsConstructor; +import java.util.Objects; @NoArgsConstructor public class Nickname { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java index 3efdea09f..776876b82 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java @@ -22,13 +22,13 @@ import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; import co.kirikiri.member.service.dto.response.MemberInformationResponse; import co.kirikiri.member.service.mapper.MemberMapper; -import java.net.URL; -import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.net.URL; +import java.util.UUID; @Service @Transactional(readOnly = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/QuerydslRepositorySupporter.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/QuerydslRepositorySupporter.java index e8c37e766..bef0cb5b1 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/QuerydslRepositorySupporter.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/QuerydslRepositorySupporter.java @@ -9,7 +9,6 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.annotation.PostConstruct; import jakarta.persistence.EntityManager; -import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cglib.core.internal.Function; import org.springframework.data.domain.Page; @@ -17,6 +16,7 @@ import org.springframework.data.jpa.repository.support.Querydsl; import org.springframework.data.support.PageableExecutionUtils; import org.springframework.stereotype.Repository; +import java.util.List; @Repository public abstract class QuerydslRepositorySupporter { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberJdbcRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberJdbcRepositoryImpl.java index 28758b191..bd16f8969 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberJdbcRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberJdbcRepositoryImpl.java @@ -1,9 +1,9 @@ package co.kirikiri.persistence.goalroom; import co.kirikiri.domain.goalroom.GoalRoomMember; -import java.util.List; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; +import java.util.List; @Repository public class GoalRoomMemberJdbcRepositoryImpl implements GoalRoomMemberJdbcRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberQueryRepositoryImpl.java index c16f46d06..0edace5f8 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberQueryRepositoryImpl.java @@ -2,11 +2,11 @@ import static co.kirikiri.domain.goalroom.QGoalRoom.goalRoom; import static co.kirikiri.domain.goalroom.QGoalRoomMember.goalRoomMember; -import static co.kirikiri.domain.roadmap.QRoadmapContent.roadmapContent; import static co.kirikiri.member.domain.QMember.member; import static co.kirikiri.member.domain.QMemberImage.memberImage; import static co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType.ACCOMPLISHMENT_RATE; import static co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType.JOINED_ASC; +import static co.kirikiri.roadmap.domain.QRoadmapContent.roadmapContent; import co.kirikiri.domain.goalroom.GoalRoomMember; import co.kirikiri.domain.goalroom.GoalRoomStatus; @@ -37,7 +37,7 @@ public Optional findByRoadmapIdAndMemberIdentifierAndGoalRoomSta .innerJoin(goalRoomMember.member, member) .fetchJoin() .where( - goalRoom.roadmapContent.roadmap.id.eq(roadmapId), + goalRoom.roadmapContent.roadmapId.eq(roadmapId), member.identifier.eq(identifier), goalRoom.status.eq(status)) .fetchOne()); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepository.java index 8a28b8bc5..1ff1ed50d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepository.java @@ -3,11 +3,11 @@ import co.kirikiri.domain.goalroom.GoalRoom; import co.kirikiri.domain.goalroom.GoalRoomMember; import co.kirikiri.member.domain.vo.Identifier; -import java.util.List; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Optional; public interface GoalRoomMemberRepository extends JpaRepository, GoalRoomMemberQueryRepository, GoalRoomMemberJdbcRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepository.java index 74a8f943b..880d1af38 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepository.java @@ -3,12 +3,12 @@ import co.kirikiri.domain.goalroom.GoalRoom; import co.kirikiri.domain.goalroom.GoalRoomPendingMember; import co.kirikiri.member.domain.vo.Identifier; -import java.util.List; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Optional; public interface GoalRoomPendingMemberRepository extends JpaRepository, GoalRoomPendingMemberQueryRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepository.java index 0c51687fd..0cd2f99a2 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepository.java @@ -3,7 +3,6 @@ import co.kirikiri.domain.goalroom.GoalRoom; import co.kirikiri.domain.goalroom.GoalRoomStatus; import co.kirikiri.member.domain.Member; -import co.kirikiri.domain.roadmap.Roadmap; import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; import java.time.LocalDate; import java.util.List; @@ -17,10 +16,10 @@ public interface GoalRoomQueryRepository { Optional findByIdWithContentAndTodos(final Long goalRoomId); - List findGoalRoomsByRoadmapAndCond(final Roadmap roadmap, - final RoadmapGoalRoomsOrderType filterType, - final Long lastId, - final int pageSize); + List findGoalRoomsByRoadmapIdAndCond(final Long roadmapId, + final RoadmapGoalRoomsOrderType filterType, + final Long lastId, + final int pageSize); Optional findByIdWithTodos(final Long goalRoomId); @@ -30,7 +29,7 @@ List findGoalRoomsByRoadmapAndCond(final Roadmap roadmap, Optional findByIdWithNodes(final Long goalRoomId); - List findByRoadmap(final Roadmap roadmap); + List findByRoadmapId(final Long roadmapId); List findAllRecruitingGoalRoomsByStartDateEarlierThan(final LocalDate startDate); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepositoryImpl.java index a98c2968e..e63da13d5 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomQueryRepositoryImpl.java @@ -5,12 +5,11 @@ import static co.kirikiri.domain.goalroom.QGoalRoomPendingMember.goalRoomPendingMember; import static co.kirikiri.domain.goalroom.QGoalRoomRoadmapNode.goalRoomRoadmapNode; import static co.kirikiri.domain.goalroom.QGoalRoomToDo.goalRoomToDo; -import static co.kirikiri.domain.roadmap.QRoadmapContent.roadmapContent; +import static co.kirikiri.roadmap.domain.QRoadmapContent.roadmapContent; import co.kirikiri.domain.goalroom.GoalRoom; import co.kirikiri.domain.goalroom.GoalRoomStatus; import co.kirikiri.member.domain.Member; -import co.kirikiri.domain.roadmap.Roadmap; import co.kirikiri.persistence.QuerydslRepositorySupporter; import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; import com.querydsl.core.types.OrderSpecifier; @@ -59,17 +58,16 @@ public Optional findByIdWithContentAndTodos(final Long goalRoomId) { } @Override - public List findGoalRoomsByRoadmapAndCond(final Roadmap roadmap, - final RoadmapGoalRoomsOrderType orderType, - final Long lastId, - final int pageSize) { + public List findGoalRoomsByRoadmapIdAndCond(final Long roadmapId, + final RoadmapGoalRoomsOrderType orderType, + final Long lastId, + final int pageSize) { return selectFrom(goalRoom) .innerJoin(goalRoom.roadmapContent, roadmapContent) - .on(roadmapContent.roadmap.eq(roadmap)) + .on(roadmapContent.roadmapId.eq(roadmapId)) .where( statusCond(orderType), - lessThanLastId(lastId, orderType), - roadmapCond(roadmap)) + lessThanLastId(lastId, orderType)) .limit(pageSize + LIMIT_OFFSET) .orderBy(sortCond(orderType)) .fetch(); @@ -117,10 +115,10 @@ public Optional findByIdWithNodes(final Long goalRoomId) { } @Override - public List findByRoadmap(final Roadmap roadmap) { + public List findByRoadmapId(final Long roadmapId) { return selectFrom(goalRoom) .innerJoin(goalRoom.roadmapContent, roadmapContent) - .where(roadmapContent.roadmap.eq(roadmap)) + .where(roadmapContent.roadmapId.eq(roadmapId)) .fetch(); } @@ -173,10 +171,6 @@ private BooleanExpression lessThanLastId(final Long lastId, final RoadmapGoalRoo ); } - private BooleanExpression roadmapCond(final Roadmap roadmap) { - return goalRoom.roadmapContent.roadmap.eq(roadmap); - } - private BooleanExpression equalOrEarlierStartDateThan(final LocalDate date) { return goalRoom.startDate.loe(date); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomRepository.java index 7f517ae99..c3262251f 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomRepository.java @@ -1,13 +1,13 @@ package co.kirikiri.persistence.goalroom; import co.kirikiri.domain.goalroom.GoalRoom; +import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDate; import java.util.List; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; public interface GoalRoomRepository extends JpaRepository, GoalRoomQueryRepository { - + Optional findById(final Long goalRoomId); List findAllByEndDate(final LocalDate endDate); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java deleted file mode 100644 index 722761e75..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import java.util.Optional; - -public interface RoadmapContentRepository extends JpaRepository { - - Optional findFirstByRoadmapOrderByCreatedAtDesc(final Roadmap roadmap); - - @Query("select rc from RoadmapContent rc " - + "join fetch rc.roadmap r " - + "where rc.id = :roadmapContentId") - Optional findByIdWithRoadmap(@Param("roadmapContentId") final Long roadmapContentId); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java deleted file mode 100644 index cbe15b11b..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; - -public interface RoadmapNodeRepository extends JpaRepository { - - List findAllByRoadmapContent(final RoadmapContent roadmapContent); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java deleted file mode 100644 index 6df4b1ba4..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.Roadmap; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface RoadmapRepository extends JpaRepository, RoadmapQueryRepository { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java deleted file mode 100644 index 84a779636..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapReview; -import java.util.List; - -public interface RoadmapReviewQueryRepository { - - List findRoadmapReviewWithMemberByRoadmapOrderByLatest(final Roadmap roadmap, - final Long lastId, - final int pageSize); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java deleted file mode 100644 index 6eeafc446..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.member.domain.Member; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapReview; -import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; - -public interface RoadmapReviewRepository extends JpaRepository, RoadmapReviewQueryRepository { - - Optional findByRoadmapAndMember(final Roadmap roadmap, final Member member); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/controller/RoadmapController.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/controller/RoadmapController.java similarity index 86% rename from backend/kirikiri/src/main/java/co/kirikiri/controller/RoadmapController.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/controller/RoadmapController.java index 21abca873..fb5f855c3 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/controller/RoadmapController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/controller/RoadmapController.java @@ -1,25 +1,23 @@ -package co.kirikiri.controller; +package co.kirikiri.roadmap.controller; import co.kirikiri.common.interceptor.Authenticated; import co.kirikiri.common.resolver.MemberIdentifier; +import co.kirikiri.roadmap.service.RoadmapCreateService; +import co.kirikiri.roadmap.service.RoadmapReadService; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import co.kirikiri.service.roadmap.RoadmapReadService; import jakarta.validation.Valid; -import java.net.URI; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -33,6 +31,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.net.URI; +import java.util.List; @RestController @RequestMapping("/roadmaps") diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/Roadmap.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/Roadmap.java similarity index 65% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/Roadmap.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/Roadmap.java index e9dc770b2..99ba766af 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/Roadmap.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/Roadmap.java @@ -1,8 +1,7 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseCreatedTimeEntity; -import co.kirikiri.member.domain.Member; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -11,11 +10,10 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import java.util.Objects; -import java.util.Optional; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import java.util.Objects; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -46,42 +44,23 @@ public class Roadmap extends BaseCreatedTimeEntity { @Column(length = 10, nullable = false) private RoadmapStatus status = RoadmapStatus.CREATED; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id", nullable = false, updatable = false) - private Member creator; + private Long creatorId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "category_id", nullable = false) private RoadmapCategory category; - @Embedded - private RoadmapContents contents = new RoadmapContents(); - @Embedded private RoadmapTags tags = new RoadmapTags(); - @Embedded - private RoadmapReviews reviews = new RoadmapReviews(); - - public Roadmap(final String title, final String introduction, final int requiredPeriod, - final RoadmapDifficulty difficulty, final Member creator, final RoadmapCategory category) { - this(null, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creator, category); - } - - public Roadmap(final String title, final String introduction, final Integer requiredPeriod, - final RoadmapDifficulty difficulty, final RoadmapStatus status, final Member creator, - final RoadmapCategory category) { - this(null, title, introduction, requiredPeriod, difficulty, status, creator, category); - } - - public Roadmap(final Long id, final String title, final String introduction, final Integer requiredPeriod, - final RoadmapDifficulty difficulty, final Member creator, final RoadmapCategory category) { - this(id, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creator, category); + public Roadmap(final String title, final String introduction, final int requiredPeriod, final RoadmapDifficulty difficulty, + final Long creatorId, final RoadmapCategory category, final RoadmapTags tags) { + this(null, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creatorId, category, tags); } public Roadmap(final Long id, final String title, final String introduction, final Integer requiredPeriod, - final RoadmapDifficulty difficulty, final RoadmapStatus status, final Member creator, - final RoadmapCategory category) { + final RoadmapDifficulty difficulty, final RoadmapStatus status, final Long creatorId, + final RoadmapCategory category, final RoadmapTags tags) { validate(title, introduction, requiredPeriod); this.id = id; this.title = title; @@ -89,8 +68,9 @@ public Roadmap(final Long id, final String title, final String introduction, fin this.requiredPeriod = requiredPeriod; this.difficulty = difficulty; this.status = status; - this.creator = creator; + this.creatorId = creatorId; this.category = category; + this.tags = tags; } private void validate(final String title, final String introduction, final int requiredPeriod) { @@ -125,42 +105,20 @@ private void validateRequiredPeriod(final int requiredPeriod) { } } - public void addContent(final RoadmapContent content) { - contents.add(content); - if (content.isNotSameRoadmap(this)) { - content.updateRoadmap(this); - } - } - - public void addTags(final RoadmapTags tags) { - this.tags.addAll(tags); - } - - public boolean isCreator(final Member member) { - return Objects.equals(creator.getId(), member.getId()); - } - - public void addReview(final RoadmapReview review) { - reviews.add(review); - if (review.isNotSameRoadmap(this)) { - review.updateRoadmap(this); - } + public boolean isCreator(final Long memberId) { + return Objects.equals(creatorId, memberId); } public void delete() { this.status = RoadmapStatus.DELETED; } - public Optional findLastRoadmapContent() { - return this.contents.findLastRoadmapContent(); - } - public boolean isDeleted() { return status == RoadmapStatus.DELETED; } - public Member getCreator() { - return creator; + public Long getCreatorId() { + return creatorId; } public String getTitle() { @@ -171,10 +129,6 @@ public RoadmapCategory getCategory() { return category; } - public RoadmapContents getContents() { - return contents; - } - public String getIntroduction() { return introduction; } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapCategory.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapCategory.java similarity index 91% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapCategory.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapCategory.java index a71fcfb19..552c6d78e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapCategory.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapCategory.java @@ -1,7 +1,7 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.AccessLevel; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContent.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapContent.java similarity index 59% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContent.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapContent.java index e982cfdf9..2233732f5 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContent.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapContent.java @@ -1,17 +1,14 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseUpdatedTimeEntity; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import java.util.Optional; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Optional; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -23,21 +20,21 @@ public class RoadmapContent extends BaseUpdatedTimeEntity { @Column(length = 2200) private String content; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "roadmap_id", nullable = false) - private Roadmap roadmap; + private Long roadmapId; @Embedded - private final RoadmapNodes nodes = new RoadmapNodes(); + private RoadmapNodes nodes; - public RoadmapContent(final String content) { - this(null, content); + public RoadmapContent(final String content, final Long roadmapId, final RoadmapNodes nodes) { + this(null, content, roadmapId, nodes); } - public RoadmapContent(final Long id, final String content) { + public RoadmapContent(final Long id, final String content, final Long roadmapId, final RoadmapNodes nodes) { validate(content); this.id = id; this.content = content; + this.roadmapId = roadmapId; + this.nodes = nodes; } private void validate(final String content) { @@ -53,21 +50,6 @@ private void validateContentLength(final String content) { } } - public void addNodes(final RoadmapNodes nodes) { - this.nodes.addAll(nodes); - nodes.updateAllRoadmapContent(this); - } - - public boolean isNotSameRoadmap(final Roadmap roadmap) { - return this.roadmap == null || !this.roadmap.equals(roadmap); - } - - public void updateRoadmap(final Roadmap roadmap) { - if (this.roadmap == null) { - this.roadmap = roadmap; - } - } - public int nodesSize() { return nodes.size(); } @@ -84,11 +66,11 @@ public String getContent() { return content; } - public RoadmapNodes getNodes() { - return nodes; + public Long getRoadmapId() { + return roadmapId; } - public Roadmap getRoadmap() { - return roadmap; + public RoadmapNodes getNodes() { + return nodes; } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapDifficulty.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapDifficulty.java similarity index 74% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapDifficulty.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapDifficulty.java index f8379da50..1a4969ced 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapDifficulty.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapDifficulty.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; public enum RoadmapDifficulty { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNode.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNode.java similarity index 74% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNode.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNode.java index 0e82f470d..4308f0440 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNode.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNode.java @@ -1,13 +1,10 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -19,20 +16,13 @@ public class RoadmapNode extends BaseEntity { private static final int TITLE_MAX_LENGTH = 40; private static final int CONTENT_MIN_LENGTH = 1; private static final int CONTENT_MAX_LENGTH = 2000; - + @Embedded + private final RoadmapNodeImages roadmapNodeImages = new RoadmapNodeImages(); @Column(length = 50, nullable = false) private String title; - @Column(length = 2200, nullable = false) private String content; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "roadmap_content_id", nullable = false) - private RoadmapContent roadmapContent; - - @Embedded - private final RoadmapNodeImages roadmapNodeImages = new RoadmapNodeImages(); - public RoadmapNode(final String title, final String content) { this(null, title, content); } @@ -67,16 +57,6 @@ public void addImages(final RoadmapNodeImages roadmapNodeImages) { this.roadmapNodeImages.addAll(roadmapNodeImages); } - public boolean isNotSameRoadmapContent(final RoadmapContent roadmapContent) { - return this.roadmapContent == null || !this.roadmapContent.equals(roadmapContent); - } - - public void updateRoadmapContent(final RoadmapContent roadmapContent) { - if (this.roadmapContent == null) { - this.roadmapContent = roadmapContent; - } - } - public String getTitle() { return title; } @@ -85,10 +65,6 @@ public String getContent() { return content; } - public RoadmapContent getRoadmapContent() { - return roadmapContent; - } - public RoadmapNodeImages getRoadmapNodeImages() { return roadmapNodeImages; } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImage.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImage.java similarity index 97% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImage.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImage.java index 4713f04a2..2e8a68d1c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImage.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImage.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; import co.kirikiri.common.type.ImageContentType; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImages.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImages.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImages.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImages.java index 8d33922dc..d939b4f5d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImages.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImages.java @@ -1,14 +1,14 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.CascadeType; import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.NoArgsConstructor; import java.util.ArrayList; import java.util.List; -import lombok.NoArgsConstructor; @Embeddable @NoArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodes.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodes.java similarity index 78% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodes.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodes.java index 728d15b6f..2e6ab937b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodes.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodes.java @@ -1,16 +1,17 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.CascadeType; import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -18,7 +19,8 @@ public class RoadmapNodes { @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, - mappedBy = "roadmapContent") + orphanRemoval = true) + @JoinColumn(name = "roadmap_content_id", nullable = false) private final List values = new ArrayList<>(); public RoadmapNodes(final List roadmapNodes) { @@ -46,18 +48,6 @@ public void addAll(final RoadmapNodes roadmapNodes) { validateTitleDistinct(values); } - public void updateAllRoadmapContent(final RoadmapContent content) { - for (final RoadmapNode roadmapNode : values) { - updateRoadmapContent(roadmapNode, content); - } - } - - private void updateRoadmapContent(final RoadmapNode roadmapNode, final RoadmapContent content) { - if (roadmapNode.isNotSameRoadmapContent(content)) { - roadmapNode.updateRoadmapContent(content); - } - } - public Optional findById(final Long roadmapNodeId) { return values.stream() .filter(it -> it.getId().equals(roadmapNodeId)) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReview.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapReview.java similarity index 69% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReview.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapReview.java index 5a9af09ec..f13644b4e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReview.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapReview.java @@ -1,16 +1,12 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseUpdatedTimeEntity; -import co.kirikiri.member.domain.Member; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.regex.Pattern; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -29,21 +25,18 @@ public class RoadmapReview extends BaseUpdatedTimeEntity { @Column(nullable = false) private Double rate = 0.0; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; + private Long memberId; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "roadmap_id") - private Roadmap roadmap; + private Long roadmapId; - public RoadmapReview(final String content, final Double rate, final Member member) { + public RoadmapReview(final String content, final Double rate, final Long memberId, final Long roadmapId) { if (content != null) { validate(content, rate); } this.content = content; this.rate = rate; - this.member = member; + this.memberId = memberId; + this.roadmapId = roadmapId; } private void validate(final String content, final Double rate) { @@ -64,16 +57,6 @@ private void validateRate(final Double rate) { } } - public void updateRoadmap(final Roadmap roadmap) { - if (this.roadmap == null) { - this.roadmap = roadmap; - } - } - - public boolean isNotSameRoadmap(final Roadmap roadmap) { - return this.roadmap == null || !this.roadmap.equals(roadmap); - } - public String getContent() { return content; } @@ -82,7 +65,11 @@ public Double getRate() { return rate; } - public Member getMember() { - return member; + public Long getMemberId() { + return memberId; + } + + public Long getRoadmapId() { + return roadmapId; } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapStatus.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapStatus.java similarity index 61% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapStatus.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapStatus.java index 2e24fc540..e730beb56 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapStatus.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapStatus.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; public enum RoadmapStatus { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTag.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTag.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTag.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTag.java index 6fb21f164..ec2feeebb 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTag.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTag.java @@ -1,7 +1,7 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import lombok.AccessLevel; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTags.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTags.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTags.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTags.java index 763c920cb..7f863adf7 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTags.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTags.java @@ -1,19 +1,19 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; import jakarta.persistence.CascadeType; import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.BatchSize; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/exception/RoadmapException.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/exception/RoadmapException.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/exception/RoadmapException.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/exception/RoadmapException.java index 987fc96ef..94c568120 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/exception/RoadmapException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/exception/RoadmapException.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap.exception; +package co.kirikiri.roadmap.domain.exception; import co.kirikiri.common.exception.domain.DomainException; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/vo/RoadmapTagName.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/vo/RoadmapTagName.java similarity index 88% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/vo/RoadmapTagName.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/vo/RoadmapTagName.java index 711208319..9b568e2fe 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/vo/RoadmapTagName.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/vo/RoadmapTagName.java @@ -1,10 +1,10 @@ -package co.kirikiri.domain.roadmap.vo; +package co.kirikiri.roadmap.domain.vo; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Objects; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class RoadmapTagName { @@ -16,7 +16,7 @@ public class RoadmapTagName { private String value; public RoadmapTagName(final String value) { - final String removedSpaceValue = value.replaceAll(" ", ""); + final String removedSpaceValue = value.replace(" ", ""); validate(removedSpaceValue); this.value = removedSpaceValue; } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapCategoryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapCategoryRepository.java similarity index 72% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapCategoryRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapCategoryRepository.java index 37d52022b..a7250e476 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapCategoryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapCategoryRepository.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; -import co.kirikiri.domain.roadmap.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapCategory; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java new file mode 100644 index 000000000..54396bac9 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java @@ -0,0 +1,15 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapContent; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; + +public interface RoadmapContentRepository extends JpaRepository { + + Optional findFirstByRoadmapIdOrderByCreatedAtDesc(final Long roadmapId); + + List findAllByRoadmapId(final Long roadmapId); + + void deleteAllByRoadmapId(final Long roadmapId); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepository.java similarity index 63% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepository.java index a88016dc5..c583aace7 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepository.java @@ -1,11 +1,9 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; -import co.kirikiri.member.domain.Member; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchDto; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; import java.util.List; import java.util.Optional; @@ -23,11 +21,9 @@ List findRoadmapsByCond(final RoadmapSearchDto searchRequest, final Long lastId, final int pageSize); - List findRoadmapsWithCategoryByMemberOrderByLatest(final Member member, - final Long lastId, - final int pageSize); + List findRoadmapsWithCategoryByMemberIdOrderByLatest(final Long memberId, + final Long lastId, + final int pageSize); Optional findByIdAndMemberIdentifier(final Long roadmapId, final String identifier); - - List findWithRoadmapContentByStatus(final RoadmapStatus status); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepositoryImpl.java similarity index 79% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepositoryImpl.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepositoryImpl.java index 998dcd62f..ba7f7f3b9 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepositoryImpl.java @@ -1,25 +1,23 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; import static co.kirikiri.domain.goalroom.QGoalRoom.goalRoom; import static co.kirikiri.domain.goalroom.QGoalRoomMember.goalRoomMember; -import static co.kirikiri.domain.roadmap.QRoadmap.roadmap; -import static co.kirikiri.domain.roadmap.QRoadmapCategory.roadmapCategory; -import static co.kirikiri.domain.roadmap.QRoadmapContent.roadmapContent; -import static co.kirikiri.domain.roadmap.QRoadmapReview.roadmapReview; -import static co.kirikiri.domain.roadmap.QRoadmapTag.roadmapTag; import static co.kirikiri.member.domain.QMember.member; +import static co.kirikiri.roadmap.domain.QRoadmap.roadmap; +import static co.kirikiri.roadmap.domain.QRoadmapCategory.roadmapCategory; +import static co.kirikiri.roadmap.domain.QRoadmapReview.roadmapReview; +import static co.kirikiri.roadmap.domain.QRoadmapTag.roadmapTag; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.member.domain.Member; import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.persistence.QuerydslRepositorySupporter; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchCreatorNickname; -import co.kirikiri.persistence.dto.RoadmapSearchDto; -import co.kirikiri.persistence.dto.RoadmapSearchTagName; -import co.kirikiri.persistence.dto.RoadmapSearchTitle; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchCreatorNickname; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchTagName; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchTitle; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; @@ -41,8 +39,6 @@ public RoadmapQueryRepositoryImpl() { @Override public Optional findRoadmapById(final Long roadmapId) { return Optional.ofNullable(selectFrom(roadmap) - .innerJoin(roadmap.creator, member) - .fetchJoin() .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() .leftJoin(roadmap.tags.values, roadmapTag) @@ -57,8 +53,6 @@ public List findRoadmapsByCategory(final RoadmapCategory category, fina return selectFrom(roadmap) .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() - .innerJoin(roadmap.creator, member) - .fetchJoin() .where( lessThanLastId(lastId, orderType), statusCond(RoadmapStatus.CREATED), @@ -74,8 +68,6 @@ public List findRoadmapsByCond(final RoadmapSearchDto searchRequest, fi return selectFrom(roadmap) .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() - .innerJoin(roadmap.creator, member) - .fetchJoin() .where( lessThanLastId(lastId, orderType), statusCond(RoadmapStatus.CREATED), @@ -88,15 +80,15 @@ public List findRoadmapsByCond(final RoadmapSearchDto searchRequest, fi } @Override - public List findRoadmapsWithCategoryByMemberOrderByLatest(final Member member, - final Long lastId, - final int pageSize) { + public List findRoadmapsWithCategoryByMemberIdOrderByLatest(final Long memberId, + final Long lastId, + final int pageSize) { final RoadmapOrderType orderType = RoadmapOrderType.LATEST; return selectFrom(roadmap) .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() .where( - creatorIdCond(member.getId()), + creatorIdCond(memberId), lessThanLastId(lastId, orderType)) .limit(pageSize + LIMIT_OFFSET) .orderBy(sortCond(orderType)) @@ -111,15 +103,6 @@ public Optional findByIdAndMemberIdentifier(final Long roadmapId, final .fetchOne()); } - @Override - public List findWithRoadmapContentByStatus(final RoadmapStatus status) { - return selectFrom(roadmap) - .innerJoin(roadmap.contents.values, roadmapContent) - .fetchJoin() - .where(statusCond(status)) - .fetch(); - } - private BooleanExpression roadmapCond(final Long roadmapId) { return roadmap.id.eq(roadmapId); } @@ -150,14 +133,17 @@ private BooleanExpression creatorIdCond(final Long creatorId) { if (creatorId == null) { return null; } - return roadmap.creator.id.eq(creatorId); + return roadmap.creatorId.eq(creatorId); } private BooleanExpression creatorNicknameCond(final RoadmapSearchCreatorNickname creatorName) { if (creatorName == null) { return null; } - return roadmap.creator.nickname.value.eq(creatorName.value()); + return roadmap.creatorId + .eq(select(member.id) + .from(member) + .where(member.nickname.value.eq(creatorName.value()))); } private BooleanExpression tagCond(final RoadmapSearchTagName tagName) { @@ -174,19 +160,19 @@ private OrderSpecifier sortCond(final RoadmapOrderType orderType) { if (orderType == RoadmapOrderType.GOAL_ROOM_COUNT) { return new OrderSpecifier<>( Order.DESC, - goalRoomCountCond(goalRoom.roadmapContent.roadmap.eq(roadmap)) + goalRoomCountCond(goalRoom.roadmapContent.roadmapId.eq(roadmap.id)) ); } if (orderType == RoadmapOrderType.PARTICIPANT_COUNT) { return new OrderSpecifier<>( Order.DESC, - participantCountCond(goalRoomMember.goalRoom.roadmapContent.roadmap.eq(roadmap)) + participantCountCond(goalRoomMember.goalRoom.roadmapContent.roadmapId.eq(roadmap.id)) ); } if (orderType == RoadmapOrderType.REVIEW_RATE) { return new OrderSpecifier<>( Order.DESC, - reviewRateCond(roadmapReview.roadmap.eq(roadmap)) + reviewRateCond(roadmapReview.roadmapId.eq(roadmap.id)) ); } return roadmap.createdAt.desc(); @@ -215,17 +201,17 @@ private BooleanExpression lessThanLastId(final Long lastId, final RoadmapOrderTy return null; } if (orderType == RoadmapOrderType.GOAL_ROOM_COUNT) { - final NumberPath goalRoomRoadmapId = goalRoom.roadmapContent.roadmap.id; + final NumberPath goalRoomRoadmapId = goalRoom.roadmapContent.roadmapId; return goalRoomCountCond(goalRoomRoadmapId.eq(roadmap.id)) .lt(goalRoomCountCond(goalRoomRoadmapId.eq(lastId))); } if (orderType == RoadmapOrderType.PARTICIPANT_COUNT) { - final NumberPath goalRoomMemberRoadmapId = goalRoomMember.goalRoom.roadmapContent.roadmap.id; + final NumberPath goalRoomMemberRoadmapId = goalRoomMember.goalRoom.roadmapContent.roadmapId; return participantCountCond(goalRoomMemberRoadmapId.eq(roadmap.id)) .lt(participantCountCond(goalRoomMemberRoadmapId.eq(lastId))); } if (orderType == RoadmapOrderType.REVIEW_RATE) { - final NumberPath roadmapReviewRoadmapId = roadmapReview.roadmap.id; + final NumberPath roadmapReviewRoadmapId = roadmapReview.roadmapId; return reviewRateCond(roadmapReviewRoadmapId.eq(roadmap.id)) .lt(reviewRateCond(roadmapReviewRoadmapId.eq(lastId))); } @@ -238,6 +224,9 @@ private BooleanExpression lessThanLastId(final Long lastId, final RoadmapOrderTy private BooleanExpression creatorIdentifierCond(final String identifier) { final Identifier creatorIdentifier = new Identifier(identifier); - return roadmap.creator.identifier.eq(creatorIdentifier); + return roadmap.creatorId + .eq(select(member.id) + .from(member) + .where(member.identifier.eq(creatorIdentifier))); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java new file mode 100644 index 000000000..a022ac304 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java @@ -0,0 +1,11 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + +public interface RoadmapRepository extends JpaRepository, RoadmapQueryRepository { + + List findByStatus(final RoadmapStatus status); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java new file mode 100644 index 000000000..3cd7c1f08 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java @@ -0,0 +1,11 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapReview; +import java.util.List; + +public interface RoadmapReviewQueryRepository { + + List findRoadmapReviewByRoadmapIdOrderByLatest(final Long roadmapId, + final Long lastId, + final int pageSize); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepositoryImpl.java similarity index 62% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepositoryImpl.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepositoryImpl.java index 5673eef40..161d12969 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepositoryImpl.java @@ -1,11 +1,9 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; -import static co.kirikiri.domain.roadmap.QRoadmapReview.roadmapReview; -import static co.kirikiri.member.domain.QMember.member; +import static co.kirikiri.roadmap.domain.QRoadmapReview.roadmapReview; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapReview; import co.kirikiri.persistence.QuerydslRepositorySupporter; +import co.kirikiri.roadmap.domain.RoadmapReview; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import java.time.LocalDateTime; @@ -19,20 +17,18 @@ public RoadmapReviewQueryRepositoryImpl() { } @Override - public List findRoadmapReviewWithMemberByRoadmapOrderByLatest(final Roadmap roadmap, - final Long lastId, - final int pageSize) { + public List findRoadmapReviewByRoadmapIdOrderByLatest(final Long roadmapId, + final Long lastId, + final int pageSize) { return selectFrom(roadmapReview) - .innerJoin(roadmapReview.member, member) - .fetchJoin() - .where(roadmapCond(roadmap), lessThanLastId(lastId)) + .where(roadmapCond(roadmapId), lessThanLastId(lastId)) .limit(pageSize) .orderBy(orderByCreatedAtDesc()) .fetch(); } - private BooleanExpression roadmapCond(final Roadmap roadmap) { - return roadmapReview.roadmap.eq(roadmap); + private BooleanExpression roadmapCond(final Long roadmapId) { + return roadmapReview.roadmapId.eq(roadmapId); } private BooleanExpression lessThanLastId(final Long lastId) { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java new file mode 100644 index 000000000..f9f6731f3 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java @@ -0,0 +1,12 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapReview; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + +public interface RoadmapReviewRepository extends JpaRepository, RoadmapReviewQueryRepository { + + Optional findByRoadmapIdAndMemberId(final Long roadmapId, final Long memberId); + + void deleteAllByRoadmapId(final Long roadmapId); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapOrderType.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapOrderType.java similarity index 67% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapOrderType.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapOrderType.java index fb4ccb0b6..bafb11c4c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapOrderType.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapOrderType.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; public enum RoadmapOrderType { LATEST, GOAL_ROOM_COUNT, PARTICIPANT_COUNT, REVIEW_RATE diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchCreatorNickname.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchCreatorNickname.java similarity index 85% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchCreatorNickname.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchCreatorNickname.java index 70ab96d1d..34d7d650b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchCreatorNickname.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchCreatorNickname.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; public record RoadmapSearchCreatorNickname( String value diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchDto.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchDto.java similarity index 95% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchDto.java index adde60018..92b34371d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTagName.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagName.java similarity index 80% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTagName.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagName.java index 3ed402e18..85b2649e2 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTagName.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagName.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; public record RoadmapSearchTagName( String value @@ -20,7 +20,7 @@ private String removeBlank(final String name) { private void validateLength(final String name) { if (name.length() < MIN_LENGTH) { - throw new BadRequestException( + throw new RoadmapException( String.format("검색어는 최소 %d자부터 가능합니다.", MIN_LENGTH)); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTitle.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitle.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTitle.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitle.java index 743e78444..9b7b139ad 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTitle.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitle.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; public record RoadmapSearchTitle( String value @@ -20,7 +20,7 @@ private String removeBlank(final String title) { private void validateLength(final String title) { if (title.length() < MIN_LENGTH) { - throw new BadRequestException( + throw new RoadmapException( String.format("검색어는 최소 %d자부터 가능합니다.", MIN_LENGTH)); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolver.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolver.java new file mode 100644 index 000000000..670ad0e4f --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolver.java @@ -0,0 +1,6 @@ +package co.kirikiri.roadmap.resolver; + +import org.springframework.web.method.support.HandlerMethodArgumentResolver; + +public interface RoadmapSaveArgumentResolver extends HandlerMethodArgumentResolver { +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImpl.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImpl.java index 8c668086b..7c8e2642b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImpl.java @@ -1,12 +1,11 @@ -package co.kirikiri.common.resolver; +package co.kirikiri.roadmap.resolver; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.http.HttpServletRequest; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.core.MethodParameter; import org.springframework.stereotype.Component; @@ -15,16 +14,17 @@ import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.support.StandardServletMultipartResolver; +import java.util.List; @Component @RequiredArgsConstructor -public class RoadmapSaveArgumentResolver implements HandlerMethodArgumentResolver { +public class RoadmapSaveArgumentResolverImpl implements RoadmapSaveArgumentResolver { + private final ObjectMapper objectMapper; private final Validator validator; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateEventListener.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateEventListener.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateEventListener.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateEventListener.java index 748e5473c..5a4fee44f 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateEventListener.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateEventListener.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.roadmap; +package co.kirikiri.roadmap.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.BadRequestException; @@ -7,21 +7,21 @@ import co.kirikiri.common.service.FileService; import co.kirikiri.common.type.ImageContentType; import co.kirikiri.common.type.ImageDirType; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.service.dto.RoadmapNodeSaveDto; +import co.kirikiri.roadmap.service.event.RoadmapCreateEvent; import co.kirikiri.service.dto.FileInformation; -import co.kirikiri.service.dto.roadmap.RoadmapNodeSaveDto; -import co.kirikiri.service.event.RoadmapCreateEvent; -import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.event.TransactionalEventListener; +import java.util.List; @Service @RequiredArgsConstructor @@ -35,12 +35,13 @@ public class RoadmapCreateEventListener { @Async @TransactionalEventListener @Transactional + @CacheEvict(value = "roadmapList", allEntries = true) public void handleRoadmapCreate(final RoadmapCreateEvent roadmapCreateEvent) { saveRoadmapNodeImage(roadmapCreateEvent); } private void saveRoadmapNodeImage(final RoadmapCreateEvent roadmapCreateEvent) { - final RoadmapContent lastRoadmapContent = findLastRoadmapContent(roadmapCreateEvent.roadmap()); + final RoadmapContent lastRoadmapContent = findLastRoadmapContent(roadmapCreateEvent.roadmapId()); for (final RoadmapNodeSaveDto roadmapNodeSaveDto : roadmapCreateEvent.roadmapSaveDto().roadmapNodes()) { final RoadmapNode roadmapNode = findRoadmapNodeByTitle(lastRoadmapContent, roadmapNodeSaveDto); final RoadmapNodeImages roadmapNodeImages = makeRoadmapNodeImages(roadmapNodeSaveDto, roadmapNode); @@ -49,8 +50,8 @@ private void saveRoadmapNodeImage(final RoadmapCreateEvent roadmapCreateEvent) { roadmapContentRepository.save(lastRoadmapContent); } - private RoadmapContent findLastRoadmapContent(final Roadmap roadmap) { - return roadmap.findLastRoadmapContent() + private RoadmapContent findLastRoadmapContent(final Long roadmapId) { + return roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(roadmapId) .orElseThrow(() -> new ServerException("로드맵 컨텐츠가 존재하지 않습니다.")); } @@ -58,7 +59,7 @@ private RoadmapNode findRoadmapNodeByTitle(final RoadmapContent lastRoadmapConte final RoadmapNodeSaveDto roadmapNodeSaveDto) { return lastRoadmapContent.findRoadmapNodeByTitle(roadmapNodeSaveDto.title()) .orElseThrow(() -> new BadRequestException( - "해당 제목을 가지고있는 로드맵 노드가 없습니다. title = " + roadmapNodeSaveDto.title())); + "해당 제목을 가지고 있는 로드맵 노드가 없습니다. title = " + roadmapNodeSaveDto.title())); } private RoadmapNodeImages makeRoadmapNodeImages(final RoadmapNodeSaveDto roadmapNodeSaveDto, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateService.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateService.java similarity index 55% rename from backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateService.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateService.java index 4b4b58578..56e3defa2 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateService.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.roadmap; +package co.kirikiri.roadmap.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.AuthenticationException; @@ -6,42 +6,39 @@ import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.goalroom.GoalRoomMember; -import co.kirikiri.domain.goalroom.GoalRoomStatus; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapTag; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; import co.kirikiri.member.domain.Member; import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; -import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; -import co.kirikiri.service.dto.roadmap.RoadmapNodeSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapReviewDto; -import co.kirikiri.service.dto.roadmap.RoadmapSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapTagSaveDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.event.RoadmapCreateEvent; -import co.kirikiri.service.mapper.RoadmapMapper; -import java.util.List; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.service.dto.RoadmapNodeSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapReviewDto; +import co.kirikiri.roadmap.service.dto.RoadmapSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapTagSaveDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.event.RoadmapCreateEvent; +import co.kirikiri.roadmap.service.event.RoadmapDeleteEvent; +import co.kirikiri.roadmap.service.mapper.RoadmapMapper; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; @Service @Transactional @@ -51,21 +48,24 @@ public class RoadmapCreateService { private final MemberRepository memberRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final RoadmapReviewRepository roadmapReviewRepository; - private final GoalRoomRepository goalRoomRepository; - private final GoalRoomMemberRepository goalRoomMemberRepository; private final RoadmapCategoryRepository roadmapCategoryRepository; + private final RoadmapGoalRoomService roadmapGoalRoomService; private final ApplicationEventPublisher applicationEventPublisher; - @CacheEvict(value = "roadmapList", allEntries = true) public Long create(final RoadmapSaveRequest request, final String identifier) { final Member member = findMemberByIdentifier(identifier); final RoadmapCategory roadmapCategory = findRoadmapCategoryById(request.categoryId()); final RoadmapSaveDto roadmapSaveDto = RoadmapMapper.convertToRoadmapSaveDto(request); - final Roadmap roadmap = createRoadmap(member, roadmapSaveDto, roadmapCategory); + + final Roadmap roadmap = makeRoadmap(member.getId(), roadmapSaveDto, roadmapCategory); final Roadmap savedRoadmap = roadmapRepository.save(roadmap); - applicationEventPublisher.publishEvent(new RoadmapCreateEvent(savedRoadmap, roadmapSaveDto)); + final RoadmapContent roadmapContent = makeRoadmapContent(roadmapSaveDto, savedRoadmap.getId()); + roadmapContentRepository.save(roadmapContent); + + applicationEventPublisher.publishEvent(new RoadmapCreateEvent(savedRoadmap.getId(), roadmapSaveDto)); return savedRoadmap.getId(); } @@ -80,29 +80,12 @@ private RoadmapCategory findRoadmapCategoryById(final Long categoryId) { .orElseThrow(() -> new NotFoundException("존재하지 않는 카테고리입니다. categoryId = " + categoryId)); } - private Roadmap createRoadmap(final Member member, final RoadmapSaveDto roadmapSaveDto, - final RoadmapCategory roadmapCategory) { - final RoadmapNodes roadmapNodes = makeRoadmapNodes(roadmapSaveDto.roadmapNodes()); - final RoadmapContent roadmapContent = makeRoadmapContent(roadmapSaveDto, roadmapNodes); + private Roadmap makeRoadmap(final Long memberId, final RoadmapSaveDto roadmapSaveDto, + final RoadmapCategory roadmapCategory) { final RoadmapTags roadmapTags = makeRoadmapTags(roadmapSaveDto.tags()); - final Roadmap roadmap = makeRoadmap(member, roadmapSaveDto, roadmapCategory); - roadmap.addContent(roadmapContent); - roadmap.addTags(roadmapTags); - return roadmap; - } - - private RoadmapNodes makeRoadmapNodes(final List roadmapNodeSaveDtos) { - return new RoadmapNodes( - roadmapNodeSaveDtos.stream() - .map(node -> new RoadmapNode(node.title(), node.content())) - .toList() - ); - } - - private RoadmapContent makeRoadmapContent(final RoadmapSaveDto roadmapSaveDto, final RoadmapNodes roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent(roadmapSaveDto.content()); - roadmapContent.addNodes(roadmapNodes); - return roadmapContent; + return new Roadmap(roadmapSaveDto.title(), roadmapSaveDto.introduction(), + roadmapSaveDto.requiredPeriod(), RoadmapDifficulty.valueOf(roadmapSaveDto.difficulty().name()), memberId, + roadmapCategory, roadmapTags); } private RoadmapTags makeRoadmapTags(final List roadmapTagSaveDto) { @@ -113,23 +96,29 @@ private RoadmapTags makeRoadmapTags(final List roadmapTagSave ); } - private Roadmap makeRoadmap(final Member member, final RoadmapSaveDto roadmapSaveDto, - final RoadmapCategory roadmapCategory) { - return new Roadmap(roadmapSaveDto.title(), roadmapSaveDto.introduction(), - roadmapSaveDto.requiredPeriod(), RoadmapDifficulty.valueOf(roadmapSaveDto.difficulty().name()), member, - roadmapCategory); + private RoadmapContent makeRoadmapContent(final RoadmapSaveDto roadmapSaveDto, final Long roadmapId) { + final RoadmapNodes nodes = makeRoadmapNodes(roadmapSaveDto.roadmapNodes()); + return new RoadmapContent(roadmapSaveDto.content(), roadmapId, nodes); + } + + private RoadmapNodes makeRoadmapNodes(final List roadmapNodeSaveDtos) { + return new RoadmapNodes( + roadmapNodeSaveDtos.stream() + .map(node -> new RoadmapNode(node.title(), node.content())) + .toList() + ); } public void createReview(final Long roadmapId, final String identifier, final RoadmapReviewSaveRequest request) { final Roadmap roadmap = findRoadmapById(roadmapId); - final GoalRoomMember goalRoomMember = findCompletedGoalRoomMember(roadmapId, identifier); - final Member member = goalRoomMember.getMember(); - final RoadmapReviewDto roadmapReviewDto = RoadmapMapper.convertRoadmapReviewDto(request, member); - validateReviewQualification(roadmap, member); - validateReviewCount(roadmap, member); - final RoadmapReview roadmapReview = new RoadmapReview(roadmapReviewDto.content(), roadmapReviewDto.rate(), - roadmapReviewDto.member()); - roadmap.addReview(roadmapReview); + final Long memberId = roadmapGoalRoomService.findCompletedGoalRoomMember(roadmapId, identifier) + .getId(); + + validateReviewQualification(roadmap, memberId); + validateReviewCount(roadmapId, memberId); + final RoadmapReviewDto roadmapReviewDto = RoadmapMapper.convertRoadmapReviewDto(request, memberId); + final RoadmapReview roadmapReview = new RoadmapReview(roadmapReviewDto.content(), roadmapReviewDto.rate(), memberId, roadmapId); + roadmapReviewRepository.save(roadmapReview); } private Roadmap findRoadmapById(final Long id) { @@ -137,24 +126,17 @@ private Roadmap findRoadmapById(final Long id) { .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = " + id)); } - private GoalRoomMember findCompletedGoalRoomMember(final Long roadmapId, final String identifier) { - return goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(roadmapId, - new Identifier(identifier), GoalRoomStatus.COMPLETED) - .orElseThrow(() -> new BadRequestException( - "로드맵에 대해서 완료된 골룸이 존재하지 않습니다. roadmapId = " + roadmapId + " memberIdentifier = " + identifier)); - } - - private void validateReviewQualification(final Roadmap roadmap, final Member member) { - if (roadmap.isCreator(member)) { + private void validateReviewQualification(final Roadmap roadmap, final Long memberId) { + if (roadmap.isCreator(memberId)) { throw new BadRequestException( - "로드맵 생성자는 리뷰를 달 수 없습니다. roadmapId = " + roadmap.getId() + " memberId = " + member.getId()); + "로드맵 생성자는 리뷰를 달 수 없습니다. roadmapId = " + roadmap.getId() + " memberId = " + memberId); } } - private void validateReviewCount(final Roadmap roadmap, final Member member) { - if (roadmapReviewRepository.findByRoadmapAndMember(roadmap, member).isPresent()) { + private void validateReviewCount(final Long roadmapId, final Long memberId) { + if (roadmapReviewRepository.findByRoadmapIdAndMemberId(roadmapId, memberId).isPresent()) { throw new BadRequestException( - "이미 작성한 리뷰가 존재합니다. roadmapId = " + roadmap.getId() + " memberId = " + member.getId()); + "이미 작성한 리뷰가 존재합니다. roadmapId = " + roadmapId + " memberId = " + memberId); } } @@ -162,8 +144,9 @@ private void validateReviewCount(final Roadmap roadmap, final Member member) { public void deleteRoadmap(final String identifier, final Long roadmapId) { final Roadmap roadmap = findRoadmapById(roadmapId); validateRoadmapCreator(roadmapId, identifier); - final List goalRooms = goalRoomRepository.findByRoadmap(roadmap); - if (goalRooms.isEmpty()) { + if (!roadmapGoalRoomService.hasGoalRooms(roadmapId)) { + applicationEventPublisher.publishEvent(new RoadmapDeleteEvent(roadmap.getId(), "Review")); + roadmapContentRepository.deleteAllByRoadmapId(roadmapId); roadmapRepository.delete(roadmap); return; } @@ -171,8 +154,9 @@ public void deleteRoadmap(final String identifier, final Long roadmapId) { } private void validateRoadmapCreator(final Long roadmapId, final String identifier) { - roadmapRepository.findByIdAndMemberIdentifier(roadmapId, identifier) - .orElseThrow(() -> new ForbiddenException("해당 로드맵을 생성한 사용자가 아닙니다.")); + if (roadmapRepository.findByIdAndMemberIdentifier(roadmapId, identifier).isEmpty()) { + throw new ForbiddenException("해당 로드맵을 생성한 사용자가 아닙니다."); + } } @CacheEvict(value = "categoryList", allEntries = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java new file mode 100644 index 000000000..0dbc56f73 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java @@ -0,0 +1,21 @@ +package co.kirikiri.roadmap.service; + +import co.kirikiri.member.domain.Member; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.service.dto.CustomScrollRequest; + +public interface RoadmapGoalRoomService { + + Member findCompletedGoalRoomMember(final Long roadmapId, final String identifier); + + boolean hasGoalRooms(final Long roadmapId); + + RoadmapGoalRoomNumberDto findRoadmapGoalRoomsByRoadmap(final Roadmap roadmap); + + RoadmapGoalRoomResponses makeRoadmapGoalRoomResponsesByOrderType(final Long roadmapId, final RoadmapGoalRoomsOrderTypeDto orderTypeDto, final CustomScrollRequest scrollRequest); + + boolean canDeleteGoalRoomsInRoadmap(final Long roadmapId); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapReadService.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReadService.java similarity index 69% rename from backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapReadService.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReadService.java index 35af34aba..945d37cc5 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapReadService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReadService.java @@ -1,59 +1,53 @@ -package co.kirikiri.service.roadmap; +package co.kirikiri.roadmap.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.NotFoundException; +import co.kirikiri.common.mapper.ScrollResponseMapper; import co.kirikiri.common.service.FileService; -import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapTags; import co.kirikiri.member.domain.Member; import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.member.service.dto.MemberDto; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchDto; -import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; +import co.kirikiri.roadmap.service.dto.RoadmapCategoryDto; +import co.kirikiri.roadmap.service.dto.RoadmapContentDto; +import co.kirikiri.roadmap.service.dto.RoadmapDto; +import co.kirikiri.roadmap.service.dto.RoadmapForListDto; +import co.kirikiri.roadmap.service.dto.RoadmapForListScrollDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.RoadmapNodeDto; +import co.kirikiri.roadmap.service.dto.RoadmapReviewReadDto; +import co.kirikiri.roadmap.service.dto.RoadmapTagDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; +import co.kirikiri.roadmap.service.mapper.RoadmapMapper; import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.goalroom.RoadmapGoalRoomDto; -import co.kirikiri.service.dto.goalroom.RoadmapGoalRoomScrollDto; -import co.kirikiri.service.dto.roadmap.RoadmapCategoryDto; -import co.kirikiri.service.dto.roadmap.RoadmapContentDto; -import co.kirikiri.service.dto.roadmap.RoadmapDto; -import co.kirikiri.service.dto.roadmap.RoadmapForListDto; -import co.kirikiri.service.dto.roadmap.RoadmapForListScrollDto; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomNumberDto; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.RoadmapNodeDto; -import co.kirikiri.service.dto.roadmap.RoadmapReviewReadDto; -import co.kirikiri.service.dto.roadmap.RoadmapTagDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.mapper.GoalRoomMapper; -import co.kirikiri.service.mapper.RoadmapMapper; -import co.kirikiri.service.mapper.ScrollResponseMapper; -import java.net.URL; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.Cacheable; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.net.URL; +import java.util.List; @Service @Transactional(readOnly = true) @@ -65,23 +59,32 @@ public class RoadmapReadService { private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapContentRepository roadmapContentRepository; private final RoadmapReviewRepository roadmapReviewRepository; - private final GoalRoomRepository goalRoomRepository; + private final RoadmapGoalRoomService roadmapGoalRoomService; private final MemberRepository memberRepository; private final FileService fileService; @Cacheable(value = "roadmap", keyGenerator = "cacheKeyGenerator", cacheManager = "redisCacheManager") - public RoadmapResponse findRoadmap(final Long id) { - final Roadmap roadmap = findRoadmapById(id); - final RoadmapContent recentRoadmapContent = findRecentContent(roadmap); - final List goalRooms = goalRoomRepository.findByRoadmap(roadmap); - final RoadmapGoalRoomNumberDto roadmapGoalRoomNumberDto = GoalRoomMapper.convertRoadmapGoalRoomDto(goalRooms); + public RoadmapResponse findRoadmap(final Long roadmapId) { + final Roadmap roadmap = findRoadmapById(roadmapId); + final RoadmapContent recentRoadmapContent = findRecentContent(roadmapId); + final RoadmapGoalRoomNumberDto roadmapGoalRoomNumberDto = roadmapGoalRoomService.findRoadmapGoalRoomsByRoadmap(roadmap); final RoadmapDto roadmapDto = makeRoadmapDto(roadmap, recentRoadmapContent); return RoadmapMapper.convertToRoadmapResponse(roadmapDto, roadmapGoalRoomNumberDto); } + private Roadmap findRoadmapById(final Long id) { + return roadmapRepository.findById(id) + .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = " + id)); + } + + private RoadmapContent findRecentContent(final Long roadmapId) { + return roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(roadmapId) + .orElseThrow(() -> new NotFoundException("로드맵에 컨텐츠가 존재하지 않습니다.")); + } + private RoadmapDto makeRoadmapDto(final Roadmap roadmap, final RoadmapContent roadmapContent) { final RoadmapCategory category = roadmap.getCategory(); - final Member creator = roadmap.getCreator(); + final Member creator = findMemberById(roadmap.getCreatorId()); final RoadmapContentDto roadmapContentDto = new RoadmapContentDto( roadmapContent.getId(), roadmapContent.getContent(), @@ -92,6 +95,11 @@ private RoadmapDto makeRoadmapDto(final Roadmap roadmap, final RoadmapContent ro roadmap.getCreatedAt(), makeRoadmapTagDtos(roadmap.getTags())); } + private Member findMemberById(final Long memberId) { + return memberRepository.findWithMemberProfileAndImageById(memberId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 회원입니다.")); + } + private MemberDto makeMemberDto(final Member creator) { final URL url = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); return new MemberDto(creator.getId(), creator.getNickname().getValue(), url.toExternalForm()); @@ -120,16 +128,6 @@ private List makeRoadmapTagDtos(final RoadmapTags roadmapTags) { .toList(); } - private Roadmap findRoadmapById(final Long id) { - return roadmapRepository.findRoadmapById(id) - .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = " + id)); - } - - private RoadmapContent findRecentContent(final Roadmap roadmap) { - return roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(roadmap) - .orElseThrow(() -> new NotFoundException("로드맵에 컨텐츠가 존재하지 않습니다.")); - } - @Cacheable(value = "roadmapList", keyGenerator = "cacheKeyGenerator", cacheManager = "redisCacheManager") public RoadmapForListResponses findRoadmapsByOrderType(final Long categoryId, final RoadmapOrderTypeRequest orderTypeRequest, @@ -164,7 +162,7 @@ private RoadmapForListDto makeRoadmapForListDto(final Roadmap roadmap) { final RoadmapCategory category = roadmap.getCategory(); final RoadmapCategoryDto roadmapCategoryDto = new RoadmapCategoryDto(category.getId(), category.getName()); - final Member creator = roadmap.getCreator(); + final Member creator = findMemberById(roadmap.getCreatorId()); final URL creatorImageUrl = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); final MemberDto memberDto = new MemberDto(creator.getId(), creator.getNickname().getValue(), creatorImageUrl.toExternalForm()); @@ -212,7 +210,7 @@ public List findAllRoadmapCategories() { public MemberRoadmapResponses findAllMemberRoadmaps(final String identifier, final CustomScrollRequest scrollRequest) { final Member member = findMemberByIdentifier(identifier); - final List roadmaps = roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest(member, + final List roadmaps = roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest(member.getId(), scrollRequest.lastId(), scrollRequest.size()); return RoadmapMapper.convertMemberRoadmapResponses(roadmaps, scrollRequest.size()); } @@ -226,37 +224,14 @@ public RoadmapGoalRoomResponses findRoadmapGoalRoomsByOrderType(final Long roadm final RoadmapGoalRoomsOrderTypeDto orderTypeDto, final CustomScrollRequest scrollRequest) { final Roadmap roadmap = findRoadmapById(roadmapId); - final RoadmapGoalRoomsOrderType orderType = GoalRoomMapper.convertToGoalRoomOrderType(orderTypeDto); - final List goalRooms = goalRoomRepository.findGoalRoomsByRoadmapAndCond( - roadmap, orderType, scrollRequest.lastId(), scrollRequest.size()); - final RoadmapGoalRoomScrollDto roadmapGoalRoomScrollDto = makeGoalRoomDtos(goalRooms, - scrollRequest.size()); - return GoalRoomMapper.convertToRoadmapGoalRoomResponses(roadmapGoalRoomScrollDto); - } - - public RoadmapGoalRoomScrollDto makeGoalRoomDtos(final List goalRooms, - final int requestSize) { - final List roadmapGoalRoomDtos = goalRooms.stream() - .map(this::makeGoalRoomDto) - .toList(); - final List subDtos = ScrollResponseMapper.getSubResponses(roadmapGoalRoomDtos, requestSize); - final boolean hasNext = ScrollResponseMapper.hasNext(roadmapGoalRoomDtos.size(), requestSize); - return new RoadmapGoalRoomScrollDto(subDtos, hasNext); - } - - private RoadmapGoalRoomDto makeGoalRoomDto(final GoalRoom goalRoom) { - final Member goalRoomLeader = goalRoom.findGoalRoomLeader(); - return new RoadmapGoalRoomDto(goalRoom.getId(), goalRoom.getName().getValue(), goalRoom.getStatus(), - goalRoom.getCurrentMemberCount(), goalRoom.getLimitedMemberCount().getValue(), - goalRoom.getCreatedAt(), goalRoom.getStartDate(), - goalRoom.getEndDate(), makeMemberDto(goalRoomLeader)); + return roadmapGoalRoomService.makeRoadmapGoalRoomResponsesByOrderType(roadmap.getId(), orderTypeDto, scrollRequest); } public List findRoadmapReviews(final Long roadmapId, final CustomScrollRequest scrollRequest) { final Roadmap roadmap = findRoadmapById(roadmapId); - final List roadmapReviews = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap, scrollRequest.lastId(), scrollRequest.size()); + final List roadmapReviews = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmap.getId(), scrollRequest.lastId(), scrollRequest.size()); final List roadmapReviewReadDtos = makeRoadmapReviewReadDtos(roadmapReviews); return RoadmapMapper.convertToRoadmapReviewResponses(roadmapReviewReadDtos); } @@ -268,7 +243,7 @@ public List makeRoadmapReviewReadDtos(final List convertRoadmapCategoryResponses( } public static RoadmapReviewDto convertRoadmapReviewDto(final RoadmapReviewSaveRequest request, - final Member member) { - return new RoadmapReviewDto(request.content(), request.rate(), member); + final Long memberId) { + return new RoadmapReviewDto(request.content(), request.rate(), memberId); } public static MemberRoadmapResponses convertMemberRoadmapResponses(final List roadmaps, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java new file mode 100644 index 000000000..d47a8b156 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java @@ -0,0 +1,46 @@ +package co.kirikiri.roadmap.service.scheduler; + +import co.kirikiri.common.aop.ExceptionConvert; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.service.RoadmapGoalRoomService; +import co.kirikiri.roadmap.service.event.RoadmapDeleteEvent; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +@Component +@Transactional +@RequiredArgsConstructor +@ExceptionConvert +public class RoadmapScheduler { + + private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; + private final RoadmapGoalRoomService roadmapGoalRoomService; + private final ApplicationEventPublisher applicationEventPublisher; + + @Scheduled(cron = "0 0 4 * * *") + public void deleteRoadmaps() { + final RoadmapStatus status = RoadmapStatus.DELETED; + final List deletedStatusRoadmaps = roadmapRepository.findByStatus(status); + for (final Roadmap roadmap : deletedStatusRoadmaps) { + delete(roadmap); + } + } + + private void delete(final Roadmap roadmap) { + final boolean canDelete = roadmapGoalRoomService.canDeleteGoalRoomsInRoadmap(roadmap.getId()); + // TODO : GoalRoom 내부의 Roadmap 직접 의존 제거 시 로드맵에 포함된 GoalRoom 따로 제거해주기 (이벤트 활용) + if (canDelete) { + applicationEventPublisher.publishEvent(new RoadmapDeleteEvent(roadmap.getId(), "Review")); + roadmapContentRepository.deleteAllByRoadmapId(roadmap.getId()); + roadmapRepository.delete(roadmap); + } + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java index 30a337e1f..7b9e5372f 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java @@ -1,8 +1,8 @@ package co.kirikiri.service; import co.kirikiri.common.service.NumberGenerator; -import java.util.Random; import org.springframework.stereotype.Component; +import java.util.Random; @Component public class RandomNumberGenerator implements NumberGenerator { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java index ebdf8ca81..c3258879d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java @@ -3,10 +3,10 @@ import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.type.ImageDirType; +import org.springframework.stereotype.Component; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.UUID; -import org.springframework.stereotype.Component; @Component public class UUIDFilePathGenerator implements FilePathGenerator { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java b/backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java deleted file mode 100644 index 02bcb7306..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.service.dto.roadmap; - -import co.kirikiri.member.domain.Member; - -public record RoadmapReviewDto( - String content, - Double rate, - Member member -) { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java b/backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java deleted file mode 100644 index d0e3d129c..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.service.event; - -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.service.dto.roadmap.RoadmapSaveDto; - -public record RoadmapCreateEvent( - Roadmap roadmap, - RoadmapSaveDto roadmapSaveDto -) { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomCreateService.java b/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomCreateService.java index 6ebc192c1..550c07408 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomCreateService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomCreateService.java @@ -1,6 +1,7 @@ package co.kirikiri.service.goalroom; import co.kirikiri.common.aop.ExceptionConvert; +import co.kirikiri.common.exception.AuthenticationException; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FilePathGenerator; @@ -16,9 +17,6 @@ import co.kirikiri.domain.goalroom.GoalRoomToDo; import co.kirikiri.domain.goalroom.GoalRoomToDoCheck; import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; import co.kirikiri.member.domain.Member; import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.persistence.MemberRepository; @@ -26,7 +24,11 @@ import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; import co.kirikiri.persistence.goalroom.GoalRoomToDoCheckRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import co.kirikiri.service.dto.FileInformation; import co.kirikiri.service.dto.goalroom.GoalRoomCreateDto; import co.kirikiri.service.dto.goalroom.GoalRoomRoadmapNodeDto; @@ -35,14 +37,14 @@ import co.kirikiri.service.dto.goalroom.request.GoalRoomTodoRequest; import co.kirikiri.service.dto.goalroom.response.GoalRoomToDoCheckResponse; import co.kirikiri.service.mapper.GoalRoomMapper; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; @Service @Transactional @@ -54,6 +56,7 @@ public class GoalRoomCreateService { private final FilePathGenerator filePathGenerator; private final MemberRepository memberRepository; private final GoalRoomRepository goalRoomRepository; + private final RoadmapRepository roadmapRepository; private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; private final GoalRoomToDoCheckRepository goalRoomToDoCheckRepository; @@ -75,17 +78,22 @@ public Long create(final GoalRoomCreateRequest goalRoomCreateRequest, final Stri } private RoadmapContent findRoadmapContentById(final Long roadmapContentId) { - return roadmapContentRepository.findByIdWithRoadmap(roadmapContentId) - .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다.")); + return roadmapContentRepository.findById(roadmapContentId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵 컨텐츠입니다.")); } private void validateDeletedRoadmap(final RoadmapContent roadmapContent) { - final Roadmap roadmap = roadmapContent.getRoadmap(); + final Roadmap roadmap = findRoadmapById(roadmapContent.getRoadmapId()); if (roadmap.isDeleted()) { throw new BadRequestException("삭제된 로드맵에 대해 골룸을 생성할 수 없습니다."); } } + private Roadmap findRoadmapById(final Long roadmapId) { + return roadmapRepository.findById(roadmapId) + .orElseThrow(() -> new AuthenticationException("존재하지 않는 로드맵입니다.")); + } + private void validateNodeSizeEqual(final int roadmapNodesSize, final int goalRoomRoadmapNodeDtosSize) { if (roadmapNodesSize != goalRoomRoadmapNodeDtosSize) { throw new BadRequestException("모든 노드에 대해 기간이 설정돼야 합니다."); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomReadService.java b/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomReadService.java index 8f99ae9b2..becc9da3e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomReadService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/GoalRoomReadService.java @@ -13,7 +13,6 @@ import co.kirikiri.domain.goalroom.GoalRoomStatus; import co.kirikiri.domain.goalroom.GoalRoomToDoCheck; import co.kirikiri.domain.goalroom.GoalRoomToDos; -import co.kirikiri.domain.roadmap.RoadmapNode; import co.kirikiri.member.domain.Member; import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.persistence.MemberRepository; @@ -24,6 +23,7 @@ import co.kirikiri.persistence.goalroom.GoalRoomRepository; import co.kirikiri.persistence.goalroom.GoalRoomToDoCheckRepository; import co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType; +import co.kirikiri.roadmap.domain.RoadmapNode; import co.kirikiri.service.dto.goalroom.CheckFeedDto; import co.kirikiri.service.dto.goalroom.GoalRoomCheckFeedDto; import co.kirikiri.service.dto.goalroom.GoalRoomMemberDto; @@ -40,15 +40,15 @@ import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomForListResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; import co.kirikiri.service.mapper.GoalRoomMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.net.URL; import java.time.LocalDate; import java.util.Collections; import java.util.List; import java.util.Optional; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpMethod; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service @Transactional(readOnly = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/RoadmapGoalRoomServiceImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/RoadmapGoalRoomServiceImpl.java new file mode 100644 index 000000000..90a126e66 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/goalroom/RoadmapGoalRoomServiceImpl.java @@ -0,0 +1,103 @@ +package co.kirikiri.service.goalroom; + +import co.kirikiri.common.aop.ExceptionConvert; +import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.common.mapper.ScrollResponseMapper; +import co.kirikiri.common.service.FileService; +import co.kirikiri.domain.goalroom.GoalRoom; +import co.kirikiri.domain.goalroom.GoalRoomStatus; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.service.dto.MemberDto; +import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; +import co.kirikiri.persistence.goalroom.GoalRoomRepository; +import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.service.RoadmapGoalRoomService; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.service.dto.CustomScrollRequest; +import co.kirikiri.service.dto.goalroom.RoadmapGoalRoomDto; +import co.kirikiri.service.dto.goalroom.RoadmapGoalRoomScrollDto; +import co.kirikiri.service.mapper.GoalRoomMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.net.URL; +import java.util.List; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +@ExceptionConvert +public class RoadmapGoalRoomServiceImpl implements RoadmapGoalRoomService { + + private static final int DELETE_AFTER_MONTH = 3; + + private final GoalRoomRepository goalRoomRepository; + private final GoalRoomMemberRepository goalRoomMemberRepository; + private final FileService fileService; + + @Override + public Member findCompletedGoalRoomMember(final Long roadmapId, final String identifier) { + return goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(roadmapId, + new Identifier(identifier), GoalRoomStatus.COMPLETED) + .orElseThrow(() -> new BadRequestException( + "로드맵에 대해서 완료된 골룸이 존재하지 않습니다. roadmapId = " + roadmapId + " memberIdentifier = " + identifier)) + .getMember(); + } + + @Override + public boolean hasGoalRooms(final Long roadmapId) { + return !findGoalRoomsByRoadmapId(roadmapId).isEmpty(); + } + + private List findGoalRoomsByRoadmapId(final Long roadmapId) { + return goalRoomRepository.findByRoadmapId(roadmapId); + } + + @Override + public RoadmapGoalRoomNumberDto findRoadmapGoalRoomsByRoadmap(final Roadmap roadmap) { + return GoalRoomMapper.convertRoadmapGoalRoomDto(findGoalRoomsByRoadmapId(roadmap.getId())); + } + + @Override + public RoadmapGoalRoomResponses makeRoadmapGoalRoomResponsesByOrderType(final Long roadmapId, final RoadmapGoalRoomsOrderTypeDto orderTypeDto, final CustomScrollRequest scrollRequest) { + final RoadmapGoalRoomsOrderType orderType = GoalRoomMapper.convertToGoalRoomOrderType(orderTypeDto); + final List roadmapGoalRoomDtos = goalRoomRepository.findGoalRoomsByRoadmapIdAndCond(roadmapId, orderType, scrollRequest.lastId(), scrollRequest.size()) + .stream() + .map(this::makeGoalRoomDto) + .toList(); + final List subDtos = ScrollResponseMapper.getSubResponses(roadmapGoalRoomDtos, scrollRequest.size()); + final boolean hasNext = ScrollResponseMapper.hasNext(roadmapGoalRoomDtos.size(), scrollRequest.size()); + + return GoalRoomMapper.convertToRoadmapGoalRoomResponses(new RoadmapGoalRoomScrollDto(subDtos, hasNext)); + } + + private RoadmapGoalRoomDto makeGoalRoomDto(final GoalRoom goalRoom) { + final Member goalRoomLeader = goalRoom.findGoalRoomLeader(); + return new RoadmapGoalRoomDto(goalRoom.getId(), goalRoom.getName().getValue(), goalRoom.getStatus(), + goalRoom.getCurrentMemberCount(), goalRoom.getLimitedMemberCount().getValue(), + goalRoom.getCreatedAt(), goalRoom.getStartDate(), + goalRoom.getEndDate(), makeMemberDto(goalRoomLeader)); + } + + private MemberDto makeMemberDto(final Member creator) { + final URL url = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); + return new MemberDto(creator.getId(), creator.getNickname().getValue(), url.toExternalForm()); + } + + @Override + @Transactional + public boolean canDeleteGoalRoomsInRoadmap(final Long roadmapId) { + final List goalRooms = goalRoomRepository.findByRoadmapId(roadmapId); + return canDeleteRoadmapBasedOnGoalRooms(goalRooms); + } + + private boolean canDeleteRoadmapBasedOnGoalRooms(final List goalRooms) { + return goalRooms.stream() + .allMatch(goalRoom -> goalRoom.isCompleted() && goalRoom.isCompletedAfterMonths(DELETE_AFTER_MONTH)); + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/GoalRoomMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/GoalRoomMapper.java index 8bb392b19..bbe37f2c6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/GoalRoomMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/GoalRoomMapper.java @@ -16,6 +16,10 @@ import co.kirikiri.member.service.dto.response.MemberResponse; import co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType; import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; import co.kirikiri.service.dto.FileInformation; import co.kirikiri.service.dto.goalroom.CheckFeedDto; import co.kirikiri.service.dto.goalroom.GoalRoomCheckFeedDto; @@ -43,19 +47,15 @@ import co.kirikiri.service.dto.goalroom.response.GoalRoomTodoResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomForListResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomNumberDto; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.time.LocalDate; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.web.multipart.MultipartFile; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class GoalRoomMapper { @@ -152,7 +152,7 @@ public static RoadmapGoalRoomResponses convertToRoadmapGoalRoomResponses( private static RoadmapGoalRoomResponse convertToRoadmapGoalRoomResponse( final RoadmapGoalRoomDto roadmapGoalRoomDto) { return new RoadmapGoalRoomResponse(roadmapGoalRoomDto.goalRoomId(), roadmapGoalRoomDto.name(), - roadmapGoalRoomDto.status(), roadmapGoalRoomDto.currentMemberCount(), + roadmapGoalRoomDto.status().name(), roadmapGoalRoomDto.currentMemberCount(), roadmapGoalRoomDto.limitedMemberCount(), roadmapGoalRoomDto.createdAt(), roadmapGoalRoomDto.startDate(), roadmapGoalRoomDto.endDate(), convertToMemberResponse(roadmapGoalRoomDto.goalRoomLeader())); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/GoalRoomScheduler.java b/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/GoalRoomScheduler.java index cc75c29d6..557bc7507 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/GoalRoomScheduler.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/GoalRoomScheduler.java @@ -8,12 +8,12 @@ import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomPendingMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import java.time.LocalDate; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.util.List; @Component @Transactional diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java b/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java deleted file mode 100644 index fc5518a54..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java +++ /dev/null @@ -1,56 +0,0 @@ -package co.kirikiri.service.scheduler; - -import co.kirikiri.common.aop.ExceptionConvert; -import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -@Component -@Transactional -@RequiredArgsConstructor -@ExceptionConvert -public class RoadmapScheduler { - - private static final int DELETE_AFTER_MONTH = 3; - - private final RoadmapRepository roadmapRepository; - private final GoalRoomRepository goalRoomRepository; - - @Scheduled(cron = "0 0 4 * * *") - public void deleteRoadmaps() { - final RoadmapStatus status = RoadmapStatus.DELETED; - final List deletedStatusRoadmaps = roadmapRepository.findWithRoadmapContentByStatus(status); - for (final Roadmap roadmap : deletedStatusRoadmaps) { - delete(roadmap); - } - } - - private void delete(final Roadmap roadmap) { - final List goalRooms = goalRoomRepository.findByRoadmap(roadmap); - final boolean canDelete = canDeleteRoadmapBasedOnGoalRooms(goalRooms); - if (canDelete) { - deleteGoalRooms(goalRooms); - deleteRoadmap(roadmap); - } - } - - private boolean canDeleteRoadmapBasedOnGoalRooms(final List goalRooms) { - return goalRooms.stream() - .allMatch(goalRoom -> goalRoom.isCompleted() && goalRoom.isCompletedAfterMonths(DELETE_AFTER_MONTH)); - } - - private void deleteGoalRooms(final List goalRooms) { - goalRoomRepository.deleteAll(goalRooms); - } - - private void deleteRoadmap(final Roadmap roadmap) { - roadmapRepository.delete(roadmap); - } -} diff --git a/backend/kirikiri/src/main/resources/properties b/backend/kirikiri/src/main/resources/properties index 2fdc5b50c..c5f41e5e1 160000 --- a/backend/kirikiri/src/main/resources/properties +++ b/backend/kirikiri/src/main/resources/properties @@ -1 +1 @@ -Subproject commit 2fdc5b50cd9c5095f16c7b28ad1275c60289f930 +Subproject commit c5f41e5e110dcb998446e18a52b31f6f4cc33d6f diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java index f40865139..d6d76ae48 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java @@ -6,24 +6,21 @@ import static org.mockito.Mockito.doThrow; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import co.kirikiri.auth.service.AuthService; import co.kirikiri.auth.service.NaverOauthService; -import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.common.exception.AuthenticationException; import co.kirikiri.controller.helper.ControllerTestHelper; import co.kirikiri.controller.helper.FieldDescriptionHelper.FieldDescription; import co.kirikiri.service.dto.ErrorResponse; import com.fasterxml.jackson.core.type.TypeReference; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -31,6 +28,7 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultMatcher; +import java.util.List; @WebMvcTest(AuthController.class) class AuthCreateApiTest extends ControllerTestHelper { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java index 866bc22a8..dd9190e8f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java @@ -11,7 +11,6 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,6 +19,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class RefreshTokenRepositoryTest { @@ -36,14 +36,6 @@ class RefreshTokenRepositoryTest { private RefreshTokenRepository refreshTokenRepository; - @BeforeEach - void init() { - when(redisTemplate.opsForValue()) - .thenReturn(valueOperations); - refreshTokenRepository = new RefreshTokenRepositoryImpl(redisTemplate, refreshTokenValidityInSeconds); - } - - @BeforeAll static void setUp() { final Identifier identifier = new Identifier("identifier1"); @@ -55,6 +47,13 @@ static void setUp() { member = new Member(identifier, encryptedPassword, nickname, null, memberProfile); } + @BeforeEach + void init() { + when(redisTemplate.opsForValue()) + .thenReturn(valueOperations); + refreshTokenRepository = new RefreshTokenRepositoryImpl(redisTemplate, refreshTokenValidityInSeconds); + } + @Test void 정상적으로_리프레시_토큰을_저장한다() { //given diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java index 5e625e778..633942adc 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java @@ -10,7 +10,6 @@ import co.kirikiri.common.exception.ServerException; import co.kirikiri.common.interceptor.Authenticated; import co.kirikiri.common.resolver.MemberIdentifier; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -22,6 +21,7 @@ import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.ModelAndViewContainer; +import java.util.List; @ExtendWith(MockitoExtension.class) class MemberIdentifierArgumentResolverImplTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java index d15e0c3e6..5fb6f8cae 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java @@ -18,13 +18,13 @@ import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; import co.kirikiri.member.persistence.MemberRepository; -import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class AuthServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java index 582609338..d64a2a8b0 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java @@ -8,10 +8,10 @@ import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Test; class JwtTokenProviderTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java index 3b0138ce3..34352b613 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java @@ -1,16 +1,12 @@ package co.kirikiri.auth.service; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; import co.kirikiri.auth.infra.NaverOauthNetworkService; import co.kirikiri.auth.service.dto.NaverOauthTokenDto; import co.kirikiri.auth.service.dto.response.AuthenticationResponse; -import java.util.Map; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -20,6 +16,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import java.util.Map; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class NaverOauthNetworkServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java index 32213e1b6..e1f021d8f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java @@ -8,8 +8,8 @@ import co.kirikiri.auth.service.dto.NaverMemberProfileDto; import co.kirikiri.auth.service.dto.NaverMemberProfileResponseDto; import co.kirikiri.auth.service.dto.NaverOauthTokenDto; -import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.member.domain.Gender; import co.kirikiri.member.domain.Member; import co.kirikiri.member.domain.MemberProfile; @@ -17,8 +17,6 @@ import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.member.service.MemberService; -import java.util.Map; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -27,6 +25,8 @@ import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; +import java.util.Map; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class NaverOauthServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java b/backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java index 33aa12c51..292e07f35 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java @@ -2,8 +2,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.lang.reflect.Method; import org.junit.jupiter.api.Test; +import java.lang.reflect.Method; class CacheKeyGeneratorTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomCreateApiTest.java index a859ec2cb..0c6c70681 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomCreateApiTest.java @@ -1,28 +1,15 @@ package co.kirikiri.controller; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; -import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders; +import static org.mockito.Mockito.*; +import static org.springframework.restdocs.headers.HeaderDocumentation.*; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.partWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.restdocs.request.RequestDocumentation.requestParts; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.request.RequestDocumentation.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.NotFoundException; @@ -36,9 +23,6 @@ import co.kirikiri.service.goalroom.GoalRoomCreateService; import co.kirikiri.service.goalroom.GoalRoomReadService; import com.fasterxml.jackson.core.type.TypeReference; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -49,6 +33,9 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultMatcher; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; @WebMvcTest(GoalRoomController.class) class GoalRoomCreateApiTest extends ControllerTestHelper { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomReadApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomReadApiTest.java index ce647440a..62f877ab6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomReadApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/controller/GoalRoomReadApiTest.java @@ -12,9 +12,7 @@ import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; +import static org.springframework.restdocs.request.RequestDocumentation.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -41,13 +39,13 @@ import co.kirikiri.service.goalroom.GoalRoomCreateService; import co.kirikiri.service.goalroom.GoalRoomReadService; import com.fasterxml.jackson.core.type.TypeReference; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MvcResult; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; @WebMvcTest(GoalRoomController.class) class GoalRoomReadApiTest extends ControllerTestHelper { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/helper/ControllerTestHelper.java b/backend/kirikiri/src/test/java/co/kirikiri/controller/helper/ControllerTestHelper.java index 1cea38e17..2a4d1e746 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/helper/ControllerTestHelper.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/controller/helper/ControllerTestHelper.java @@ -5,10 +5,10 @@ import co.kirikiri.common.interceptor.AuthInterceptor; import co.kirikiri.common.resolver.MemberIdentifierArgumentResolver; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.restdocs.payload.FieldDescriptor; +import java.util.List; public class ControllerTestHelper extends RestDocsHelper { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMemberTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMemberTest.java index cf482aada..70d3dd296 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMemberTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMemberTest.java @@ -11,7 +11,7 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapContent; import org.junit.jupiter.api.Test; import java.time.LocalDateTime; @@ -24,7 +24,7 @@ class GoalRoomPendingMemberTest { new Nickname("nickname"), null, new MemberProfile(Gender.FEMALE, "kirikiri1@email.com")); final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("goalroom"), new LimitedMemberCount(10), - new RoadmapContent("content"), member); + new RoadmapContent("content", null, null), member); // when final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(GoalRoomRole.LEADER, goalRoom, @@ -41,7 +41,7 @@ class GoalRoomPendingMemberTest { new Nickname("nickname"), null, new MemberProfile(Gender.FEMALE, "kirikiri1@email.com")); final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("goalroom"), new LimitedMemberCount(10), - new RoadmapContent("content"), member); + new RoadmapContent("content", 1L, null), member); // when final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, goalRoom, diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembersTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembersTest.java index 838578967..b232582d6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembersTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomPendingMembersTest.java @@ -11,10 +11,10 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapContent; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.util.List; -import org.junit.jupiter.api.Test; class GoalRoomPendingMembersTest { @@ -29,7 +29,7 @@ null, new EncryptedPassword(new Password("password2!")), void 골룸의_리더를_찾는다() { // given final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("goalroom"), new LimitedMemberCount(10), - new RoadmapContent("content"), MEMBER1); + new RoadmapContent("content", 1L, null), MEMBER1); // when final GoalRoomPendingMembers goalRoomPendingMembers = new GoalRoomPendingMembers(List.of( @@ -45,7 +45,7 @@ null, new EncryptedPassword(new Password("password2!")), void 골룸의_리더가_없으면_예외가_발생한다() { // given final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("goalroom"), new LimitedMemberCount(10), - new RoadmapContent("content"), MEMBER1); + new RoadmapContent("content", 1L, null), MEMBER1); // when final GoalRoomPendingMembers goalRoomPendingMembers = new GoalRoomPendingMembers(List.of( diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodeTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodeTest.java index 51a8d6208..5dda912e9 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodeTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodeTest.java @@ -6,10 +6,10 @@ import co.kirikiri.domain.goalroom.exception.GoalRoomException; import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.RoadmapNode; -import java.time.LocalDate; +import co.kirikiri.roadmap.domain.RoadmapNode; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import java.time.LocalDate; class GoalRoomRoadmapNodeTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodesTest.java index 3743814ba..cd91bfdad 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodesTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomRoadmapNodesTest.java @@ -7,14 +7,14 @@ import co.kirikiri.domain.goalroom.exception.GoalRoomException; import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNode; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; class GoalRoomRoadmapNodesTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomTest.java index f11343bd4..20d62b87e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomTest.java @@ -15,19 +15,15 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.util.Collections; import java.util.List; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; class GoalRoomTest { @@ -53,11 +49,8 @@ static void setUp() { void 골룸의_총_기간을_계산한다() { // given final Member creator = 크리에이터를_생성한다(); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final RoadmapContent roadmapContent = 로드맵_콘텐츠를_생성한다(); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); // when final int totalPeriod = goalRoom.calculateTotalPeriod(); @@ -71,7 +64,7 @@ static void setUp() { void 골룸에_대기중인_인원수를_계산한다() { // given final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("goalroom"), new LimitedMemberCount(10), - new RoadmapContent("content"), member); + new RoadmapContent("content", 1L, null), member); final Member member1 = new Member(2L, new Identifier("identifier2"), null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임2"), null, @@ -93,7 +86,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸에_사용자를_추가한다() { //given final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(10), - new RoadmapContent("로드맵 내용"), member); + new RoadmapContent("로드맵 내용", 1L, null), member); final Member follower = 사용자를_생성한다(2L, "identifier12", "시진이"); //when @@ -108,7 +101,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 @Test void 모집중이_아닌_골룸에_사용자를_추가하면_예외가_발생한다() { //given - final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(10), new RoadmapContent("로드맵 내용"), + final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(10), new RoadmapContent("로드맵 내용", 1L, null), 사용자를_생성한다(2L, "identifier1", "시진이")); goalRoom.start(); @@ -121,7 +114,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 @Test void 제한_인원이_가득_찬_골룸에_사용자를_추가하면_예외가_발생한다() { //given - final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(1), new RoadmapContent("로드맵 내용"), + final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(1), new RoadmapContent("로드맵 내용", 1L, null), 사용자를_생성한다(2L, "identifier1", "시진이")); //when,then @@ -134,7 +127,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 이미_참여_중인_사용자를_골룸에_추가하면_예외가_발생한다() { //given final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(2), - new RoadmapContent("로드맵 내용"), member); + new RoadmapContent("로드맵 내용", 1L, null), member); //when,then assertThatThrownBy(() -> goalRoom.join(member)) @@ -146,11 +139,8 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸의_총_인증_횟수를_구한다() { //given final Member creator = 크리에이터를_생성한다(); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final RoadmapContent roadmapContent = 로드맵_콘텐츠를_생성한다(); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); //expect assertThat(goalRoom.getAllCheckCount()).isEqualTo(20); @@ -160,11 +150,8 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸이_시작하기_전에_참여_멤버를_확인한다() { //given final Member creator = 크리에이터를_생성한다(); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final RoadmapContent roadmapContent = 로드맵_콘텐츠를_생성한다(); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); final Member 참여자 = 사용자를_생성한다(2L, "identifier1", "팔로워"); goalRoom.join(참여자); @@ -180,11 +167,8 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸이_시작한_후에_참여_멤버를_확인한다() { //given final Member creator = 크리에이터를_생성한다(); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final RoadmapContent roadmapContent = 로드맵_콘텐츠를_생성한다(); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); final Member 참여자 = 사용자를_생성한다(2L, "identifier1", "팔로워"); // goalRoom.join(참여자); @@ -201,7 +185,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸을_나간다() { //given final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(2), - new RoadmapContent("로드맵 내용"), member); + new RoadmapContent("로드맵 내용", 1L, null), member); // when goalRoom.leave(member); @@ -214,7 +198,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸에_참여하지_않은_멤버가_나가면_예외가_발생한다() { //given final GoalRoom goalRoom = new GoalRoom(GOAL_ROOM_NAME, new LimitedMemberCount(2), - new RoadmapContent("로드맵 내용"), member); + new RoadmapContent("로드맵 내용", 1L, null), member); final Member notJoinMember = new Member(new Identifier("identifier2"), new EncryptedPassword(new Password("password2!")), @@ -230,11 +214,8 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 void 골룸이_종료된지_3개월_이상_지나지_않으면_false를_반환한다() { //given final Member creator = 크리에이터를_생성한다(); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final RoadmapContent roadmapContent = 로드맵_콘텐츠를_생성한다(); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); // when final boolean result = goalRoom.isCompletedAfterMonths(3); @@ -255,13 +236,9 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 new Nickname(nickname), null, memberProfile); } - private Roadmap 로드맵을_생성한다(final Member creator) { - final RoadmapCategory category = new RoadmapCategory("게임"); + private RoadmapContent 로드맵_콘텐츠를_생성한다() { final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmap; + return 로드맵_본문을_생성한다(roadmapNodes); } private List 로드맵_노드들을_생성한다() { @@ -272,8 +249,7 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("닉네임3 } private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, new RoadmapNodes(roadmapNodes)); return roadmapContent; } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomToDoTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomToDoTest.java index 16b3a5dce..0e2a2fcb7 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomToDoTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/domain/goalroom/GoalRoomToDoTest.java @@ -6,9 +6,9 @@ import co.kirikiri.domain.goalroom.exception.GoalRoomException; import co.kirikiri.domain.goalroom.vo.GoalRoomTodoContent; import co.kirikiri.domain.goalroom.vo.Period; -import java.time.LocalDate; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import java.time.LocalDate; class GoalRoomToDoTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java deleted file mode 100644 index 1fcf31d41..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static co.kirikiri.domain.roadmap.RoadmapDifficulty.DIFFICULT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -import co.kirikiri.member.domain.EncryptedPassword; -import co.kirikiri.member.domain.Gender; -import co.kirikiri.member.domain.Member; -import co.kirikiri.member.domain.MemberProfile; -import co.kirikiri.member.domain.vo.Identifier; -import co.kirikiri.member.domain.vo.Nickname; -import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import java.util.List; -import org.junit.jupiter.api.Test; - -class RoadmapContentTest { - - @Test - void 로드맵_본문의_길이가_2000보다_크면_예외가_발생한다() { - // given - final String content = "a".repeat(2001); - - // expect - assertThatThrownBy(() -> new RoadmapContent(content)) - .isInstanceOf(RoadmapException.class); - } - - @Test - void 로드맵_본문은_null값을_허용한다() { - // given - final String content = null; - - // expect - assertDoesNotThrow(() -> new RoadmapContent(content)); - } - - @Test - void 로드맵_본문에_노드들을_추가한다() { - // given - final RoadmapContent content = new RoadmapContent("content"); - - // when - content.addNodes( - new RoadmapNodes( - List.of(new RoadmapNode("title1", "content1"), new RoadmapNode("title2", "content1")))); - - // then - final RoadmapNodes nodes = content.getNodes(); - assertAll( - () -> assertThat(nodes.getValues()).hasSize(2), - () -> assertThat(nodes.getValues().get(0).getRoadmapContent()).isEqualTo(content), - () -> assertThat(nodes.getValues().get(1).getRoadmapContent()).isEqualTo(content) - ); - } - - @Test - void 로드맵_본문에_노드를_추가할때_이름이_겹치면_예외를_던진다() { - // given - final RoadmapContent content = new RoadmapContent("content"); - - // when - // then - final String title = "title"; - assertThatThrownBy(() -> content.addNodes( - new RoadmapNodes( - List.of(new RoadmapNode(title, "content1"), new RoadmapNode(title, "content1"))))); - } - - @Test - void 로드맵_본문의_로드맵인_경우_false를_반환한다() { - // given - final RoadmapContent content = new RoadmapContent("content"); - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member creator = new Member(new Identifier("creator"), - new EncryptedPassword(new Password("password1")), new Nickname("nickname"), null, profile); - final RoadmapCategory category = new RoadmapCategory(1L, "여가"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, creator, category); - - // when - roadmap.addContent(content); - - // then - assertThat(content.isNotSameRoadmap(roadmap)).isFalse(); - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java deleted file mode 100644 index a9e9113f9..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; -import java.util.List; - -class RoadmapContentsTest { - - @Test - void 로드맵_본문을_추가한다() { - // given - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목", "로드맵 노드 내용"))); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); - final RoadmapContents roadmapContents = new RoadmapContents(List.of(roadmapContent)); - final RoadmapContent updatedRoadmapContent = new RoadmapContent("로드맵 본문 수정본"); - updatedRoadmapContent.addNodes(roadmapNodes); - - // when - roadmapContents.add(updatedRoadmapContent); - - // then - assertThat(roadmapContents.getValues()).usingRecursiveComparison() - .isEqualTo(List.of(roadmapContent, updatedRoadmapContent)); - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java deleted file mode 100644 index e8c06eecc..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; - -import org.junit.jupiter.api.Test; -import java.util.List; - -class RoadmapNodesTest { - - @Test - void 로드맵_노드를_추가한다() { - // given - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목1", "로드맵 노드 내용"))); - - // when - roadmapNodes.add(new RoadmapNode("로드맵 노드 제목2", "로드맵 노드 내용")); - - // then - assertThat(roadmapNodes.getValues()).hasSize(2); - } - - @Test - void 로드맵_노드들의_로드맵_본문을_업데이트한다() { - // given - final RoadmapNodes roadmapNodes = new RoadmapNodes( - List.of(new RoadmapNode("로드맵 노드 제목1", "로드맵 노드 내용1"), new RoadmapNode("로드맵 노드 제목2", "로드맵 노드 내용2"))); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - - // when - roadmapNodes.updateAllRoadmapContent(roadmapContent); - - // then - final List nodes = roadmapNodes.getValues(); - assertAll( - () -> assertThat(nodes.get(0).getRoadmapContent()).isEqualTo(roadmapContent), - () -> assertThat(nodes.get(1).getRoadmapContent()).isEqualTo(roadmapContent) - ); - } - -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java deleted file mode 100644 index 756cb856e..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static co.kirikiri.domain.roadmap.RoadmapDifficulty.DIFFICULT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -import co.kirikiri.member.domain.EncryptedPassword; -import co.kirikiri.member.domain.Gender; -import co.kirikiri.member.domain.Member; -import co.kirikiri.member.domain.MemberProfile; -import co.kirikiri.member.domain.vo.Identifier; -import co.kirikiri.member.domain.vo.Nickname; -import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -class RoadmapTest { - - private final Member creator = 크리에이터를_생성한다(); - private final RoadmapCategory category = 카테고리를_생성한다(); - private final List roadmapNodes = 로드맵_노드들을_생성한다(); - private final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - - @Test - void 로드맵이_성공적으로_생성된다() { - // expect - assertDoesNotThrow(() -> new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, - creator, category)); - } - - @Test - void 로드맵에_본문을_추가한다() { - // given - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, creator, category); - - // when - roadmap.addContent(roadmapContent); - - // then - final RoadmapContents contents = roadmap.getContents(); - assertThat(contents.getValues()).hasSize(1); - } - - @ParameterizedTest - @ValueSource(ints = {0, 41}) - void 로드맵_제목의_길이가_1보다_작거나_40보다_크면_예외가_발생한다(final int titleLength) { - // given - final String title = "a".repeat(titleLength); - - // expect - assertThatThrownBy(() -> new Roadmap(title, "로드맵 소개글", 30, DIFFICULT, creator, category)) - .isInstanceOf(RoadmapException.class); - } - - @ParameterizedTest - @ValueSource(ints = {0, 151}) - void 로드맵_소개글의_길이가_1보다_작거나_150보다_크면_예외가_발생한다(final int introductionLength) { - // given - final String introduction = "a".repeat(introductionLength); - - // expect - assertThatThrownBy(() -> new Roadmap("로드맵 제목", introduction, 30, DIFFICULT, creator, category)) - .isInstanceOf(RoadmapException.class); - } - - @ParameterizedTest - @ValueSource(ints = {-1, 1001}) - void 로드맵_추천_소요_기간이_0보다_작고_1000보다_크면_예외가_발생한다(final int requiredPeriod) { - // expect - assertThatThrownBy(() -> new Roadmap("로드맵 제목", "로드맵 소개글", requiredPeriod, DIFFICULT, creator, category)) - .isInstanceOf(RoadmapException.class); - } - - private Member 크리에이터를_생성한다() { - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - - return new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); - } - - private RoadmapCategory 카테고리를_생성한다() { - return new RoadmapCategory(1L, "여가"); - } - - private List 로드맵_노드들을_생성한다() { - return List.of(new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"), - new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용")); - } - - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java index 9e3c12788..d0ee3c329 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java @@ -15,9 +15,6 @@ import com.amazonaws.Protocol; import com.amazonaws.SdkClientException; import com.amazonaws.services.s3.AmazonS3; -import java.io.FileInputStream; -import java.net.MalformedURLException; -import java.net.URL; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -25,6 +22,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.env.Environment; import org.springframework.http.HttpMethod; +import java.io.FileInputStream; +import java.net.MalformedURLException; +import java.net.URL; @ExtendWith(MockitoExtension.class) class AmazonS3FileServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java index 517944096..6514f6bf6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java @@ -6,14 +6,14 @@ import co.kirikiri.common.exception.ServerException; import co.kirikiri.common.infra.CloudFrontService; -import java.net.MalformedURLException; -import java.net.URL; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.env.Environment; +import java.net.MalformedURLException; +import java.net.URL; @ExtendWith(MockitoExtension.class) class CloudFrontServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java index 7d192e4e6..44b57c71f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java @@ -15,9 +15,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; +import java.util.List; class AuthenticationIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java index 875cffbc9..aec2d0ebc 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java @@ -2,29 +2,8 @@ import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_나가기_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_목록_조회_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_생성; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_참가_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_투두리스트_추가; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_투두리스트_추가후_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_투두리스트를_체크한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_생성하고_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_시작한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸의_사용자_정보를_정렬_기준없이_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.사용자의_특정_골룸_정보를_조회한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.이십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.인증_피드_등록; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_생성; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_투두_컨텐츠; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; -import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; +import static co.kirikiri.integration.fixture.MemberAPIFixture.*; import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; import static org.assertj.core.api.Assertions.assertThat; @@ -35,6 +14,8 @@ import co.kirikiri.member.service.dto.request.GenderType; import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.ErrorResponse; import co.kirikiri.service.dto.goalroom.GoalRoomFilterTypeDto; import co.kirikiri.service.dto.goalroom.request.CheckFeedRequest; @@ -44,20 +25,18 @@ import co.kirikiri.service.dto.goalroom.response.GoalRoomMemberResponse; import co.kirikiri.service.dto.goalroom.response.GoalRoomToDoCheckResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import com.fasterxml.jackson.core.JsonProcessingException; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.io.IOException; -import java.time.temporal.ChronoUnit; -import java.util.Collections; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockMultipartFile; +import java.io.IOException; +import java.time.temporal.ChronoUnit; +import java.util.Collections; +import java.util.List; class GoalRoomCreateIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java index 2ab6e6bd6..0ab954bb0 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java @@ -2,30 +2,7 @@ import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_노드_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_아이디로_골룸을_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_아이디와_토큰으로_골룸_정보를_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_참가_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_투두리스트_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_투두리스트_추가; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_생성하고_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_시작한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸의_사용자_정보를_전체_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸의_사용자_정보를_정렬_기준없이_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.기본_골룸_생성; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.로드맵_아이디로_골룸_목록_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.사용자가_참여한_골룸_중_골룸_진행_상태에_따라_목록을_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.사용자의_모든_골룸_조회; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.사용자의_특정_골룸_정보를_조회한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.삼십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.이십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.인증_피드_등록; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.인증_피드_전체_조회_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; @@ -37,6 +14,11 @@ import co.kirikiri.member.service.dto.request.GenderType; import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.ErrorResponse; import co.kirikiri.service.dto.goalroom.GoalRoomMemberSortTypeDto; import co.kirikiri.service.dto.goalroom.request.CheckFeedRequest; @@ -54,21 +36,16 @@ import co.kirikiri.service.dto.goalroom.response.GoalRoomTodoResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomForListResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.io.IOException; -import java.time.LocalDate; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockMultipartFile; +import java.io.IOException; +import java.time.LocalDate; +import java.util.List; class GoalRoomReadIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java index dbd66d24b..7c8b9d99d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java @@ -3,17 +3,7 @@ import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; import static co.kirikiri.integration.fixture.CommonFixture.LOCATION; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_생성; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_참가_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_시작한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.기본_골룸_생성; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.사용자의_특정_골룸_정보를_조회한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.이십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; @@ -29,14 +19,14 @@ import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomPendingMemberRepository; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import co.kirikiri.service.scheduler.GoalRoomScheduler; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.List; -import org.junit.jupiter.api.Test; class GoalRoomSchedulerIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java index 9a790a59c..c97688a92 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java @@ -1,12 +1,6 @@ package co.kirikiri.integration; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_GENDER_TYPE; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_IDENTIFIER; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_NICKNAME; -import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_특정_사용자의_정보_조회; -import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; +import static co.kirikiri.integration.fixture.MemberAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.integration.helper.InitIntegrationTest; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java index 28de9fe3d..ae22e8dd4 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java @@ -1,37 +1,32 @@ package co.kirikiri.integration; import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; -import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; -import static co.kirikiri.integration.fixture.CommonFixture.아이디를_반환한다; -import static co.kirikiri.integration.fixture.CommonFixture.응답_상태_코드_검증; +import static co.kirikiri.integration.fixture.CommonFixture.*; import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_삭제; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_카테고리를_생성한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.요청을_받는_이미지가_포함된_로드맵_생성; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.integration.helper.InitIntegrationTest; import co.kirikiri.member.service.dto.request.GenderType; import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import co.kirikiri.service.dto.ErrorResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.io.IOException; -import java.util.Collections; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.http.HttpStatus; +import java.io.IOException; +import java.util.Collections; +import java.util.List; class RoadmapCreateIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java index e51683df5..1ae51d154 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java @@ -1,31 +1,22 @@ package co.kirikiri.integration; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로그인한_사용자가_생성한_로드맵을_이전에_받은_로드맵의_제일마지막_아이디_이후의_조건으로_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로그인한_사용자가_생성한_로드맵을_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.모든_카테고리를_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.사이즈_없이_로드맵을_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.사이즈별로_로드맵을_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.정렬된_카테고리별_로드맵_리스트_조회; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.카테고리_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.카테고리들_생성; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import co.kirikiri.domain.roadmap.RoadmapCategory; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.ErrorResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java index 8630b44c1..8511d4a18 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java @@ -1,41 +1,29 @@ package co.kirikiri.integration; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸_참가_요청; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_생성하고_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_시작한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; import static co.kirikiri.integration.fixture.MemberAPIFixture.사용자를_추가하고_토큰을_조회한다; import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.리뷰를_생성한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.정렬된_로드맵_리스트_조회; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.정렬된_카테고리별_로드맵_리스트_조회; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.카테고리_생성; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.roadmap.RoadmapCategory; import co.kirikiri.integration.helper.InitIntegrationTest; import co.kirikiri.member.service.dto.response.MemberInformationResponse; -import co.kirikiri.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.List; -import org.junit.jupiter.api.Test; class RoadmapReadOrderIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java index 96f22dfaf..91eeefa44 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java @@ -2,18 +2,9 @@ import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_생성하고_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; -import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.리뷰를_생성한다; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; +import static co.kirikiri.integration.fixture.MemberAPIFixture.*; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.auth.service.dto.request.LoginRequest; @@ -22,18 +13,18 @@ import co.kirikiri.member.service.dto.request.GenderType; import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.ErrorResponse; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; -import java.io.IOException; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; +import java.io.IOException; +import java.util.List; class RoadmapReviewCreateIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java index 159720a70..d7c8643ff 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java @@ -2,13 +2,8 @@ import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; -import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; -import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.MemberAPIFixture.회원가입; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_리뷰를_조회한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.리뷰를_생성한다; +import static co.kirikiri.integration.fixture.MemberAPIFixture.*; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -19,21 +14,21 @@ import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.member.service.dto.response.MemberInformationResponse; import co.kirikiri.member.service.dto.response.MemberResponse; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; import co.kirikiri.service.dto.CustomScrollRequest; import co.kirikiri.service.dto.ErrorResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; import java.io.IOException; import java.time.LocalDateTime; import java.util.List; -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; class RoadmapReviewReadIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java index a5a3e83f4..c0e8eb0f2 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java @@ -1,23 +1,16 @@ package co.kirikiri.integration; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_생성하고_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_삭제; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.domain.goalroom.GoalRoomStatus; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.service.scheduler.RoadmapScheduler; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.scheduler.RoadmapScheduler; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import org.junit.jupiter.api.Test; import java.io.IOException; import java.time.LocalDate; @@ -65,7 +58,7 @@ public RoadmapSchedulerIntegrationTest(final RoadmapScheduler roadmapScheduler, roadmapScheduler.deleteRoadmaps(); // then - assertThat(roadmapRepository.findAll()).hasSize(0); + assertThat(roadmapRepository.findAll()).isEmpty(); } @Test diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java index 10382cf1f..aec2b8e55 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java @@ -1,23 +1,20 @@ package co.kirikiri.integration; import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.제목으로_최신순_정렬된_로드맵을_검색한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.크리에이터_닉네임으로_정렬된_로드맵을_생성한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.태그_이름으로_최신순_정렬된_로드맵을_검색한다; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.integration.helper.InitIntegrationTest; import co.kirikiri.member.service.dto.response.MemberInformationResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; import io.restassured.common.mapper.TypeRef; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.List; -import org.junit.jupiter.api.Test; class RoadmapSearchIntegrationTest extends InitIntegrationTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java index 598efe8ad..c59f78b8d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java @@ -1,28 +1,26 @@ package co.kirikiri.integration.fixture; -import static co.kirikiri.integration.fixture.CommonFixture.API_PREFIX; -import static co.kirikiri.integration.fixture.CommonFixture.AUTHORIZATION; -import static co.kirikiri.integration.fixture.CommonFixture.LOCATION; +import static co.kirikiri.integration.fixture.CommonFixture.*; import static io.restassured.RestAssured.given; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.goalroom.request.CheckFeedRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomTodoRequest; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import io.restassured.http.Header; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.List; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; public class GoalRoomAPIFixture { @@ -30,10 +28,10 @@ public class GoalRoomAPIFixture { public static final LocalDate 십일_후 = 오늘.plusDays(10L); public static final LocalDate 이십일_후 = 십일_후.plusDays(10L); public static final LocalDate 삼십일_후 = 이십일_후.plusDays(10L); + public static final int 정상적인_골룸_노드_인증_횟수 = (int) ChronoUnit.DAYS.between(오늘, 십일_후); public static final String 정상적인_골룸_이름 = "GOAL_ROOM_NAME"; public static final int 정상적인_골룸_제한_인원 = 20; public static final String 정상적인_골룸_투두_컨텐츠 = "GOAL_ROOM_TO_DO_CONTENT"; - public static final int 정상적인_골룸_노드_인증_횟수 = (int) ChronoUnit.DAYS.between(오늘, 십일_후); public static Long 골룸을_생성하고_아이디를_반환한다(final GoalRoomCreateRequest 골룸_생성_요청, final String 액세스_토큰) { final String 골룸_생성_응답_Location_헤더 = 골룸_생성(골룸_생성_요청, 액세스_토큰).response().getHeader(LOCATION); diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java index c6097e8df..e8800017d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java @@ -1,9 +1,7 @@ package co.kirikiri.integration.fixture; import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; -import static co.kirikiri.integration.fixture.CommonFixture.API_PREFIX; -import static co.kirikiri.integration.fixture.CommonFixture.AUTHORIZATION; -import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; +import static co.kirikiri.integration.fixture.CommonFixture.*; import static io.restassured.RestAssured.given; import co.kirikiri.auth.service.dto.request.LoginRequest; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java index 0acc14aae..d8966e793 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java @@ -4,14 +4,14 @@ import static co.kirikiri.integration.fixture.CommonFixture.AUTHORIZATION; import static io.restassured.RestAssured.given; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.restassured.response.ExtractableResponse; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java index 28b448b74..243e577e3 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java @@ -5,11 +5,11 @@ import static co.kirikiri.integration.fixture.MemberAPIFixture.기본_회원가입; import static co.kirikiri.integration.fixture.RoadmapAPIFixture.카테고리_생성; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import org.junit.jupiter.api.BeforeEach; import java.util.List; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java index 4ce173e30..85cfdef3f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java @@ -20,15 +20,12 @@ @Import(TestConfig.class) public class IntegrationTest { - @LocalServerPort - private int port; - @Autowired protected ObjectMapper objectMapper; - @Autowired protected TestTransactionService testTransactionService; - + @LocalServerPort + private int port; @Autowired private DatabaseCleaner databaseCleaner; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestFileService.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestFileService.java index 54b3a2557..264538fee 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestFileService.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestFileService.java @@ -2,9 +2,9 @@ import co.kirikiri.common.service.FileService; import co.kirikiri.service.dto.FileInformation; +import org.springframework.http.HttpMethod; import java.net.MalformedURLException; import java.net.URL; -import org.springframework.http.HttpMethod; public class TestFileService implements FileService { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java index c2b14cdab..f63bc8d47 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java @@ -1,11 +1,6 @@ package co.kirikiri.integration.helper; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.골룸을_생성하고_아이디를_반환한다; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.십일_후; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.오늘; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_노드_인증_횟수; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_이름; -import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.정상적인_골룸_제한_인원; +import static co.kirikiri.integration.fixture.GoalRoomAPIFixture.*; import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_PASSWORD; import static co.kirikiri.integration.helper.InitIntegrationTest.기본_로그인_토큰; @@ -23,25 +18,24 @@ import co.kirikiri.member.service.dto.response.MemberInformationResponse; import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import org.springframework.transaction.annotation.Transactional; @Transactional public class TestTransactionService { - @PersistenceContext - private EntityManager em; - private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; + @PersistenceContext + private EntityManager em; public TestTransactionService(final GoalRoomRepository goalRoomRepository, final GoalRoomMemberRepository goalRoomMemberRepository) { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java index 9e2bf952c..d854cbeb6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java @@ -6,8 +6,8 @@ import static org.mockito.Mockito.doThrow; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -20,7 +20,6 @@ import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.service.dto.ErrorResponse; import com.fasterxml.jackson.core.type.TypeReference; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -29,6 +28,7 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultMatcher; +import java.util.List; @WebMvcTest(MemberController.class) class MemberCreateApiTest extends ControllerTestHelper { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java index 43eb0fd6a..d0b59d02b 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java @@ -13,9 +13,9 @@ import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; import co.kirikiri.persistence.helper.RepositoryTest; -import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Optional; @RepositoryTest class MemberRepositoryTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java index 247b91d7a..aa0212588 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java @@ -25,9 +25,6 @@ import co.kirikiri.member.service.dto.request.MemberJoinRequest; import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; import co.kirikiri.member.service.dto.response.MemberInformationResponse; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -36,6 +33,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.env.Environment; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class MemberServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/CheckFeedRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/CheckFeedRepositoryTest.java index 2d31ec8ea..cf3a3c241 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/CheckFeedRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/CheckFeedRepositoryTest.java @@ -21,23 +21,25 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.persistence.helper.RepositoryTest; import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.persistence.helper.RepositoryTest; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Test; @RepositoryTest class CheckFeedRepositoryTest { @@ -53,6 +55,7 @@ class CheckFeedRepositoryTest { private final MemberRepository memberRepository; private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; private final CheckFeedRepository checkFeedRepository; @@ -60,12 +63,14 @@ class CheckFeedRepositoryTest { public CheckFeedRepositoryTest(final MemberRepository memberRepository, final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomMemberRepository goalRoomMemberRepository, final CheckFeedRepository checkFeedRepository) { this.memberRepository = memberRepository; this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; this.checkFeedRepository = checkFeedRepository; @@ -75,13 +80,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 사용자가_해당_골룸에서_오늘_올린_피드의_존재유무를_확인한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -109,13 +112,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 사용자가_현재_진행중인_노드에서_인증한_횟수를_확인한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -140,13 +141,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 사용자가_골룸에서_등록한_인증_피드_횟수를_확인한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -174,14 +173,12 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 특정_골룸에서_등록된_모든_인증_피드들을_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom1 = 골룸을_저장한다(targetRoadmapContent, creator); - final GoalRoom goalRoom2 = 골룸을_저장한다(targetRoadmapContent, creator); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom1 = 골룸을_저장한다(roadmapContent, creator); + final GoalRoom goalRoom2 = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom1, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom1, @@ -215,13 +212,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 골룸이_진행중일_때_특정_노드_동안_등록된_인증_피드들을_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -258,13 +253,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 진행중인_골룸에서_특정_노드_기간이_아니면_빈_인증_피드들_반환한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -292,13 +285,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 골룸이_완료됐을_때는_특정한_노드_동안이_아닌_모든_기간_동안_등록된_인증_피드들을_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -337,13 +328,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 골룸_진행_중에_특정_노드_동안_등록된_인증_피드들을_등록한_사용자의_정보와_함께_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -396,13 +385,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 골룸_완료_시_모든_기간_동안_등록된_인증_피드들을_등록한_사용자의_정보와_함께_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember joinedMember = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -442,19 +429,22 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, return memberRepository.save(creator); } - private RoadmapCategory 카테고리를_저장한다(final String name) { + private RoadmapCategory 카테고리를_생성한다(final String name) { final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } + private RoadmapContent 로드맵_본문을_저장한다(final Long roadmapId) { + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); + } + private List 로드맵_노드들을_생성한다() { final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); @@ -462,12 +452,6 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepositoryTest.java index c8a4fe403..4ef2ecc37 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomMemberRepositoryTest.java @@ -19,26 +19,28 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; +import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType; import co.kirikiri.persistence.helper.RepositoryTest; -import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; @RepositoryTest class GoalRoomMemberRepositoryTest { @@ -49,20 +51,23 @@ class GoalRoomMemberRepositoryTest { private static final LocalDate THIRTY_DAY_LATER = TODAY.plusDays(30); private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, - final RoadmapCategoryRepository roadmapCategoryRepository, final GoalRoomMemberRepository goalRoomMemberRepository) { this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; } @@ -70,22 +75,18 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸과_사용자_아이디로_골룸_사용자_목록을_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, creator); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, creator); final GoalRoomMember expected = goalRoomMemberRepository.save(goalRoomMember); // when final Optional findGoalRoomMember = goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier( - savedGoalRoom, new Identifier("cokirikiri")); + goalRoom, new Identifier("cokirikiri")); // then assertThat(findGoalRoomMember.get()) @@ -98,18 +99,14 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸과_사용자_아이디로_골룸_사용자_목록_조회시_없으면_빈값을_반환한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); // when final Optional findGoalRoomMember = goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier( - savedGoalRoom, new Identifier("cokirikiri2")); + goalRoom, new Identifier("cokirikiri2")); // then assertThat(findGoalRoomMember) @@ -120,25 +117,21 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸으로_사용자_목록과_멤버를_함께_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember1, goalRoomMember2, goalRoomMember3)); @@ -155,31 +148,27 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸_사용자를_조회하고_들어온지_오래된_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember1, goalRoomMember2, goalRoomMember3)); // when final List goalRoomMembers = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); // then assertThat(goalRoomMembers) @@ -190,32 +179,28 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸_사용자를_조회하고_마지막으로_들어온_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3); final GoalRoomMember savedGoalRoomMember1 = goalRoomMemberRepository.save(goalRoomMember1); final GoalRoomMember savedGoalRoomMember2 = goalRoomMemberRepository.save(goalRoomMember2); final GoalRoomMember savedGoalRoomMember3 = goalRoomMemberRepository.save(goalRoomMember3); // when final List goalRoomMembers = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); // then assertThat(goalRoomMembers) @@ -226,36 +211,32 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸_사용자를_조회하고_달성률이_높은_순대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1); goalRoomMember1.updateAccomplishmentRate(30.0); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2); goalRoomMember2.updateAccomplishmentRate(70.0); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3); goalRoomMember3.updateAccomplishmentRate(10.0); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember2, goalRoomMember1, goalRoomMember3)); // when final List goalRoomMembers1 = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); + goalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); final List goalRoomMembers2 = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), null); + goalRoom.getId(), null); // then assertThat(goalRoomMembers1) @@ -267,15 +248,11 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, @Test void 골룸_아이디와_사용자_아이디로_골룸_멤버를_조회한다() { // given - final Member creator = 사용자를_생성한다("identifier1", "password!1", "name1", "kirikiri1@email.com"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - goalRoomRepository.save(goalRoom); + final Member creator = 크리에이터를_저장한다(); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember goalRoomMember = new GoalRoomMember( GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator @@ -310,11 +287,22 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, return memberRepository.save(member); } - private RoadmapCategory 카테고리를_저장한다(final String name) { + private RoadmapCategory 카테고리를_생성한다(final String name) { final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } + private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); + return roadmapRepository.save(roadmap); + } + + private RoadmapContent 로드맵_본문을_저장한다(final Long roadmapId) { + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); + } + private List 로드맵_노드들을_생성한다() { final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); @@ -322,12 +310,6 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), @@ -335,15 +317,7 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, ); } - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); - } - - private GoalRoom 골룸을_생성한다(final RoadmapContent roadmapContent, final Member member) { + private GoalRoom 골룸을_저장한다(final RoadmapContent roadmapContent, final Member member) { final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent, member); final List roadmapNodes = roadmapContent.getNodes().getValues(); @@ -360,6 +334,6 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes( List.of(firstGoalRoomRoadmapNode, secondGoalRoomRoadmapNode)); goalRoom.addAllGoalRoomRoadmapNodes(goalRoomRoadmapNodes); - return goalRoom; + return goalRoomRepository.save(goalRoom); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepositoryTest.java index 3916f10c9..63d98d128 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomPendingMemberRepositoryTest.java @@ -19,24 +19,26 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; +import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.persistence.goalroom.dto.GoalRoomMemberSortType; import co.kirikiri.persistence.helper.RepositoryTest; -import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -49,19 +51,22 @@ class GoalRoomPendingMemberRepositoryTest { private static final LocalDate THIRTY_DAY_LATER = TODAY.plusDays(30); private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; private final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberRepository, final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository) { this.memberRepository = memberRepository; this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomPendingMemberRepository = goalRoomPendingMemberRepository; } @@ -70,21 +75,17 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸과_사용자_아이디로_골룸_사용자_대기_목록을_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomPendingMember expected = new GoalRoomPendingMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, creator); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, creator); // when final Optional findGoalRoomPendingMember = goalRoomPendingMemberRepository.findByGoalRoomAndMemberIdentifier( - savedGoalRoom, new Identifier("cokirikiri")); + goalRoom, new Identifier("cokirikiri")); // then assertThat(findGoalRoomPendingMember.get()) @@ -97,18 +98,14 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸과_사용자_아이디로_골룸_사용자_대기_목록_조회시_없으면_빈값을_반환한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); // when final Optional findGoalRoomPendingMember = goalRoomPendingMemberRepository.findByGoalRoomAndMemberIdentifier( - savedGoalRoom, new Identifier("cokirikiri2")); + goalRoom, new Identifier("cokirikiri2")); // then assertThat(findGoalRoomPendingMember) @@ -119,27 +116,23 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸으로_사용자_대기_목록과_멤버를_함께_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, creator); + LocalDateTime.now(), goalRoom, creator); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member1); + LocalDateTime.now(), goalRoom, member1); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2); + LocalDateTime.now(), goalRoom, member2); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3); + LocalDateTime.now(), goalRoom, member3); goalRoomPendingMemberRepository.saveAll( List.of(goalRoomPendingMember1, goalRoomPendingMember2, goalRoomPendingMember3)); @@ -161,17 +154,15 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸에_참가한다() { //given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member follower = 사용자를_생성한다("identifier2", "password!2", "name", "kirikiri1@email.com"); //when - savedGoalRoom.join(follower); + goalRoom.join(follower); //then final List goalRoomPendingMembers = goalRoomPendingMemberRepository.findByGoalRoom( @@ -191,14 +182,10 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸_아이디로_골룸_사용자를_조회하고_들어온지_오래된_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); @@ -206,11 +193,11 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito final GoalRoomPendingMember goalRoomPendingMember0 = goalRoom.getGoalRoomPendingMembers().getValues().get(0); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member1); + LocalDateTime.now(), goalRoom, member1); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2); + LocalDateTime.now(), goalRoom, member2); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3); + LocalDateTime.now(), goalRoom, member3); goalRoomPendingMemberRepository.saveAll( List.of(goalRoomPendingMember1, goalRoomPendingMember2, goalRoomPendingMember3)); final List expected = List.of(goalRoomPendingMember0, goalRoomPendingMember1, @@ -218,7 +205,7 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito // when final List goalRoomPendingMembers = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); // then assertThat(goalRoomPendingMembers) @@ -229,14 +216,10 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸_아이디로_골룸_사용자를_조회하고_마지막으로_들어온_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); @@ -244,11 +227,11 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito final GoalRoomPendingMember goalRoomPendingMember0 = goalRoom.getGoalRoomPendingMembers().getValues().get(0); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, member1); + LocalDateTime.now(), goalRoom, member1); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2); + LocalDateTime.now(), goalRoom, member2); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3); + LocalDateTime.now(), goalRoom, member3); final GoalRoomPendingMember savedGoalRoomPendingMember1 = goalRoomPendingMemberRepository.save( goalRoomPendingMember1); final GoalRoomPendingMember savedGoalRoomPendingMember2 = goalRoomPendingMemberRepository.save( @@ -260,7 +243,7 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito // when final List goalRoomPendingMembers = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); // then assertThat(goalRoomPendingMembers) @@ -271,14 +254,10 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸_아이디로_골룸_사용자를_조회하고_정렬조건을_달성률순_또는_입력하지_않은경우_참여한순으로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); @@ -286,11 +265,11 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito final GoalRoomPendingMember goalRoomPendingMember0 = goalRoom.getGoalRoomPendingMembers().getValues().get(0); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, member1); + LocalDateTime.now(), goalRoom, member1); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2); + LocalDateTime.now(), goalRoom, member2); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3); + LocalDateTime.now(), goalRoom, member3); goalRoomPendingMemberRepository.saveAll( List.of(goalRoomPendingMember1, goalRoomPendingMember2, goalRoomPendingMember3)); final List expected = List.of(goalRoomPendingMember0, goalRoomPendingMember1, @@ -298,9 +277,9 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito // when final List goalRoomPendingMembers1 = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); + goalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); final List goalRoomPendingMembers2 = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), null); + goalRoom.getId(), null); // then assertThat(goalRoomPendingMembers1) @@ -326,19 +305,22 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito return memberRepository.save(member); } - private RoadmapCategory 카테고리를_저장한다(final String name) { + private RoadmapCategory 카테고리를_생성한다(final String name) { final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } + private RoadmapContent 로드맵_본문을_저장한다(final Long roadmapId) { + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); + } + private List 로드맵_노드들을_생성한다() { final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); @@ -346,12 +328,6 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), @@ -359,7 +335,7 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito ); } - private GoalRoom 골룸을_생성한다(final RoadmapContent roadmapContent, final Member member) { + private GoalRoom 골룸을_저장한다(final RoadmapContent roadmapContent, final Member member) { final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent, member); final List roadmapNodes = roadmapContent.getNodes().getValues(); @@ -377,6 +353,6 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes( List.of(firstGoalRoomRoadmapNode, secondGoalRoomRoadmapNode)); goalRoom.addAllGoalRoomRoadmapNodes(goalRoomRoadmapNodes); - return goalRoom; + return goalRoomRepository.save(goalRoom); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomRepositoryTest.java index 4bde0bcf9..fdf033eb9 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomRepositoryTest.java @@ -19,19 +19,22 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; +import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; import co.kirikiri.persistence.helper.RepositoryTest; -import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import org.junit.jupiter.api.Test; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; @RepositoryTest @@ -43,18 +46,21 @@ class GoalRoomRepositoryTest { private static final LocalDate THIRTY_DAY_LATER = TODAY.plusDays(30); private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; public GoalRoomRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, - final GoalRoomRepository goalRoomRepository, - final RoadmapCategoryRepository roadmapCategoryRepository) { + final RoadmapContentRepository roadmapContentRepository, + final GoalRoomRepository goalRoomRepository) { this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; } @Test @@ -62,10 +68,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -92,10 +99,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - final Roadmap roadmap = 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -116,9 +124,9 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, goalRoomRepository.save(goalRoom2); // when - final List goalRooms1 = goalRoomRepository.findGoalRoomsByRoadmapAndCond(roadmap, + final List goalRooms1 = goalRoomRepository.findGoalRoomsByRoadmapIdAndCond(roadmap.getId(), RoadmapGoalRoomsOrderType.LATEST, null, 1); - final List goalRooms2 = goalRoomRepository.findGoalRoomsByRoadmapAndCond(roadmap, + final List goalRooms2 = goalRoomRepository.findGoalRoomsByRoadmapIdAndCond(roadmap.getId(), RoadmapGoalRoomsOrderType.LATEST, goalRoom2.getId(), 10); assertThat(goalRooms1) @@ -132,10 +140,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - final Roadmap roadmap = 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); final GoalRoomRoadmapNode goalRoomRoadmapNode2 = 골룸_로드맵_노드를_생성한다(TODAY.plusDays(11), TODAY.plusDays(20), @@ -155,9 +164,9 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, goalRoomRepository.save(goalRoom2); // when - final List goalRooms1 = goalRoomRepository.findGoalRoomsByRoadmapAndCond(roadmap, + final List goalRooms1 = goalRoomRepository.findGoalRoomsByRoadmapIdAndCond(roadmap.getId(), RoadmapGoalRoomsOrderType.CLOSE_TO_DEADLINE, null, 1); - final List goalRooms2 = goalRoomRepository.findGoalRoomsByRoadmapAndCond(roadmap, + final List goalRooms2 = goalRoomRepository.findGoalRoomsByRoadmapIdAndCond(roadmap.getId(), RoadmapGoalRoomsOrderType.CLOSE_TO_DEADLINE, goalRoom1.getId(), 10); // then @@ -170,9 +179,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -206,10 +216,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, void 투두리스트와_함께_골룸을_조회한다() { final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -243,9 +254,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸과_로드맵컨텐츠_골룸노드_투두_정보를_조회한다() { final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode); @@ -290,9 +302,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -309,8 +322,8 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode2)), creator); final GoalRoom goalRoom3 = 골룸을_생성한다("goalroom3", 20, roadmapContent, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); - final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom3", 20, roadmapContent, - new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); + final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom4", 20, roadmapContent, + new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode4)), creator); final Member member = 사용자를_생성한다("팔로워", "010-111-1111", "identifier2", "password2@"); goalRoom1.join(member); @@ -344,9 +357,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -363,8 +377,8 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode2)), creator); final GoalRoom goalRoom3 = 골룸을_생성한다("goalroom3", 20, roadmapContent, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); - final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom3", 20, roadmapContent, - new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); + final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom4", 20, roadmapContent, + new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode4)), creator); final Member member = 사용자를_생성한다("팔로워", "010-111-1111", "identifier2", "password2@"); goalRoom1.join(member); @@ -405,10 +419,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, void 노드와_함께_골룸을_조회한다() { final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -434,9 +449,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode)); - final Roadmap roadmap = 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TEN_DAY_LATER, roadmapNode); @@ -454,7 +470,7 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, goalRoomRepository.save(goalRoom3); // when - final List goalRooms = goalRoomRepository.findByRoadmap(roadmap); + final List goalRooms = goalRoomRepository.findByRoadmapId(roadmap.getId()); // then assertThat(goalRooms) @@ -466,17 +482,16 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + + final Roadmap roadmap1 = 로드맵을_저장한다(creator, category); final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); + final RoadmapContent roadmapContent1 = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap1.getId()); - final RoadmapContent roadmapContent1 = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - final Roadmap roadmap1 = 로드맵을_생성한다(creator, category, roadmapContent1); - + final Roadmap roadmap2 = 로드맵을_저장한다(creator, category); final RoadmapNode roadmapNode3 = 로드맵_노드를_생성한다("로드맵 1주차 입니다.", "로드맵 1주차 내용"); final RoadmapNode roadmapNode4 = 로드맵_노드를_생성한다("로드맵 2주차 입니다.", "로드맵 2주차 내용"); - - final RoadmapContent roadmapContent2 = 로드맵_본문을_생성한다(List.of(roadmapNode3, roadmapNode4)); - 로드맵을_생성한다(creator, category, roadmapContent2); + final RoadmapContent roadmapContent2 = 로드맵_본문을_저장한다(List.of(roadmapNode3, roadmapNode4), roadmap2.getId()); final Member member = 사용자를_생성한다("name2", "kirikiri@email.com", "identifier2", "password!2"); @@ -497,7 +512,7 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, goalRoomRepository.saveAll(List.of(goalRoom1, goalRoom2, goalRoom3)); // when - final List goalRooms = goalRoomRepository.findByRoadmap(roadmap1); + final List goalRooms = goalRoomRepository.findByRoadmapId(roadmap1.getId()); // then assertThat(goalRooms).isEqualTo(List.of(goalRoom1, goalRoom2)); @@ -508,9 +523,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode), roadmap.getId()); final GoalRoomRoadmapNode todayGoalRoomRoadmapNode = 골룸_로드맵_노드를_생성한다(TODAY, TEN_DAY_LATER, roadmapNode); @@ -556,17 +572,14 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; + private RoadmapContent 로드맵_본문을_저장한다(final List roadmapNodes, final Long roadmapId) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); } - private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category, - final RoadmapContent roadmapContent) { + private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, RoadmapDifficulty.DIFFICULT, - creator, category); - roadmap.addContent(roadmapContent); + creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomToDoCheckRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomToDoCheckRepositoryTest.java index a43022d53..dcb93f110 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomToDoCheckRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/persistence/goalroom/GoalRoomToDoCheckRepositoryTest.java @@ -20,20 +20,23 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.persistence.helper.RepositoryTest; import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.persistence.helper.RepositoryTest; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Test; @RepositoryTest class GoalRoomToDoCheckRepositoryTest { @@ -42,6 +45,7 @@ class GoalRoomToDoCheckRepositoryTest { private final MemberRepository memberRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; private final RoadmapCategoryRepository roadmapCategoryRepository; @@ -49,12 +53,14 @@ class GoalRoomToDoCheckRepositoryTest { public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomMemberRepository goalRoomMemberRepository, final RoadmapCategoryRepository roadmapCategoryRepository, final GoalRoomToDoCheckRepository goalRoomToDoCheckRepository) { this.memberRepository = memberRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; this.roadmapCategoryRepository = roadmapCategoryRepository; @@ -66,10 +72,11 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "01011111111", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -112,10 +119,11 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "01011111111", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -170,17 +178,14 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; + private RoadmapContent 로드맵_본문을_저장한다(final List roadmapNodes, final Long roadmapId) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); } - private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category, - final RoadmapContent roadmapContent) { + private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, RoadmapDifficulty.DIFFICULT, - creator, category); - roadmap.addContent(roadmapContent); + creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/helper/RepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/helper/RepositoryTest.java index 5bfa474ac..fc8ae1932 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/helper/RepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/persistence/helper/RepositoryTest.java @@ -1,13 +1,13 @@ package co.kirikiri.persistence.helper; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestConstructor; import org.springframework.test.context.TestConstructor.AutowireMode; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; @DataJpaTest @ActiveProfiles("test") diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapCreateApiTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapCreateApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapCreateApiTest.java index 72b9bda67..c491db44f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapCreateApiTest.java @@ -1,26 +1,14 @@ -package co.kirikiri.controller; +package co.kirikiri.roadmap.controller; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; -import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; -import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.multipart; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestPartFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.partWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.restdocs.request.RequestDocumentation.requestParts; +import static org.springframework.restdocs.headers.HeaderDocumentation.*; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.request.RequestDocumentation.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -30,18 +18,16 @@ import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.controller.helper.ControllerTestHelper; +import co.kirikiri.roadmap.service.RoadmapCreateService; +import co.kirikiri.roadmap.service.RoadmapReadService; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import co.kirikiri.service.dto.ErrorResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import co.kirikiri.service.roadmap.RoadmapReadService; import com.fasterxml.jackson.core.type.TypeReference; -import java.util.ArrayList; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -55,6 +41,8 @@ import org.springframework.restdocs.snippet.Attributes.Attribute; import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; +import java.util.ArrayList; +import java.util.List; @WebMvcTest(RoadmapController.class) class RoadmapCreateApiTest extends ControllerTestHelper { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapReadApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapReadApiTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapReadApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapReadApiTest.java index fa34e9c88..69f322ef2 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapReadApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapReadApiTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.controller; +package co.kirikiri.roadmap.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -10,39 +10,33 @@ import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; +import static org.springframework.restdocs.request.RequestDocumentation.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.controller.helper.ControllerTestHelper; import co.kirikiri.domain.goalroom.GoalRoomStatus; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; import co.kirikiri.member.service.dto.response.MemberResponse; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.service.RoadmapCreateService; +import co.kirikiri.roadmap.service.RoadmapReadService; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapContentResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapNodeResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapTagResponse; import co.kirikiri.service.dto.CustomScrollRequest; import co.kirikiri.service.dto.ErrorResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapContentResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapNodeResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapTagResponse; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import co.kirikiri.service.roadmap.RoadmapReadService; import com.fasterxml.jackson.core.type.TypeReference; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -50,6 +44,10 @@ import org.springframework.http.MediaType; import org.springframework.restdocs.snippet.Attributes; import org.springframework.test.web.servlet.MvcResult; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.List; @WebMvcTest(RoadmapController.class) class RoadmapReadApiTest extends ControllerTestHelper { @@ -472,7 +470,7 @@ class RoadmapReadApiTest extends ControllerTestHelper { responseFields( fieldWithPath("responses[0].goalRoomId").description("골룸 아이디"), fieldWithPath("responses[0].name").description("골룸 이름"), - fieldWithPath("responses[0].status").description("골룸 상태"), + fieldWithPath("responses[0].goalRoomStatus").description("골룸 상태"), fieldWithPath("responses[0].currentMemberCount").description("현재 골룸에 참여한 인원 수"), fieldWithPath("responses[0].limitedMemberCount").description( "골룸에 참여할 수 있는 제한 인원 수"), @@ -689,12 +687,12 @@ class RoadmapReadApiTest extends ControllerTestHelper { private RoadmapGoalRoomResponses 골룸_응답들을_생성한다() { final RoadmapGoalRoomResponse roadmapGoalRoomResponse1 = new RoadmapGoalRoomResponse(1L, "골룸 이름1", - GoalRoomStatus.RECRUITING, 3, 6, + GoalRoomStatus.RECRUITING.name(), 3, 6, LocalDateTime.of(2023, 7, 20, 13, 0, 0), LocalDate.now(), LocalDate.now().plusDays(100), new MemberResponse(1L, "황시진", "default-member-image")); final RoadmapGoalRoomResponse roadmapGoalRoomResponse2 = new RoadmapGoalRoomResponse(2L, "골룸 이름2", - GoalRoomStatus.RECRUITING, 4, 10, + GoalRoomStatus.RECRUITING.name(), 4, 10, LocalDateTime.of(2023, 7, 10, 13, 0, 0), LocalDate.now(), LocalDate.now().plusDays(100), new MemberResponse(2L, "시진이", "default-member-image")); diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapCategoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapCategoryTest.java similarity index 92% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapCategoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapCategoryTest.java index 726de9855..255ad2f96 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapCategoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapCategoryTest.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java new file mode 100644 index 000000000..d6974a0f3 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java @@ -0,0 +1,29 @@ +package co.kirikiri.roadmap.domain; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import org.junit.jupiter.api.Test; + +class RoadmapContentTest { + + @Test + void 로드맵_본문의_길이가_2000보다_크면_예외가_발생한다() { + // given + final String content = "a".repeat(2001); + + // expect + assertThatThrownBy(() -> new RoadmapContent(content, 1L, null)) + .isInstanceOf(RoadmapException.class); + } + + @Test + void 로드맵_본문은_null값을_허용한다() { + // given + final String content = null; + + // expect + assertDoesNotThrow(() -> new RoadmapContent(content, 1L, null)); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java new file mode 100644 index 000000000..a3f0b63f8 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java @@ -0,0 +1,22 @@ +package co.kirikiri.roadmap.domain; + +class RoadmapContentsTest { + +// @Test +// void 로드맵_본문을_추가한다() { +// // given +// final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목", "로드맵 노드 내용"))); +// final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); +// roadmapContent.addNodes(roadmapNodes); +// final RoadmapContents roadmapContents = new RoadmapContents(List.of(roadmapContent)); +// final RoadmapContent updatedRoadmapContent = new RoadmapContent("로드맵 본문 수정본"); +// updatedRoadmapContent.addNodes(roadmapNodes); +// +// // when +// roadmapContents.add(updatedRoadmapContent); +// +// // then +// assertThat(roadmapContents.getValues()).usingRecursiveComparison() +// .isEqualTo(List.of(roadmapContent, updatedRoadmapContent)); +// } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeImagesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeImagesTest.java similarity index 97% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeImagesTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeImagesTest.java index 12b46e1ee..ba0566cd6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeImagesTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeImagesTest.java @@ -1,12 +1,12 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import java.util.List; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.api.Test; +import java.util.List; class RoadmapNodeImagesTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeTest.java similarity index 91% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeTest.java index 97ae660fc..c54a409cf 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeTest.java @@ -1,8 +1,8 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java new file mode 100644 index 000000000..965808b8b --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java @@ -0,0 +1,78 @@ +package co.kirikiri.roadmap.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Optional; + +class RoadmapNodesTest { + + @Test + void 로드맵_본문의_노드의_이름이_겹치면_예외를_던진다() { + // given + final String title = "title"; + final RoadmapNode node1 = new RoadmapNode(title, "content1"); + final RoadmapNode node2 = new RoadmapNode(title, "content1"); + + // when,then + assertThatThrownBy(() -> new RoadmapNodes(List.of(node1, node2))) + .isInstanceOf(RoadmapException.class) + .hasMessage("한 로드맵에 같은 이름의 노드가 존재할 수 없습니다."); + } + + @Test + void 로드맵_노드_아이디로_노드를_반환한다() { + // given + final RoadmapNode node1 = new RoadmapNode(1L, "title1", "content1"); + final RoadmapNode node2 = new RoadmapNode(2L, "title2", "content2"); + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(node1, node2)); + + // when + final long findNodeId = 1; + final long notExistId = 3; + final Optional foundNode1 = roadmapNodes.findById(findNodeId); + final Optional foundNode2 = roadmapNodes.findById(notExistId); + + // then + assertAll( + () -> assertThat(node1).isEqualTo(foundNode1.get()), + () -> assertThat(foundNode2).isEmpty() + ); + } + + @Test + void 로드맵_노드_제목으로_노드를_반환한다() { + // given + final RoadmapNode node1 = new RoadmapNode(1L, "title1", "content1"); + final RoadmapNode node2 = new RoadmapNode(2L, "title2", "content2"); + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(node1, node2)); + + // when + final String findNodeTitle = "title1"; + final String notExistTitle = "nothing"; + final Optional foundNode1 = roadmapNodes.findByTitle(findNodeTitle); + final Optional foundNode2 = roadmapNodes.findByTitle(notExistTitle); + + // then + assertAll( + () -> assertThat(node1).isEqualTo(foundNode1.get()), + () -> assertThat(foundNode2).isEmpty() + ); + } + + @Test + void 로드맵_노드를_추가한다() { + // given + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목1", "로드맵 노드 내용"))); + + // when + roadmapNodes.add(new RoadmapNode("로드맵 노드 제목2", "로드맵 노드 내용")); + + // then + assertThat(roadmapNodes.getValues()).hasSize(2); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapReviewTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapReviewTest.java similarity index 54% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapReviewTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapReviewTest.java index 50c32f252..54515e4c0 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapReviewTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapReviewTest.java @@ -1,17 +1,10 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.member.domain.EncryptedPassword; -import co.kirikiri.member.domain.Gender; -import co.kirikiri.member.domain.Member; -import co.kirikiri.member.domain.MemberProfile; -import co.kirikiri.member.domain.vo.Identifier; -import co.kirikiri.member.domain.vo.Nickname; -import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -23,13 +16,12 @@ class RoadmapReviewTest { void 별점이_0부터_5사이의_소수점이_5로_끝나는_값이면서_내용이_1000자_이내라면_정상적으로_생성된다(final Double rate) { // given final String content = "a".repeat(1000); - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); + final Long memberId = 1L; + final Long roadmapId = 1L; // expected final RoadmapReview roadmapReview = - assertDoesNotThrow(() -> new RoadmapReview(content, rate, member)); + assertDoesNotThrow(() -> new RoadmapReview(content, rate, memberId, roadmapId)); assertThat(roadmapReview) .isInstanceOf(RoadmapReview.class); } @@ -38,12 +30,11 @@ class RoadmapReviewTest { void 리뷰_내용이_1000자를_넘으면_예외가_발생한다() { // given final String content = "a".repeat(1001); - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); + final Long memberId = 1L; + final Long roadmapId = 1L; // expected - assertThatThrownBy(() -> new RoadmapReview(content, null, member)) + assertThatThrownBy(() -> new RoadmapReview(content, null, memberId, roadmapId)) .isInstanceOf(RoadmapException.class); } @@ -51,12 +42,11 @@ class RoadmapReviewTest { @ValueSource(doubles = {-1, -1.5, 5.5, 1.2, 3.7, 4.55}) void 리뷰_별점이_0과_5사이의_소수점_5_단위의_값이_아니면_예외가_발생한다(final double rate) { // given - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); + final Long memberId = 1L; + final Long roadmapId = 1L; // expected - assertThatThrownBy(() -> new RoadmapReview("리뷰", rate, member)) + assertThatThrownBy(() -> new RoadmapReview("리뷰", rate, memberId, roadmapId)) .isInstanceOf(RoadmapException.class); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTagsTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTagsTest.java similarity index 93% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTagsTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTagsTest.java index 76ba65ba5..73524b170 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTagsTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTagsTest.java @@ -1,13 +1,13 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; -import java.util.List; +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; import org.junit.jupiter.api.Test; +import java.util.List; class RoadmapTagsTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java new file mode 100644 index 000000000..becb76891 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java @@ -0,0 +1,59 @@ +package co.kirikiri.roadmap.domain; + +import static co.kirikiri.roadmap.domain.RoadmapDifficulty.DIFFICULT; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import java.util.ArrayList; + +class RoadmapTest { + + private final Long creatorId = 1L; + private final RoadmapCategory category = 카테고리를_생성한다(); + private final RoadmapTags emptyTags = new RoadmapTags(new ArrayList<>()); + + @Test + void 로드맵이_성공적으로_생성된다() { + // expect + assertDoesNotThrow(() -> new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, + creatorId, category, null)); + } + + @ParameterizedTest + @ValueSource(ints = {0, 41}) + void 로드맵_제목의_길이가_1보다_작거나_40보다_크면_예외가_발생한다(final int titleLength) { + // given + final String title = "a".repeat(titleLength); + + // expect + assertThatThrownBy(() -> new Roadmap(title, "로드맵 소개글", 30, DIFFICULT, creatorId, category, emptyTags)) + .isInstanceOf(RoadmapException.class); + } + + @ParameterizedTest + @ValueSource(ints = {0, 151}) + void 로드맵_소개글의_길이가_1보다_작거나_150보다_크면_예외가_발생한다(final int introductionLength) { + // given + final String introduction = "a".repeat(introductionLength); + + // expect + assertThatThrownBy(() -> new Roadmap("로드맵 제목", introduction, 30, DIFFICULT, creatorId, category, emptyTags)) + .isInstanceOf(RoadmapException.class); + } + + @ParameterizedTest + @ValueSource(ints = {-1, 1001}) + void 로드맵_추천_소요_기간이_0보다_작고_1000보다_크면_예외가_발생한다(final int requiredPeriod) { + // expect + assertThatThrownBy(() -> new Roadmap("로드맵 제목", "로드맵 소개글", requiredPeriod, DIFFICULT, creatorId, category, emptyTags)) + .isInstanceOf(RoadmapException.class); + } + + private RoadmapCategory 카테고리를_생성한다() { + return new RoadmapCategory(1L, "여가"); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/vo/RoadmapTagNameTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/vo/RoadmapTagNameTest.java similarity index 94% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/vo/RoadmapTagNameTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/vo/RoadmapTagNameTest.java index d563697df..84fdd7532 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/vo/RoadmapTagNameTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/vo/RoadmapTagNameTest.java @@ -1,10 +1,10 @@ -package co.kirikiri.domain.roadmap.vo; +package co.kirikiri.roadmap.domain.vo; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapContentRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapContentRepositoryTest.java similarity index 58% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapContentRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapContentRepositoryTest.java index 3c201e212..fdfd2c8d6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapContentRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapContentRepositoryTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -10,13 +10,16 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.persistence.helper.RepositoryTest; import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.persistence.helper.RepositoryTest; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapTags; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; @RepositoryTest class RoadmapContentRepositoryTest { @@ -37,52 +40,51 @@ public RoadmapContentRepositoryTest(final MemberRepository memberRepository, } @Test - void 로드맵_컨텐츠를_로드맵과_함께_조회한다() { + void 로드맵_아이디로_로드맵의_가장_최근_컨텐츠를_조회한다() { // given - final Roadmap roadmap = 로드맵을_생성한다(); - final Roadmap savedRoadmap = roadmapRepository.save(roadmap); - final Long roadmapContentId = savedRoadmap.getContents().getValues().get(0).getId(); + final Roadmap roadmap = 로드맵을_저장한다(); + 로드맵_컨텐츠를_저장한다(roadmap.getId()); + final RoadmapContent oldRoadmapContent = roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc( + roadmap.getId()).get(); + + final RoadmapContent newRoadmapContent = 로드맵_컨텐츠를_저장한다(roadmap.getId()); // when - final RoadmapContent roadmapContent = roadmapContentRepository.findByIdWithRoadmap(roadmapContentId).get(); + final RoadmapContent expectedRoadmapContent = roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc( + roadmap.getId()).get(); // then assertAll( - () -> assertThat(roadmapContent).isEqualTo(savedRoadmap.getContents().getValues().get(0)), - () -> assertThat(roadmapContent.getRoadmap()).isEqualTo(savedRoadmap) + () -> assertThat(oldRoadmapContent).isNotEqualTo(expectedRoadmapContent), + () -> assertThat(newRoadmapContent).isEqualTo(expectedRoadmapContent) ); } @Test - void 로드맵의_가장_최근_컨텐츠를_조회한다() { + void 로드맵에_생성된_모든_컨텐츠를_삭제한다() { // given - final Roadmap savedRoadmap = roadmapRepository.save(로드맵을_생성한다()); - final RoadmapContent oldRoadmapContent = roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc( - savedRoadmap).get(); - - final RoadmapContent newRoadmapContent = new RoadmapContent("로드맵 제목"); - savedRoadmap.addContent(newRoadmapContent); + final Roadmap roadmap = 로드맵을_저장한다(); + 로드맵_컨텐츠를_저장한다(roadmap.getId()); + 로드맵_컨텐츠를_저장한다(roadmap.getId()); // when - final RoadmapContent expectedRoadmapContent = roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc( - savedRoadmap).get(); + final List roadmapContents = roadmapContentRepository.findAllByRoadmapId(roadmap.getId()); + roadmapContentRepository.deleteAllByRoadmapId(roadmap.getId()); // then assertAll( - () -> assertThat(oldRoadmapContent).isNotEqualTo(expectedRoadmapContent), - () -> assertThat(expectedRoadmapContent).isEqualTo(newRoadmapContent) + () -> assertThat(roadmapContents).hasSize(2), + () -> assertThat(roadmapContentRepository.findAllByRoadmapId(roadmap.getId())) + .isEmpty() ); } - private Roadmap 로드맵을_생성한다() { + private Roadmap 로드맵을_저장한다() { final Member creator = 사용자를_생성한다(); final RoadmapCategory category = 로드맵_카테고리를_생성한다(); - final RoadmapContent content = new RoadmapContent("로드맵 제목"); - - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(content); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); - return roadmap; + return roadmapRepository.save(roadmap); } private Member 사용자를_생성한다() { @@ -97,4 +99,8 @@ public RoadmapContentRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory category = new RoadmapCategory("운동"); return roadmapCategoryRepository.save(category); } + + private RoadmapContent 로드맵_컨텐츠를_저장한다(final Long roadmapId) { + return roadmapContentRepository.save(new RoadmapContent("content", roadmapId, null)); + } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapRepositoryTest.java similarity index 82% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapRepositoryTest.java index 026fd182d..d81d43f62 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapRepositoryTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -20,48 +20,55 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.domain.roadmap.RoadmapTag; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchDto; +import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; import co.kirikiri.persistence.helper.RepositoryTest; -import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.Test; @RepositoryTest class RoadmapRepositoryTest { private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; + private final RoadmapReviewRepository roadmapReviewRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; public RoadmapRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, + final RoadmapReviewRepository roadmapReviewRepository, final GoalRoomRepository goalRoomRepository, - final GoalRoomMemberRepository goalRoomMemberRepository, - final RoadmapCategoryRepository roadmapCategoryRepository) { + final GoalRoomMemberRepository goalRoomMemberRepository) { this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; + this.roadmapReviewRepository = roadmapReviewRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; } @Test @@ -69,7 +76,7 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("cokirikiri", "코끼리"); final RoadmapCategory category = 카테고리를_생성한다("여가"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); // when final Roadmap savedRoadmap = roadmapRepository.save(roadmap); @@ -87,7 +94,7 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final Roadmap savedRoadmap = 로드맵을_저장한다("로드맵 제목", creator, category); // when - final Roadmap expectedRoadmap = roadmapRepository.findRoadmapById(savedRoadmap.getId()).get(); + final Roadmap expectedRoadmap = roadmapRepository.findById(savedRoadmap.getId()).get(); assertThat(expectedRoadmap) .usingRecursiveComparison() @@ -191,19 +198,26 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); final RoadmapCategory travelCategory = 카테고리를_생성한다("여행"); - final Roadmap gameRoadmap1 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵", creator, gameCategory); - final Roadmap gameRoadmap2 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵2", creator, gameCategory); - final Roadmap travelRoadmap = 노드_정보를_포함한_로드맵을_생성한다("여행 로드맵", creator, travelCategory); - 노드_정보를_포함한_삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + final Roadmap gameRoadmap1 = 로드맵을_저장한다("게임 로드맵", creator, gameCategory); + final RoadmapContent gameRoadmapContent1 = 로드맵_컨텐츠를_저장한다(gameRoadmap1.getId()); + + final Roadmap gameRoadmap2 = 로드맵을_저장한다("게임 로드맵2", creator, gameCategory); + 로드맵_컨텐츠를_저장한다(gameRoadmap2.getId()); + + final Roadmap travelRoadmap = 로드맵을_저장한다("여행 로드맵", creator, travelCategory); + final RoadmapContent travelRoadmapContent = 로드맵_컨텐츠를_저장한다(travelRoadmap.getId()); + + final Roadmap deletedRoadmap = 삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + 로드맵_컨텐츠를_저장한다(deletedRoadmap.getId()); // gameRoadmap1 : 골룸 3개 - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); + 골룸을_생성한다(gameRoadmapContent1, creator); + 골룸을_생성한다(gameRoadmapContent1, creator); + 골룸을_생성한다(gameRoadmapContent1, creator); // gameRoadmap2 : 골룸 0개 // travelRoadmap : 골룸 1개 - 골룸을_생성한다(travelRoadmap.getContents().getValues().get(0), creator); + 골룸을_생성한다(travelRoadmapContent, creator); final RoadmapCategory category = null; final RoadmapOrderType orderType = RoadmapOrderType.GOAL_ROOM_COUNT; @@ -236,14 +250,21 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); final RoadmapCategory travelCategory = 카테고리를_생성한다("여행"); - final Roadmap gameRoadmap1 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵", creator, gameCategory); - final Roadmap gameRoadmap2 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵2", creator, gameCategory); - final Roadmap travelRoadmap = 노드_정보를_포함한_로드맵을_생성한다("여행 로드맵", creator, travelCategory); - 노드_정보를_포함한_삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + final Roadmap gameRoadmap1 = 로드맵을_저장한다("게임 로드맵", creator, gameCategory); + final RoadmapContent gameRoadmapContent1 = 로드맵_컨텐츠를_저장한다(gameRoadmap1.getId()); + + final Roadmap gameRoadmap2 = 로드맵을_저장한다("게임 로드맵2", creator, gameCategory); + final RoadmapContent gameRoadmapContent2 = 로드맵_컨텐츠를_저장한다(gameRoadmap2.getId()); + + final Roadmap travelRoadmap = 로드맵을_저장한다("여행 로드맵", creator, travelCategory); + final RoadmapContent travelRoadmapContent = 로드맵_컨텐츠를_저장한다(travelRoadmap.getId()); + + final Roadmap deletedRoadmap = 삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + 로드맵_컨텐츠를_저장한다(deletedRoadmap.getId()); - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); - final GoalRoom gameRoadmap2GoalRoom = 골룸을_생성한다(gameRoadmap2.getContents().getValues().get(0), creator); - final GoalRoom travelRoadmapGoalRoom = 골룸을_생성한다(travelRoadmap.getContents().getValues().get(0), creator); + 골룸을_생성한다(gameRoadmapContent1, creator); + final GoalRoom gameRoadmap2GoalRoom = 골룸을_생성한다(gameRoadmapContent2, creator); + final GoalRoom travelRoadmapGoalRoom = 골룸을_생성한다(travelRoadmapContent, creator); // gameRoadmap1 : 참가인원 0명 // gameRoadmap2 : 참가인원 1명 @@ -288,25 +309,22 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); final RoadmapCategory travelCategory = 카테고리를_생성한다("여행"); - final Roadmap gameRoadmap1 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵", creator, gameCategory); - final Roadmap gameRoadmap2 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵2", creator, gameCategory); - final Roadmap travelRoadmap = 노드_정보를_포함한_로드맵을_생성한다("여행 로드맵", creator, travelCategory); - 노드_정보를_포함한_삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + final Roadmap gameRoadmap1 = 로드맵을_저장한다("게임 로드맵", creator, gameCategory); + final Roadmap gameRoadmap2 = 로드맵을_저장한다("게임 로드맵2", creator, gameCategory); + final Roadmap travelRoadmap = 로드맵을_저장한다("여행 로드맵", creator, travelCategory); + 삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); // gameRoadmap1 : 4.5 - final RoadmapReview gameRoadmap1Review = new RoadmapReview("리뷰1", 4.5, follower); - gameRoadmap1.addReview(gameRoadmap1Review); - roadmapRepository.save(gameRoadmap1); + final RoadmapReview gameRoadmap1Review = new RoadmapReview("리뷰1", 4.5, follower.getId(), gameRoadmap1.getId()); + roadmapReviewRepository.save(gameRoadmap1Review); // gameRoadmap2 : 5.0 - final RoadmapReview gameRoadmap2Review = new RoadmapReview("리뷰2", 5.0, follower); - gameRoadmap2.addReview(gameRoadmap2Review); - roadmapRepository.save(gameRoadmap2); + final RoadmapReview gameRoadmap2Review = new RoadmapReview("리뷰2", 5.0, follower.getId(), gameRoadmap2.getId()); + roadmapReviewRepository.save(gameRoadmap2Review); // travelRoadmap : 4.0 - final RoadmapReview travelRoadmapReview = new RoadmapReview("리뷰3", 4.0, follower); - travelRoadmap.addReview(travelRoadmapReview); - roadmapRepository.save(travelRoadmap); + final RoadmapReview travelRoadmapReview = new RoadmapReview("리뷰3", 4.0, follower.getId(), travelRoadmap.getId()); + roadmapReviewRepository.save(travelRoadmapReview); final RoadmapCategory category = null; final RoadmapOrderType orderType = RoadmapOrderType.REVIEW_RATE; @@ -462,10 +480,10 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, roadmapRepository.saveAll(List.of(gameRoadmap, travelRoadmap, deletedGameRoadmap)); // when - final List roadmapsFirstPage = roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest(creator, + final List roadmapsFirstPage = roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest(creator.getId(), null, 2); - final List roadmapsSecondPage = roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest( - creator, roadmapsFirstPage.get(1).getId(), 2); + final List roadmapsSecondPage = roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest( + creator.getId(), roadmapsFirstPage.get(1).getId(), 2); // then assertAll( @@ -524,7 +542,7 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, } @Test - void 삭제된_로드맵을_로드맵_본문과_함께_조회한다() { + void 삭제된_로드맵을_조회한다() { // given final Member creator = 사용자를_생성한다("cokirikiri", "코끼리"); final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); @@ -535,14 +553,10 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final Roadmap deletedRoadmap = 삭제된_로드맵을_저장한다("로드맵", creator, travelCategory); // when - final List roadmapsByStatus = roadmapRepository.findWithRoadmapContentByStatus(RoadmapStatus.DELETED); + final List roadmapsByStatus = roadmapRepository.findByStatus(RoadmapStatus.DELETED); // then - assertAll( - () -> assertThat(roadmapsByStatus).isEqualTo(List.of(deletedRoadmap)), - () -> assertThat(roadmapsByStatus.get(0).getContents().getValues().get(0).getContent()) - .isEqualTo("로드맵 본문2") - ); + assertThat(roadmapsByStatus).isEqualTo(List.of(deletedRoadmap)); } private Member 사용자를_생성한다(final String identifier, final String nickname) { @@ -559,41 +573,26 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, } private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(new RoadmapContent("로드맵 본문")); + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } private Roadmap 삭제된_로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글2", 7, RoadmapDifficulty.DIFFICULT, creator, category); - roadmap.addContent(new RoadmapContent("로드맵 본문2")); + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글2", 7, RoadmapDifficulty.DIFFICULT, creator.getId(), category, new RoadmapTags(new ArrayList<>())); roadmap.delete(); return roadmapRepository.save(roadmap); } - private Roadmap 로드맵을_태그와_저장한다(final String title, final Member creator, final RoadmapCategory category, - final RoadmapTags roadmapTags) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addTags(roadmapTags); - return roadmapRepository.save(roadmap); - } - - private Roadmap 노드_정보를_포함한_로드맵을_생성한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); + private RoadmapContent 로드맵_컨텐츠를_저장한다(final Long roadmapId) { final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(List.of(roadmapNode1, roadmapNode2))); + return roadmapContentRepository.save(roadmapContent); } - private Roadmap 노드_정보를_포함한_삭제된_로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - roadmap.addContent(roadmapContent); - roadmap.delete(); + private Roadmap 로드맵을_태그와_저장한다(final String title, final Member creator, final RoadmapCategory category, + final RoadmapTags roadmapTags) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, roadmapTags); return roadmapRepository.save(roadmap); } @@ -601,12 +600,6 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private GoalRoom 골룸을_생성한다(final RoadmapContent roadmapContent, final Member member) { final LocalDate today = LocalDate.now(); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(today, today.plusDays(10), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepositoryTest.java similarity index 59% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepositoryTest.java index 188073880..cf9cc5e30 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepositoryTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; @@ -12,15 +12,10 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.persistence.helper.RepositoryTest; import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.persistence.helper.RepositoryTest; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapReview; import org.junit.jupiter.api.Test; import java.util.List; import java.util.Optional; @@ -47,19 +42,17 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, void 로드맵과_사용자로_로드맵_리뷰_정보가_존재하면_반환한다() { // given final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(member, category); + final Long roadmapId = 1L; - final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 1.5, member); - roadmapReview.updateRoadmap(roadmap); + final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 1.5, member.getId(), roadmapId); roadmapReviewRepository.save(roadmapReview); // when - final RoadmapReview findRoadmapReview = roadmapReviewRepository.findByRoadmapAndMember(roadmap, member).get(); + final RoadmapReview findRoadmapReview = roadmapReviewRepository.findByRoadmapIdAndMemberId(roadmapId, member.getId()) + .get(); // then - assertThat(findRoadmapReview) - .isEqualTo(roadmapReview); + assertThat(findRoadmapReview).isEqualTo(roadmapReview); } @Test @@ -67,20 +60,17 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, // given final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); final Member member2 = 사용자를_저장한다("끼리코", "kirikirico"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(member, category); + final Long roadmapId = 1L; - final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member); - roadmapReview.updateRoadmap(roadmap); + final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member.getId(), roadmapId); roadmapReviewRepository.save(roadmapReview); // when - final Optional findRoadmapReview = roadmapReviewRepository.findByRoadmapAndMember(roadmap, - member2); + final Optional findRoadmapReview = roadmapReviewRepository.findByRoadmapIdAndMemberId(roadmapId, + member2.getId()); // then - assertThat(findRoadmapReview) - .isEmpty(); + assertThat(findRoadmapReview).isEmpty(); } @Test @@ -89,25 +79,21 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); final Member member2 = 사용자를_저장한다("끼리코", "kirikirico"); final Member member3 = 사용자를_저장한다("리끼코", "rikirikico"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(member, category); - - final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰1", 2.5, member); - final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰2", 4.0, member2); - final RoadmapReview roadmapReview3 = new RoadmapReview("리뷰3", 5.0, member3); - roadmapReview1.updateRoadmap(roadmap); - roadmapReview2.updateRoadmap(roadmap); - roadmapReview3.updateRoadmap(roadmap); + final Long roadmapId = 1L; + + final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰1", 2.5, member.getId(), roadmapId); + final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰2", 4.0, member2.getId(), roadmapId); + final RoadmapReview roadmapReview3 = new RoadmapReview("리뷰3", 5.0, member3.getId(), roadmapId); roadmapReviewRepository.save(roadmapReview1); roadmapReviewRepository.save(roadmapReview2); roadmapReviewRepository.save(roadmapReview3); // when - final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap, null, 2); + final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmapId, null, 2); - final List roadmapReviewsSecondPage = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap, roadmapReviewsFirstPage.get(1).getId(), 2); + final List roadmapReviewsSecondPage = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmapId, roadmapReviewsFirstPage.get(1).getId(), 2); // then assertAll( @@ -122,18 +108,15 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, void 로드맵에_대한_리뷰_정보가_없으면_빈_값을_반환한다() { // given final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); - final Member member2 = 사용자를_저장한다("끼리코", "kirikirico"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap1 = 로드맵을_저장한다(member, category); - final Roadmap roadmap2 = 로드맵을_저장한다(member2, category); + final Long roadmapId = 1L; + final Long roadmapId2 = 2L; - final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member); - roadmapReview.updateRoadmap(roadmap1); + final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member.getId(), roadmapId2); roadmapReviewRepository.save(roadmapReview); // when - final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap2, null, 1); + final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmapId, null, 1); // then assertThat(roadmapReviewsFirstPage).isEmpty(); @@ -151,24 +134,4 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } - - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); - } - - private List 로드맵_노드들을_생성한다() { - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - return List.of(roadmapNode1, roadmapNode2); - } - - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTagNameTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagNameTest.java similarity index 89% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTagNameTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagNameTest.java index 795be340d..eaac6349a 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTagNameTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagNameTest.java @@ -1,10 +1,10 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @@ -40,6 +40,6 @@ class RoadmapSearchTagNameTest { // expected assertThatThrownBy(() -> new RoadmapSearchTagName(name)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(RoadmapException.class); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTitleTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitleTest.java similarity index 89% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTitleTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitleTest.java index 10e762ae4..698710a89 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTitleTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitleTest.java @@ -1,10 +1,10 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @@ -40,6 +40,6 @@ class RoadmapSearchTitleTest { // expected assertThatThrownBy(() -> new RoadmapSearchTitle(title)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(RoadmapException.class); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolverTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java similarity index 93% rename from backend/kirikiri/src/test/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolverTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java index e4db7865c..bf63d3c5e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolverTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.common.resolver; +package co.kirikiri.roadmap.resolver; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -6,10 +6,9 @@ import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.member.service.dto.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import javax.xml.validation.Validator; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -24,14 +23,11 @@ import org.springframework.web.method.support.ModelAndViewContainer; @ExtendWith(MockitoExtension.class) -class RoadmapSaveArgumentResolverTest { +class RoadmapSaveArgumentResolverImplTest { @Mock private ObjectMapper objectMapper; - @Mock - private Validator validator; - @Mock private MethodParameter parameter; @@ -45,7 +41,7 @@ class RoadmapSaveArgumentResolverTest { private WebDataBinderFactory binderFactory; @InjectMocks - private RoadmapSaveArgumentResolver resolver; + private RoadmapSaveArgumentResolverImpl resolver; @Test void 정상적으로_핸들러의_파라미터가_객체를_타도록_한다() { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateEventListenerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateEventListenerTest.java similarity index 62% rename from backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateEventListenerTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateEventListenerTest.java index 760430c4b..12779de3e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateEventListenerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateEventListenerTest.java @@ -1,36 +1,28 @@ -package co.kirikiri.service; +package co.kirikiri.roadmap.service; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.ServerException; import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.service.FileService; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.member.domain.EncryptedPassword; -import co.kirikiri.member.domain.Gender; -import co.kirikiri.member.domain.Member; -import co.kirikiri.member.domain.MemberProfile; -import co.kirikiri.member.domain.vo.Identifier; -import co.kirikiri.member.domain.vo.Nickname; -import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.service.dto.RoadmapNodeSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapTagSaveDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.event.RoadmapCreateEvent; import co.kirikiri.service.dto.FileInformation; -import co.kirikiri.service.dto.roadmap.RoadmapNodeSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapTagSaveDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.event.RoadmapCreateEvent; -import co.kirikiri.service.roadmap.RoadmapCreateEventListener; -import java.io.IOException; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -38,13 +30,15 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class RoadmapCreateEventListenerTest { - private static final Member member = new Member(1L, new Identifier("identifier1"), - null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); + private final Long memberId = 1L; @Mock private RoadmapContentRepository roadmapContentRepository; @@ -60,12 +54,10 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 @Test void 정상적으로_로드맵_노드_이미지를_저장한다() throws IOException { - final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent"); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "introduction", 10, + RoadmapDifficulty.DIFFICULT, RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final RoadmapNode roadmapNode = new RoadmapNode("roadmapNodeTitle", "roadmapNodeContent"); - roadmapContent.addNodes(new RoadmapNodes(List.of(roadmapNode))); - - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent", roadmap.getId(), new RoadmapNodes(List.of(roadmapNode))); final MultipartFile imageFile = new MockMultipartFile(roadmapNode.getTitle(), "originalFileName.jpeg", "image/jpeg", "tempImage".getBytes()); @@ -77,11 +69,11 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 roadmapContent.getContent(), RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - roadmap.addContent(roadmapContent); - - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); // When + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent); // Then @@ -91,8 +83,8 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 @Test void 로드맵에_컨텐츠가_존재하지_않을_경우_예외를_던진다() throws IOException { //given - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "inroduction", 10, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final MultipartFile imageFile = new MockMultipartFile("roadmapNodeTitle", "originalFileName.jpeg", "image/jpeg", "tempImage".getBytes()); @@ -104,23 +96,25 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 "roadmapNodeContent", RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); //when + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.empty()); + //then assertThatThrownBy(() -> roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent)) - .isInstanceOf(ServerException.class); + .isInstanceOf(ServerException.class) + .hasMessage("로드맵 컨텐츠가 존재하지 않습니다."); } @Test void 로드맵_노드_제목을_가진_노드가_로드맵에_존재하지_않을때_예외를_던진다() throws IOException { //given - final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent"); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "introduction", 10, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final RoadmapNode roadmapNode = new RoadmapNode("roadmapNodeTitle", "roadmapNodeContent"); - roadmapContent.addNodes(new RoadmapNodes(List.of(roadmapNode))); - - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent", roadmap.getId(), new RoadmapNodes(List.of(roadmapNode))); final MultipartFile imageFile = new MockMultipartFile(roadmapNode.getTitle(), "originalFileName.jpeg", "image/jpeg", "tempImage".getBytes()); @@ -132,43 +126,45 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 roadmapContent.getContent(), RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - roadmap.addContent(roadmapContent); - - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); //when + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); + //then assertThatThrownBy(() -> roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(BadRequestException.class) + .hasMessage("해당 제목을 가지고 있는 로드맵 노드가 없습니다. title = Wrong Title"); } @Test void 로드맵_노드_이미지에_원본_파일_이름이_없을_경우_예외를_던진다() throws IOException { //given - final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent"); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "inroduction", 10, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final RoadmapNode roadmapNode = new RoadmapNode("roadmapNodeTitle", "roadmapNodeContent"); - roadmapContent.addNodes(new RoadmapNodes(List.of(roadmapNode))); - - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent", roadmap.getId(), new RoadmapNodes(List.of(roadmapNode))); final MultipartFile imageFile = new MockMultipartFile(roadmapNode.getTitle(), null, "image/jpeg", "tempImage".getBytes()); - final FileInformation fileInformation = new FileInformation(imageFile.getOriginalFilename(), - imageFile.getSize(), imageFile.getContentType(), imageFile.getInputStream()); - final RoadmapNodeSaveDto roadmapNodeSaveDto = new RoadmapNodeSaveDto("Wrong Title", roadmapNode.getContent(), + final FileInformation fileInformation = new FileInformation(null, imageFile.getSize(), + imageFile.getContentType(), imageFile.getInputStream()); + final RoadmapNodeSaveDto roadmapNodeSaveDto = new RoadmapNodeSaveDto("roadmapNodeTitle", roadmapNode.getContent(), List.of(fileInformation)); final RoadmapSaveDto roadmapSaveDto = new RoadmapSaveDto(1L, roadmap.getTitle(), roadmap.getIntroduction(), roadmapContent.getContent(), RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - roadmap.addContent(roadmapContent); - - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); //when + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); + //then assertThatThrownBy(() -> roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(BadRequestException.class) + .hasMessage("원본 파일의 이름이 존재하지 않습니다."); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateServiceTest.java similarity index 73% rename from backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateServiceTest.java index bcc5e7a5c..96e15b60d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateServiceTest.java @@ -1,33 +1,17 @@ -package co.kirikiri.service; +package co.kirikiri.roadmap.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import co.kirikiri.common.exception.AuthenticationException; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.goalroom.GoalRoomMember; -import co.kirikiri.domain.goalroom.GoalRoomRole; -import co.kirikiri.domain.goalroom.vo.GoalRoomName; -import co.kirikiri.domain.goalroom.vo.LimitedMemberCount; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapReview; import co.kirikiri.member.domain.EncryptedPassword; import co.kirikiri.member.domain.Gender; import co.kirikiri.member.domain.Member; @@ -36,28 +20,35 @@ import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; import co.kirikiri.member.persistence.MemberRepository; -import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; -import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.List; -import java.util.Optional; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.context.ApplicationEventPublisher; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class RoadmapCreateServiceTest { @@ -74,13 +65,10 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 private RoadmapRepository roadmapRepository; @Mock - private RoadmapReviewRepository roadmapReviewRepository; - - @Mock - private GoalRoomRepository goalRoomRepository; + private RoadmapContentRepository roadmapContentRepository; @Mock - private GoalRoomMemberRepository goalRoomMemberRepository; + private RoadmapReviewRepository roadmapReviewRepository; @Mock private RoadmapCategoryRepository roadmapCategoryRepository; @@ -88,6 +76,9 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 @Mock private ApplicationEventPublisher applicationEventPublisher; + @Mock + private RoadmapGoalRoomService roadmapGoalRoomService; + @InjectMocks private RoadmapCreateService roadmapCreateService; @@ -107,13 +98,15 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 final RoadmapSaveRequest request = new RoadmapSaveRequest(1L, roadmapTitle, roadmapIntroduction, roadmapContent, difficulty, requiredPeriod, roadmapNodes, roadmapTags); + when(memberRepository.findByIdentifier(MEMBER.getIdentifier())) + .thenReturn(Optional.of(MEMBER)); given(roadmapCategoryRepository.findById(any())) .willReturn(Optional.of(category)); given(roadmapRepository.save(any())) - .willReturn(new Roadmap(1L, roadmapTitle, roadmapIntroduction, requiredPeriod, - RoadmapDifficulty.valueOf(difficulty.name()), MEMBER, category)); - when(memberRepository.findByIdentifier(MEMBER.getIdentifier())) - .thenReturn(Optional.of(MEMBER)); + .willReturn(new Roadmap(1L, roadmapTitle, roadmapIntroduction, requiredPeriod, RoadmapDifficulty.valueOf(difficulty.name()), + RoadmapStatus.CREATED, MEMBER.getId(), category, new RoadmapTags(List.of(new RoadmapTag(new RoadmapTagName("태그 1")))))); + given(roadmapContentRepository.save(any())) + .willReturn(new RoadmapContent(roadmapContent, 1L, null)); // expect assertDoesNotThrow(() -> roadmapCreateService.create(request, "identifier1")); @@ -162,18 +155,13 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); final RoadmapCategory category = new RoadmapCategory(1L, "운동"); - final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(MEMBER, targetRoadmapContent); when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(anyLong(), any(), any())) - .thenReturn(Optional.of( - new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower))); - when(roadmapReviewRepository.findByRoadmapAndMember(any(), any())) + when(roadmapGoalRoomService.findCompletedGoalRoomMember(anyLong(), any())) + .thenReturn(follower); + when(roadmapReviewRepository.findByRoadmapIdAndMemberId(any(), anyLong())) .thenReturn(Optional.empty()); final RoadmapReviewSaveRequest roadmapReviewSaveRequest = new RoadmapReviewSaveRequest("최고의 로드맵이네요", 5.0); @@ -205,8 +193,8 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(anyLong(), any(), any())) - .thenReturn(Optional.empty()); + when(roadmapGoalRoomService.findCompletedGoalRoomMember(anyLong(), any())) + .thenThrow(new BadRequestException("Error Message")); final RoadmapReviewSaveRequest roadmapReviewSaveRequest = new RoadmapReviewSaveRequest("리뷰 내용", null); @@ -225,19 +213,14 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); final RoadmapCategory category = new RoadmapCategory(1L, "운동"); - final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(MEMBER, targetRoadmapContent); when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(anyLong(), any(), any())) - .thenReturn(Optional.of( - new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower))); - when(roadmapReviewRepository.findByRoadmapAndMember(any(), any())) - .thenReturn(Optional.of(new RoadmapReview("로드맵 짱!", 5.0, MEMBER))); + when(roadmapGoalRoomService.findCompletedGoalRoomMember(anyLong(), any())) + .thenReturn(follower); + when(roadmapReviewRepository.findByRoadmapIdAndMemberId(any(), anyLong())) + .thenReturn(Optional.of(new RoadmapReview("로드맵 짱!", 5.0, MEMBER.getId(), roadmap.getId()))); final RoadmapReviewSaveRequest roadmapReviewSaveRequest = new RoadmapReviewSaveRequest("최고의 로드맵이네요", 5.0); @@ -256,8 +239,8 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 .thenReturn(Optional.of(roadmap)); when(roadmapRepository.findByIdAndMemberIdentifier(anyLong(), anyString())) .thenReturn(Optional.of(roadmap)); - when(goalRoomRepository.findByRoadmap(any())) - .thenReturn(Collections.emptyList()); + when(roadmapGoalRoomService.hasGoalRooms(roadmap.getId())) + .thenReturn(false); // when // then @@ -275,16 +258,12 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 final RoadmapCategory category = new RoadmapCategory(1L, "운동"); final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(follower, targetRoadmapContent); - when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); when(roadmapRepository.findByIdAndMemberIdentifier(anyLong(), anyString())) .thenReturn(Optional.of(roadmap)); - when(goalRoomRepository.findByRoadmap(any())) - .thenReturn(List.of(goalRoom)); + when(roadmapGoalRoomService.hasGoalRooms(roadmap.getId())) + .thenReturn(true); // when // then @@ -312,10 +291,6 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 final RoadmapCategory category = new RoadmapCategory(1L, "운동"); final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - 골룸을_생성한다(MEMBER, targetRoadmapContent); - when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); when(roadmapRepository.findByIdAndMemberIdentifier(anyLong(), anyString())) @@ -356,13 +331,7 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 } private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category) { - final RoadmapContent content = new RoadmapContent("콘텐츠 제목"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(content); - return roadmap; - } - - private GoalRoom 골룸을_생성한다(final Member member, final RoadmapContent roadmapContent) { - return new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent, member); + return new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, + RoadmapStatus.CREATED, creator.getId(), category, new RoadmapTags(new ArrayList<>())); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapReadServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapReadServiceTest.java similarity index 75% rename from backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapReadServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapReadServiceTest.java index 09b00a96e..66c15c0ef 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapReadServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapReadServiceTest.java @@ -1,34 +1,15 @@ -package co.kirikiri.service; +package co.kirikiri.roadmap.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FileService; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.goalroom.GoalRoomRoadmapNode; -import co.kirikiri.domain.goalroom.GoalRoomRoadmapNodes; import co.kirikiri.domain.goalroom.GoalRoomStatus; -import co.kirikiri.domain.goalroom.vo.GoalRoomName; -import co.kirikiri.domain.goalroom.vo.LimitedMemberCount; -import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapTag; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; import co.kirikiri.member.domain.EncryptedPassword; import co.kirikiri.member.domain.Gender; import co.kirikiri.member.domain.Member; @@ -39,41 +20,51 @@ import co.kirikiri.member.domain.vo.Password; import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.member.service.dto.response.MemberResponse; -import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import co.kirikiri.persistence.goalroom.dto.RoadmapGoalRoomsOrderType; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapContentResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapNodeResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapTagResponse; import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapContentResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapNodeResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapTagResponse; -import co.kirikiri.service.roadmap.RoadmapReadService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class RoadmapReadServiceTest { @@ -86,6 +77,9 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 new MemberProfile(Gender.FEMALE, "kirikiri1@email.com")); private final LocalDateTime now = LocalDateTime.now(); + @Mock + private MemberRepository memberRepository; + @Mock private RoadmapRepository roadmapRepository; @@ -96,13 +90,10 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 private RoadmapContentRepository roadmapContentRepository; @Mock - private GoalRoomRepository goalRoomRepository; + private RoadmapReviewRepository roadmapReviewRepository; @Mock - private MemberRepository memberRepository; - - @Mock - private RoadmapReviewRepository roadmapReviewRepository; + private RoadmapGoalRoomService roadmapGoalRoomService; @Mock private FileService fileService; @@ -113,30 +104,27 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 @Test void 특정_아이디를_가지는_로드맵_단일_조회시_해당_로드맵의_정보를_반환한다() throws MalformedURLException { //given - final Member member = 사용자를_생성한다(1L, "identifier1", "코끼리"); final RoadmapCategory category = 로드맵_카테고리를_생성한다(1L, "운동"); - final RoadmapContent content = 로드맵_컨텐츠를_생성한다(1L, "콘텐츠 내용"); final Roadmap roadmap = 로드맵을_생성한다("로드맵 제목", category); - roadmap.addContent(content); - final Long roadmapId = 1L; - - final List goalRooms = 상태별_골룸_목록을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_컨텐츠를_생성한다("로드맵 본문", roadmap.getId()); - when(roadmapRepository.findRoadmapById(anyLong())) + when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(any())) - .thenReturn(Optional.of(roadmap.getContents().getValues().get(0))); - when(goalRoomRepository.findByRoadmap(any())) - .thenReturn(goalRooms); + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); + when(roadmapGoalRoomService.findRoadmapGoalRoomsByRoadmap(any())) + .thenReturn(new RoadmapGoalRoomNumberDto(2, 2, 2)); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); when(fileService.generateUrl(anyString(), any())) .thenReturn(new URL("http://example.com/serverFilePath")); //when - final RoadmapResponse roadmapResponse = roadmapService.findRoadmap(roadmapId); + final RoadmapResponse roadmapResponse = roadmapService.findRoadmap(roadmap.getId()); //then final RoadmapResponse expectedResponse = new RoadmapResponse( - roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로드맵 소개글", + roadmap.getId(), new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로드맵 소개글", new MemberResponse(1L, "닉네임", "http://example.com/serverFilePath"), new RoadmapContentResponse(1L, "로드맵 본문", List.of( new RoadmapNodeResponse(1L, "로드맵 노드1 제목", "로드맵 노드1 설명", Collections.emptyList()) @@ -155,7 +143,7 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 @Test void 로드맵_단일_조회_시_로드맵_아이디가_존재하지_않는_아이디일_경우_예외를_반환한다() { //when - when(roadmapRepository.findRoadmapById(anyLong())) + when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.empty()); //then @@ -190,6 +178,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 .thenReturn(Optional.of(category)); when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -239,6 +229,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 .thenReturn(Optional.of(category)); when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -276,6 +268,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -323,6 +317,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 .thenReturn(Optional.of(new RoadmapCategory("여행"))); when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -377,6 +373,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 when(roadmapRepository.findRoadmapsByCond(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -425,7 +423,7 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(member)); - when(roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest(any(), any(), anyInt())) + when(roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest(anyLong(), any(), anyInt())) .thenReturn(List.of(roadmap2, roadmap1)); // when @@ -459,64 +457,37 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 } @Test - void 로드맵의_골룸_목록을_최신순으로_조회한다() throws MalformedURLException { + void 로드맵의_골룸_목록을_최신순으로_조회한다() { // given final Member member1 = 사용자를_생성한다(1L, "identifier1", "name1"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(roadmapNode1, roadmapNode2)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); - final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, member1, - new RoadmapCategory("it")); - - final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode(new Period(TODAY, TODAY.plusDays(10)), - 1, roadmapNode1); - final GoalRoomRoadmapNode goalRoomRoadmapNode2 = new GoalRoomRoadmapNode( - new Period(TODAY.plusDays(11), TODAY.plusDays(20)), 1, roadmapNode2); - final GoalRoomRoadmapNode goalRoomRoadmapNode3 = new GoalRoomRoadmapNode(new Period(TODAY, TODAY.plusDays(10)), - 1, roadmapNode1); - final GoalRoomRoadmapNode goalRoomRoadmapNode4 = new GoalRoomRoadmapNode( - new Period(TODAY.plusDays(11), TODAY.plusDays(20)), 1, roadmapNode2); + final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, RoadmapStatus.CREATED, + member1.getId(), new RoadmapCategory("it"), new RoadmapTags(new ArrayList<>())); final Member member2 = 사용자를_생성한다(2L, "identifier2", "name2"); - final GoalRoom goalRoom1 = new GoalRoom(1L, new GoalRoomName("goalroom1"), new LimitedMemberCount(10), - roadmapContent, member2); - goalRoom1.addAllGoalRoomRoadmapNodes( - new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode1, goalRoomRoadmapNode2))); - final Member member3 = 사용자를_생성한다(3L, "identifier2", "name3"); - final GoalRoom goalRoom2 = new GoalRoom(2L, new GoalRoomName("goalroom2"), new LimitedMemberCount(10), - roadmapContent, member3); - goalRoom2.addAllGoalRoomRoadmapNodes( - new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3, goalRoomRoadmapNode4))); - - final List goalRooms = List.of(goalRoom2, goalRoom1); - given(roadmapRepository.findRoadmapById(anyLong())) - .willReturn(Optional.of(roadmap)); - given(goalRoomRepository.findGoalRoomsByRoadmapAndCond(roadmap, - RoadmapGoalRoomsOrderType.LATEST, null, 10)) - .willReturn(goalRooms); - given(fileService.generateUrl(anyString(), any())) - .willReturn(new URL("http://example.com/serverFilePath")); - - // when - final RoadmapGoalRoomResponses result = roadmapService.findRoadmapGoalRoomsByOrderType(1L, - RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10)); final RoadmapGoalRoomResponses expected = new RoadmapGoalRoomResponses(List.of( - new RoadmapGoalRoomResponse(2L, "goalroom2", GoalRoomStatus.RECRUITING, 1, 10, + new RoadmapGoalRoomResponse(2L, "goalroom2", GoalRoomStatus.RECRUITING.name(), 1, 10, LocalDateTime.now(), TODAY, TODAY.plusDays(20), new MemberResponse(member3.getId(), member3.getNickname().getValue(), "http://example.com/serverFilePath")), - new RoadmapGoalRoomResponse(1L, "goalroom1", GoalRoomStatus.RECRUITING, 1, 10, + new RoadmapGoalRoomResponse(1L, "goalroom1", GoalRoomStatus.RECRUITING.name(), 1, 10, LocalDateTime.now(), TODAY, TODAY.plusDays(20), new MemberResponse(member2.getId(), member2.getNickname().getValue(), "http://example.com/serverFilePath"))), false); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(roadmap)); + given(roadmapGoalRoomService.makeRoadmapGoalRoomResponsesByOrderType(any(), any(), any())) + .willReturn(expected); + + // when + final RoadmapGoalRoomResponses result = roadmapService.findRoadmapGoalRoomsByOrderType(1L, + RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10)); + assertThat(result) .usingRecursiveComparison() .ignoringFields("responses.createdAt") @@ -526,7 +497,7 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 @Test void 로드맵의_골룸_목록을_조회할때_존재하지_않는_로드맵이면_예외가_발생한다() { // given - given(roadmapRepository.findRoadmapById(anyLong())) + given(roadmapRepository.findById(anyLong())) .willThrow(new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = 1")); // when @@ -543,22 +514,17 @@ RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10))) // given final Member member1 = 사용자를_생성한다(1L, "identifier1", "리뷰어1"); final Member member2 = 사용자를_생성한다(2L, "identifier2", "리뷰어2"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(roadmapNode1, roadmapNode2)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); - final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, member1, - new RoadmapCategory("it")); - - final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰 내용", 5.0, member1); - final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰 내용", 4.5, member2); - roadmapReview1.updateRoadmap(roadmap); - roadmapReview2.updateRoadmap(roadmap); - - when(roadmapRepository.findRoadmapById(anyLong())).thenReturn(Optional.of(roadmap)); - when(roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest(any(), any(), anyInt())) + final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, RoadmapStatus.CREATED, + member1.getId(), new RoadmapCategory("it"), new RoadmapTags(new ArrayList<>())); + + final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰 내용", 5.0, member1.getId(), roadmap.getId()); + final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰 내용", 4.5, member2.getId(), roadmap.getId()); + + when(roadmapRepository.findById(anyLong())).thenReturn(Optional.of(roadmap)); + when(roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest(any(), any(), anyInt())) .thenReturn(List.of(roadmapReview2, roadmapReview1)); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member2), Optional.of(member1)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -582,7 +548,7 @@ RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10))) @Test void 로드맵_리뷰_조회_시_유효하지_않은_로드맵_아이디라면_예외를_반환한다() { // given - when(roadmapRepository.findRoadmapById(anyLong())) + when(roadmapRepository.findById(anyLong())) .thenThrow(new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = 1")); // when, then @@ -600,29 +566,22 @@ null, new EncryptedPassword(new Password("password1!")), } private Roadmap 로드맵을_생성한다(final String roadmapTitle, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(1L, roadmapTitle, "로드맵 소개글", 30, - RoadmapDifficulty.valueOf("DIFFICULT"), member, category); - final RoadmapTags roadmapTags = new RoadmapTags( List.of(new RoadmapTag(1L, new RoadmapTagName("태그1")), new RoadmapTag(2L, new RoadmapTagName("태그2")))); - roadmap.addTags(roadmapTags); - - final RoadmapContent roadmapContent = new RoadmapContent(1L, "로드맵 본문"); - final RoadmapNodes roadmapNodes = new RoadmapNodes( - List.of(new RoadmapNode(1L, "로드맵 노드1 제목", "로드맵 노드1 설명"))); - roadmapContent.addNodes(roadmapNodes); - roadmap.addContent(roadmapContent); - return roadmap; + return new Roadmap(1L, roadmapTitle, "로드맵 소개글", 30, + RoadmapDifficulty.valueOf("DIFFICULT"), RoadmapStatus.CREATED, member.getId(), category, roadmapTags); } private RoadmapCategory 로드맵_카테고리를_생성한다(final Long id, final String title) { return new RoadmapCategory(id, title); } - private RoadmapContent 로드맵_컨텐츠를_생성한다(final Long id, final String content) { - return new RoadmapContent(id, content); + private RoadmapContent 로드맵_컨텐츠를_생성한다(final String content, final Long roadmapId) { + final RoadmapNodes roadmapNodes = new RoadmapNodes( + List.of(new RoadmapNode(1L, "로드맵 노드1 제목", "로드맵 노드1 설명"))); + return new RoadmapContent(1L, content, roadmapId, roadmapNodes); } private List 로드맵_카테고리_리스트를_반환한다() { @@ -652,28 +611,4 @@ null, new EncryptedPassword(new Password("password1!")), return List.of(category1, category2, category3, category4, category5, category6, category7, category8, category9); } - - private List 상태별_골룸_목록을_생성한다() { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 내용"); - final GoalRoom recruitedGoalRoom1 = new GoalRoom(new GoalRoomName("모집 중 골룸 1"), - new LimitedMemberCount(20), roadmapContent, member); - final GoalRoom recruitedGoalRoom2 = new GoalRoom(new GoalRoomName("모집 중 골룸 2"), - new LimitedMemberCount(20), roadmapContent, member); - final GoalRoom runningGoalRoom1 = new GoalRoom(new GoalRoomName("진행 중 골룸 1"), - new LimitedMemberCount(20), roadmapContent, member); - final GoalRoom runningGoalRoom2 = new GoalRoom(new GoalRoomName("진행 중 골룸 2"), - new LimitedMemberCount(20), roadmapContent, member); - final GoalRoom completedGoalRoom1 = new GoalRoom(new GoalRoomName("완료된 골룸 1"), - new LimitedMemberCount(20), roadmapContent, member); - final GoalRoom completedGoalRoom2 = new GoalRoom(new GoalRoomName("완료된 골룸 2"), - new LimitedMemberCount(20), roadmapContent, member); - - runningGoalRoom1.start(); - runningGoalRoom2.start(); - completedGoalRoom1.complete(); - completedGoalRoom2.complete(); - - return List.of(recruitedGoalRoom1, recruitedGoalRoom2, runningGoalRoom1, runningGoalRoom2, - completedGoalRoom1, completedGoalRoom2); - } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java new file mode 100644 index 000000000..14e3544ff --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java @@ -0,0 +1,107 @@ +package co.kirikiri.roadmap.service; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.service.scheduler.RoadmapScheduler; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@ExtendWith(MockitoExtension.class) +class RoadmapSchedulerTest { + + private static final LocalDate TODAY = LocalDate.now(); + private static final LocalDate TEN_DAY_LATER = TODAY.plusDays(10); + + @Mock + private RoadmapRepository roadmapRepository; + + @Mock + private RoadmapGoalRoomService roadmapGoalRoomService; + + @InjectMocks + private RoadmapScheduler roadmapScheduler; + + @Test + void 삭제된_상태의_로드맵_삭제시_종료되지_않은_골룸이_있으면_삭제되지_않는다() { + // given + final Member member = new Member(new Identifier("identifier1"), + new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, + new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); + + final RoadmapCategory category = new RoadmapCategory("여행"); + final Roadmap roadmap = new Roadmap(1L, "로드맵2", "로드맵 설명2", 30, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, member.getId(), category, new RoadmapTags(new ArrayList<>())); + + given(roadmapRepository.findByStatus(any())) + .willReturn(List.of(roadmap)); + given(roadmapGoalRoomService.canDeleteGoalRoomsInRoadmap(anyLong())) + .willReturn(false); + + // when + roadmap.delete(); + + // then + assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); + verify(roadmapRepository, never()).delete(any()); + } + + @Test + void 삭제된_상태의_로드맵_삭제시_골룸이_종료된지_3개월이_지나지_않으면_삭제되지_않는다() { + // given + final Member member = new Member(new Identifier("identifier1"), + new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, + new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); + + final RoadmapCategory category = new RoadmapCategory("여행"); + final Roadmap roadmap = new Roadmap("로드맵1", "로드맵 설명1", 30, RoadmapDifficulty.DIFFICULT, member.getId(), category, new RoadmapTags(new ArrayList<>())); + + given(roadmapRepository.findByStatus(any())) + .willReturn(List.of(roadmap)); + given(roadmapGoalRoomService.canDeleteGoalRoomsInRoadmap(any())) + .willReturn(false); + + // when + roadmap.delete(); + + // then + assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); + verify(roadmapRepository, never()).delete(any()); + } + + @Test + void 삭제된_상태의_로드맵이_없는_경우_삭제되지_않는다() { + // given + given(roadmapRepository.findByStatus(any())) + .willReturn(Collections.emptyList()); + + // when + // then + assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); + verify(roadmapRepository, never()).deleteAll(any()); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomCreateServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomCreateServiceTest.java index 75f69cfb9..2d475c48e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomCreateServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomCreateServiceTest.java @@ -5,17 +5,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.common.exception.domain.ImageExtensionException; import co.kirikiri.common.exception.NotFoundException; +import co.kirikiri.common.exception.domain.ImageExtensionException; import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.service.FileService; import co.kirikiri.common.type.ImageContentType; @@ -32,16 +28,6 @@ import co.kirikiri.domain.goalroom.vo.GoalRoomTodoContent; import co.kirikiri.domain.goalroom.vo.LimitedMemberCount; import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapStatus; import co.kirikiri.member.domain.EncryptedPassword; import co.kirikiri.member.domain.Gender; import co.kirikiri.member.domain.Member; @@ -54,13 +40,28 @@ import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; import co.kirikiri.persistence.goalroom.GoalRoomToDoCheckRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import co.kirikiri.service.dto.goalroom.request.CheckFeedRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomCreateRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.service.dto.goalroom.request.GoalRoomTodoRequest; import co.kirikiri.service.dto.goalroom.response.GoalRoomToDoCheckResponse; import co.kirikiri.service.goalroom.GoalRoomCreateService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockMultipartFile; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; @@ -68,13 +69,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.mock.web.MockMultipartFile; @ExtendWith(MockitoExtension.class) class GoalRoomCreateServiceTest { @@ -83,30 +77,28 @@ class GoalRoomCreateServiceTest { private static final LocalDate TEN_DAY_LATER = TODAY.plusDays(10); private static final LocalDate TWENTY_DAY_LATER = TODAY.plusDays(20); - private static final RoadmapNode ROADMAP_NODE = new RoadmapNode(1L, "title", "content"); - private static final RoadmapContent ROADMAP_CONTENT = new RoadmapContent(1L, "content"); - private static final RoadmapContent DELETED_ROADMAP_CONTENT = new RoadmapContent(2L, "content2"); - private static final RoadmapNodes ROADMAP_CONTENTS = new RoadmapNodes(new ArrayList<>(List.of(ROADMAP_NODE))); - - private static final Member MEMBER = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password!2")), - new Nickname("name2"), null, + private static final Member MEMBER = new Member(new Identifier("identifier1"), + new EncryptedPassword(new Password("password1!")), + new Nickname("name1"), null, new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - private static final Roadmap ROADMAP = new Roadmap("roadmap", "introduction", 30, RoadmapDifficulty.DIFFICULT, - MEMBER, new RoadmapCategory("IT")); - - private static final Roadmap DELETED_ROADMAP = new Roadmap("roadmap", "introduction", 30, - RoadmapDifficulty.DIFFICULT, RoadmapStatus.DELETED, MEMBER, new RoadmapCategory("IT")); - - private static Member member; - + private static final Roadmap ROADMAP = new Roadmap(1L, "roadmap", "introduction", 30, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, MEMBER.getId(), new RoadmapCategory("IT"), new RoadmapTags(new ArrayList<>())); + private static final Roadmap DELETED_ROADMAP = new Roadmap(2L, "roadmap", "introduction", 30, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.DELETED, MEMBER.getId(), new RoadmapCategory("IT"), new RoadmapTags(new ArrayList<>())); + private static final RoadmapNode roadmapNode1 = new RoadmapNode(1L, "title1", "content1"); + private static final RoadmapNode roadmapNode2 = new RoadmapNode(2L, "title2", "content2"); + private static final RoadmapContent DELETED_ROADMAP_CONTENT = new RoadmapContent(2L, "content2", DELETED_ROADMAP.getId(), null); + private static final RoadmapContent ROADMAP_CONTENT = new RoadmapContent(1L, "content", ROADMAP.getId(), new RoadmapNodes(List.of(roadmapNode1, roadmapNode2))); @Mock private GoalRoomRepository goalRoomRepository; @Mock private GoalRoomMemberRepository goalRoomMemberRepository; + @Mock + private RoadmapRepository roadmapRepository; + @Mock private RoadmapContentRepository roadmapContentRepository; @@ -128,35 +120,24 @@ class GoalRoomCreateServiceTest { @InjectMocks private GoalRoomCreateService goalRoomCreateService; - @BeforeAll - static void setUp() { - ROADMAP_CONTENT.addNodes(ROADMAP_CONTENTS); - ROADMAP.addContent(ROADMAP_CONTENT); - DELETED_ROADMAP.addContent(DELETED_ROADMAP_CONTENT); - final Identifier identifier = new Identifier("identifier1"); - final Password password = new Password("password1!"); - final EncryptedPassword encryptedPassword = new EncryptedPassword(password); - final Nickname nickname = new Nickname("nickname"); - final String email = "kirikiri@email.com"; - final MemberProfile memberProfile = new MemberProfile(Gender.MALE, email); - member = new Member(identifier, encryptedPassword, nickname, null, memberProfile); - } - @Test void 정상적으로_골룸을_생성한다() { //given - final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", - 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)))); + final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, + List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER), + new GoalRoomRoadmapNodeRequest(2L, 5, TEN_DAY_LATER.plusDays(1), TWENTY_DAY_LATER))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(ROADMAP)); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(member)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.save(any())) .willReturn(new GoalRoom(1L, null, null, null, null)); //when - assertDoesNotThrow(() -> goalRoomCreateService.create(request, member.getIdentifier().getValue())); + assertDoesNotThrow(() -> goalRoomCreateService.create(request, MEMBER.getIdentifier().getValue())); } @Test @@ -165,12 +146,14 @@ static void setUp() { final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(DELETED_ROADMAP_CONTENT)); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(DELETED_ROADMAP)); //when //then - assertThatThrownBy(() -> goalRoomCreateService.create(request, member.getIdentifier().getValue())) + assertThatThrownBy(() -> goalRoomCreateService.create(request, MEMBER.getIdentifier().getValue())) .isInstanceOf(BadRequestException.class); } @@ -180,77 +163,80 @@ static void setUp() { final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.empty()); //when //then - assertThatThrownBy(() -> goalRoomCreateService.create(request, member.getIdentifier().getValue())) - .isInstanceOf(NotFoundException.class); + assertThatThrownBy(() -> goalRoomCreateService.create(request, MEMBER.getIdentifier().getValue())) + .isInstanceOf(NotFoundException.class) + .hasMessage("존재하지 않는 로드맵 컨텐츠입니다."); } @Test void 골룸_생성_시_로드맵_컨텐츠의_노드사이즈와_요청의_노드사이즈가_다를때_예외를_던진다() { //given - final List wrongSizeGoalRoomRoadmapNodeRequest = new ArrayList<>(List.of( - new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER), - new GoalRoomRoadmapNodeRequest(2L, 10, TODAY, TEN_DAY_LATER))); + final List wrongSizeGoalRoomRoadmapNodeRequest = List.of( + new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)); final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, wrongSizeGoalRoomRoadmapNodeRequest); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(ROADMAP)); //when //then - assertThatThrownBy(() -> goalRoomCreateService.create(request, member.getIdentifier().getValue())) + assertThatThrownBy(() -> goalRoomCreateService.create(request, MEMBER.getIdentifier().getValue())) .isInstanceOf(BadRequestException.class); } @Test void 골룸_생성_시_로드맵에_존재하지_않는_노드가_요청으로_들어올때_예외를_던진다() { //given - final long wrongRoadmapNodId = 2L; - final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", - 20, - new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(wrongRoadmapNodId, 10, TODAY, TEN_DAY_LATER)))); + final long wrongRoadmapNodId = 3L; + final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, + List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER), + new GoalRoomRoadmapNodeRequest(wrongRoadmapNodId, 5, TEN_DAY_LATER, TWENTY_DAY_LATER))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(ROADMAP)); //when //then - assertThatThrownBy(() -> goalRoomCreateService.create(request, member.getIdentifier().getValue())) + assertThatThrownBy(() -> goalRoomCreateService.create(request, MEMBER.getIdentifier().getValue())) .isInstanceOf(NotFoundException.class); } @Test void 골룸_생성_시_존재하지_않은_회원의_Identifier가_들어올때_예외를_던진다() { //given - final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", - 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)))); + final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, + List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER), + new GoalRoomRoadmapNodeRequest(2L, 5, TEN_DAY_LATER.plusDays(1), TWENTY_DAY_LATER))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(ROADMAP)); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.empty()); //when //then - assertThatThrownBy(() -> goalRoomCreateService.create(request, member.getIdentifier().getValue())) + assertThatThrownBy(() -> goalRoomCreateService.create(request, "identifier")) .isInstanceOf(NotFoundException.class); } @Test void 골룸에_참가한다() { //given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); - final Member follower = 사용자를_생성한다(2L, "identifier2", "password1!", "팔로워", "kirikiri1@email"); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final Member follower = 사용자를_생성한다(2L, "identifier2", "password2@", "팔로워", "kirikiri1@email"); when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(follower)); @@ -258,7 +244,7 @@ static void setUp() { .thenReturn(Optional.of(goalRoom)); //when - goalRoomCreateService.join("identifier2", 1L); + goalRoomCreateService.join(follower.getIdentifier().getValue(), goalRoom.getId()); //then assertThat(goalRoom.getCurrentMemberCount()) @@ -272,7 +258,7 @@ static void setUp() { .thenReturn(Optional.empty()); //when, then - assertThatThrownBy(() -> goalRoomCreateService.join("identifier2", 1L)) + assertThatThrownBy(() -> goalRoomCreateService.join("identifier", 1L)) .isInstanceOf(NotFoundException.class) .hasMessage("존재하지 않는 회원입니다."); } @@ -280,10 +266,8 @@ static void setUp() { @Test void 골룸_참가_요청시_유효한_골룸_아이디가_아니면_예외가_발생한다() { //given - final Member follower = 사용자를_생성한다(1L, "identifier1", "password1!", "팔로워", "kirikiri1@email"); - when(memberRepository.findByIdentifier(any())) - .thenReturn(Optional.of(follower)); + .thenReturn(Optional.of(MEMBER)); when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong())) .thenReturn(Optional.empty()); @@ -296,12 +280,8 @@ static void setUp() { @Test void 골룸_참가_요청시_제한_인원이_가득_찼을_경우_예외가_발생한다() { //given - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 1; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); final Member follower = 사용자를_생성한다(1L, "identifier2", "password1!", "팔로워", "kirikiri1@email"); when(memberRepository.findByIdentifier(any())) @@ -310,29 +290,28 @@ static void setUp() { .thenReturn(Optional.of(goalRoom)); //when, then - assertThatThrownBy(() -> goalRoomCreateService.join("identifier2", 1L)) + assertThatThrownBy(() -> goalRoomCreateService.join(follower.getIdentifier().getValue(), goalRoom.getId())) .isInstanceOf(GoalRoomException.class) .hasMessage("제한 인원이 꽉 찬 골룸에는 참여할 수 없습니다."); } @Test void 골룸_참가_요청시_모집_중이_아닌_경우_예외가_발생한다() { - //given - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); + // given final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); - final Member follower = 사용자를_생성한다(2L, "identifier2", "password2!", "팔로워", "kirikiri1@email"); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.start(); + final Member follower = 사용자를_생성한다(2L, "identifier2", "password2!", "팔로워", "kirikiri1@email"); + + // when when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(follower)); when(goalRoomRepository.findGoalRoomByIdWithPessimisticLock(anyLong())) .thenReturn(Optional.of(goalRoom)); - //when, then - assertThatThrownBy(() -> goalRoomCreateService.join("identifier2", 1L)) + // then + assertThatThrownBy(() -> goalRoomCreateService.join(follower.getIdentifier().getValue(), 1L)) .isInstanceOf(GoalRoomException.class) .hasMessage("모집 중이지 않은 골룸에는 참여할 수 없습니다."); } @@ -340,18 +319,14 @@ static void setUp() { @Test void 정상적으로_골룸에_투두리스트를_추가한다() { //given - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo( new GoalRoomToDo(new GoalRoomTodoContent("goalRoomTodoContent"), new Period(TODAY, TEN_DAY_LATER))); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(creator)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.of(goalRoom)); @@ -360,7 +335,7 @@ static void setUp() { //when //then - assertDoesNotThrow(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier1", goalRoomTodoRequest)); + assertDoesNotThrow(() -> goalRoomCreateService.addGoalRoomTodo(1L, MEMBER.getIdentifier().getValue(), goalRoomTodoRequest)); } @Test @@ -374,25 +349,21 @@ static void setUp() { //when //then - assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier1", goalRoomTodoRequest)) + assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier", goalRoomTodoRequest)) .isInstanceOf(NotFoundException.class); } @Test void 골룸에_투두리스트_추가시_골룸을_찾지_못할_경우_예외를_던진다() { //given - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo( new GoalRoomToDo(new GoalRoomTodoContent("goalRoomTodoContent"), new Period(TODAY, TEN_DAY_LATER))); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(creator)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.empty()); @@ -401,26 +372,22 @@ static void setUp() { //when //then - assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier1", goalRoomTodoRequest)) + assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(2L, MEMBER.getIdentifier().getValue(), goalRoomTodoRequest)) .isInstanceOf(NotFoundException.class); } @Test void 골룸에_투두리스트_추가시_종료된_골룸일_경우_예외를_던진다() { //given - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo( new GoalRoomToDo(new GoalRoomTodoContent("goalRoomTodoContent"), new Period(TODAY, TEN_DAY_LATER))); goalRoom.complete(); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(creator)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.of(goalRoom)); @@ -429,25 +396,22 @@ static void setUp() { //when //then - assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier1", goalRoomTodoRequest)) + assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, MEMBER.getIdentifier().getValue(), goalRoomTodoRequest)) .isInstanceOf(BadRequestException.class); } @Test void 골룸에_투두리스트_추가시_리더가_아닐_경우_예외를_던진다() { //given - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final Member follower = 사용자를_생성한다(2L, "identifier2", "password2@", "팔로워", "kirikiri1@email"); goalRoom.addGoalRoomTodo( new GoalRoomToDo(new GoalRoomTodoContent("goalRoomTodoContent"), new Period(TODAY, TEN_DAY_LATER))); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(member)); + .willReturn(Optional.of(follower)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.of(goalRoom)); @@ -456,25 +420,21 @@ static void setUp() { //when //then - assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier2", goalRoomTodoRequest)) + assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, follower.getIdentifier().getValue(), goalRoomTodoRequest)) .isInstanceOf(BadRequestException.class); } @Test void 골룸에_투두리스트_추가시_골룸_컨텐츠가_250글자가_넘을때_예외를_던진다() { //given - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo( new GoalRoomToDo(new GoalRoomTodoContent("goalRoomTodoContent"), new Period(TODAY, TEN_DAY_LATER))); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(creator)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.of(goalRoom)); @@ -484,27 +444,23 @@ static void setUp() { //when //then - assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, "identifier1", goalRoomTodoRequest)) + assertThatThrownBy(() -> goalRoomCreateService.addGoalRoomTodo(1L, MEMBER.getIdentifier().getValue(), goalRoomTodoRequest)) .isInstanceOf(GoalRoomException.class); } @Test void 골룸을_시작한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); when(memberRepository.findByIdentifier(any())) - .thenReturn(Optional.of(creator)); + .thenReturn(Optional.of(MEMBER)); when(goalRoomRepository.findById(any())) .thenReturn(Optional.of(goalRoom)); // when - goalRoomCreateService.startGoalRoom("cokirikiri", 1L); + goalRoomCreateService.startGoalRoom(MEMBER.getIdentifier().getValue(), 1L); // then assertThat(goalRoom.getStatus()).isEqualTo(RUNNING); @@ -524,10 +480,8 @@ static void setUp() { @Test void 골룸_시작시_존재하지_않는_골룸이면_예외가_발생한다() { // given - final Member member = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - when(memberRepository.findByIdentifier(any())) - .thenReturn(Optional.of(member)); + .thenReturn(Optional.of(MEMBER)); when(goalRoomRepository.findById(any())) .thenReturn(Optional.empty()); @@ -539,13 +493,9 @@ static void setUp() { @Test void 골룸을_시작하는_사용자가_골룸의_리더가_아니면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); final Member follower = 사용자를_생성한다(2L, "kirikirico", "password2!", "끼리코", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(follower)); @@ -553,27 +503,23 @@ static void setUp() { .thenReturn(Optional.of(goalRoom)); // expected - assertThatThrownBy(() -> goalRoomCreateService.startGoalRoom("identifier", 1L)) + assertThatThrownBy(() -> goalRoomCreateService.startGoalRoom(follower.getIdentifier().getValue(), 1L)) .isInstanceOf(BadRequestException.class); } @Test void 골룸_시작시_시작날짜가_아직_지나지_않았으면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); when(memberRepository.findByIdentifier(any())) - .thenReturn(Optional.of(creator)); + .thenReturn(Optional.of(MEMBER)); when(goalRoomRepository.findById(any())) .thenReturn(Optional.of(goalRoom)); // expected - assertThatThrownBy(() -> goalRoomCreateService.startGoalRoom("cokirikiri", 1L)) + assertThatThrownBy(() -> goalRoomCreateService.startGoalRoom(MEMBER.getIdentifier().getValue(), 1L)) .isInstanceOf(BadRequestException.class); } @@ -582,14 +528,9 @@ static void setUp() { // given final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); goalRoomMemberRepository.save(goalRoomLeader); final GoalRoomRoadmapNode goalRoomRoadmapNode = goalRoom.getGoalRoomRoadmapNodes().getValues().get(0); final CheckFeed checkFeed = 인증_피드를_생성한다(goalRoomRoadmapNode, goalRoomLeader); @@ -610,7 +551,7 @@ static void setUp() { .thenReturn(makeUrl("originalFileName.jpeg")); // when - final String response = goalRoomCreateService.createCheckFeed("identifier", 1L, request); + final String response = goalRoomCreateService.createCheckFeed(MEMBER.getIdentifier().getValue(), 1L, request); // then assertAll( @@ -622,16 +563,9 @@ static void setUp() { @Test void 인증_피드_등록시_노드_기간에_해당하지_않으면_예외가_발생한다() { // given - final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); - - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); goalRoomMemberRepository.save(goalRoomLeader); when(goalRoomRepository.findById(anyLong())) @@ -639,9 +573,12 @@ static void setUp() { when(goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier(any(), any())) .thenReturn(Optional.of(goalRoomLeader)); - // expected + // when + final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); + + // then assertThatThrownBy( - () -> goalRoomCreateService.createCheckFeed("identifier", 1L, request)) + () -> goalRoomCreateService.createCheckFeed(MEMBER.getIdentifier().getValue(), goalRoom.getId(), request)) .isInstanceOf(BadRequestException.class) .hasMessage("인증 피드는 노드 기간 내에만 작성할 수 있습니다."); } @@ -649,17 +586,11 @@ static void setUp() { @Test void 하루에_두_번_이상_인증_피드_등록_요청_시_예외를_반환한다() { // given - final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); - - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); goalRoomMemberRepository.save(goalRoomLeader); + final GoalRoomRoadmapNode goalRoomRoadmapNode = goalRoom.getGoalRoomRoadmapNodes().getValues().get(0); final CheckFeed checkFeed = 인증_피드를_생성한다(goalRoomRoadmapNode, goalRoomLeader); @@ -670,9 +601,12 @@ static void setUp() { when(checkFeedRepository.findByGoalRoomMemberAndDateTime(any(), any(), any())) .thenReturn(Optional.of(checkFeed)); - //expect + // when + final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); + + // then assertThatThrownBy( - () -> goalRoomCreateService.createCheckFeed("identifier", 1L, request)) + () -> goalRoomCreateService.createCheckFeed(MEMBER.getIdentifier().getValue(), goalRoom.getId(), request)) .isInstanceOf(BadRequestException.class) .hasMessage("이미 오늘 인증 피드를 등록하였습니다."); } @@ -680,16 +614,10 @@ static void setUp() { @Test void 골룸_노드에서_허가된_인증_횟수보다_많은_인증_피드_등록_요청_시_예외를_반환한다() { // given - final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); - - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); goalRoomMemberRepository.save(goalRoomLeader); final GoalRoomRoadmapNode goalRoomRoadmapNode = goalRoom.getGoalRoomRoadmapNodes().getValues().get(0); @@ -700,9 +628,12 @@ static void setUp() { when(checkFeedRepository.countByGoalRoomMemberAndGoalRoomRoadmapNode(any(), any())) .thenReturn(goalRoomRoadmapNode.getCheckCount()); - //expect + // when + final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); + + // then assertThatThrownBy( - () -> goalRoomCreateService.createCheckFeed("identifier", 1L, request)) + () -> goalRoomCreateService.createCheckFeed(MEMBER.getIdentifier().getValue(), goalRoom.getId(), request)) .isInstanceOf(BadRequestException.class) .hasMessage("이번 노드에는 최대 " + goalRoomRoadmapNode.getCheckCount() + "번만 인증 피드를 등록할 수 있습니다."); } @@ -710,18 +641,10 @@ static void setUp() { @Test void 인증_피드_등록_요청_시_허용되지_않는_확장자_형식이라면_예외를_반환한다() { // given - final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/gif"); - - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); goalRoomMemberRepository.save(goalRoomLeader); - final GoalRoomRoadmapNode goalRoomRoadmapNode = goalRoom.getGoalRoomRoadmapNodes().getValues().get(0); when(goalRoomRepository.findById(any())) .thenReturn(Optional.of(goalRoom)); @@ -729,8 +652,11 @@ static void setUp() { .thenReturn(Optional.of(goalRoomLeader)); // when + final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/gif"); + + // then assertThatThrownBy( - () -> goalRoomCreateService.createCheckFeed("identifier", 1L, request)) + () -> goalRoomCreateService.createCheckFeed(MEMBER.getIdentifier().getValue(), goalRoom.getId(), request)) .isInstanceOf(ImageExtensionException.class) .hasMessage("허용되지 않는 확장자입니다."); } @@ -738,23 +664,20 @@ static void setUp() { @Test void 인증_피드_등록_요청_시_존재하지_않는_골룸이라면_예외를_반환한다() { // given - final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); - - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); goalRoomMemberRepository.save(goalRoomLeader); when(goalRoomRepository.findById(any())) .thenReturn(Optional.empty()); - //expect + // when + final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); + + // then assertThatThrownBy( - () -> goalRoomCreateService.createCheckFeed("identifier", 1L, request)) + () -> goalRoomCreateService.createCheckFeed(MEMBER.getIdentifier().getValue(), goalRoom.getId(), request)) .isInstanceOf(NotFoundException.class) .hasMessage("존재하지 않는 골룸입니다. goalRoomId = 1"); } @@ -762,16 +685,9 @@ static void setUp() { @Test void 인증_피드_등록_요청_시_사용자가_참여하지_않은_골룸이라면_예외를_반환한다() { // given - final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); - - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); - - final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); + final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); goalRoomMemberRepository.save(goalRoomLeader); when(goalRoomRepository.findById(any())) @@ -779,9 +695,12 @@ static void setUp() { when(goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier(any(), any())) .thenReturn(Optional.empty()); - //expect + // when + final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); + + // then assertThatThrownBy( - () -> goalRoomCreateService.createCheckFeed("identifier", 1L, request)) + () -> goalRoomCreateService.createCheckFeed("identifier", goalRoom.getId(), request)) .isInstanceOf(NotFoundException.class) .hasMessage("골룸에 해당 사용자가 존재하지 않습니다. 사용자 아이디 = " + "identifier"); } @@ -789,29 +708,21 @@ static void setUp() { @Test void 투두리스트를_체크한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo(new GoalRoomToDo( - 1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TODAY.plusDays(3)) - )); - final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + 1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TODAY.plusDays(3)))); + final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); when(goalRoomRepository.findByIdWithTodos(anyLong())) .thenReturn(Optional.of(goalRoom)); - when(goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier(any(), any())) .thenReturn(Optional.of(goalRoomMember)); - when(goalRoomToDoCheckRepository.findByGoalRoomIdAndTodoAndMemberIdentifier(any(), any(), any())) .thenReturn(Optional.empty()); // when - final GoalRoomToDoCheckResponse checkResponse = goalRoomCreateService.checkGoalRoomTodo(1L, 1L, "cokirikiri"); + final GoalRoomToDoCheckResponse checkResponse = goalRoomCreateService.checkGoalRoomTodo(goalRoom.getId(), 1L, MEMBER.getIdentifier().getValue()); // then assertThat(checkResponse) @@ -821,31 +732,24 @@ static void setUp() { @Test void 투두리스트_체크시_체크_이력이_있으면_제거한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); final GoalRoomToDo goalRoomToDo = new GoalRoomToDo( 1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TODAY.plusDays(3))); goalRoom.addGoalRoomTodo(goalRoomToDo); - final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, - creator); + final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, MEMBER); final GoalRoomToDoCheck goalRoomToDoCheck = new GoalRoomToDoCheck(goalRoomMember, goalRoomToDo); when(goalRoomRepository.findByIdWithTodos(anyLong())) .thenReturn(Optional.of(goalRoom)); - when(goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier(any(), any())) .thenReturn(Optional.of(goalRoomMember)); - when(goalRoomToDoCheckRepository.findByGoalRoomIdAndTodoAndMemberIdentifier(any(), any(), any())) .thenReturn(Optional.of(goalRoomToDoCheck)); // when - final GoalRoomToDoCheckResponse checkResponse = goalRoomCreateService.checkGoalRoomTodo(1L, 1L, "cokirikiri"); + final GoalRoomToDoCheckResponse checkResponse = goalRoomCreateService.checkGoalRoomTodo(goalRoom.getId(), 1L, MEMBER.getIdentifier().getValue()); // then assertThat(checkResponse) @@ -867,12 +771,8 @@ static void setUp() { @Test void 투두리스트_체크시_해당_투두가_존재하지_않으면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo(new GoalRoomToDo( 1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TODAY.plusDays(3)))); @@ -880,7 +780,7 @@ static void setUp() { .thenReturn(Optional.of(goalRoom)); // expected - assertThatThrownBy(() -> goalRoomCreateService.checkGoalRoomTodo(1L, 2L, "cokirikiri")) + assertThatThrownBy(() -> goalRoomCreateService.checkGoalRoomTodo(goalRoom.getId(), 2L, MEMBER.getIdentifier().getValue())) .isInstanceOf(NotFoundException.class) .hasMessage("존재하지 않는 투두입니다. todoId = 2"); } @@ -888,23 +788,18 @@ static void setUp() { @Test void 투두리스트_체크시_골룸에_사용자가_없으면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final int limitedMemberCount = 10; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); goalRoom.addGoalRoomTodo(new GoalRoomToDo( 1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TODAY.plusDays(3)))); when(goalRoomRepository.findByIdWithTodos(anyLong())) .thenReturn(Optional.of(goalRoom)); - when(goalRoomMemberRepository.findByGoalRoomAndMemberIdentifier(any(), any())) .thenReturn(Optional.empty()); // expected - assertThatThrownBy(() -> goalRoomCreateService.checkGoalRoomTodo(1L, 1L, "cokirikiri")) + assertThatThrownBy(() -> goalRoomCreateService.checkGoalRoomTodo(goalRoom.getId(), 1L, "cokirikiri")) .isInstanceOf(NotFoundException.class) .hasMessage("골룸에 사용자가 존재하지 않습니다. goalRoomId = 1 memberIdentifier = cokirikiri"); } @@ -912,8 +807,8 @@ static void setUp() { @Test void 골룸을_나간다() { // given - final GoalRoom goalRoom = new GoalRoom(1L, new GoalRoomName("골룸"), new LimitedMemberCount(3), - new RoadmapContent("content"), MEMBER); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(MEMBER)); @@ -922,7 +817,7 @@ static void setUp() { // when // then - assertDoesNotThrow(() -> goalRoomCreateService.leave("identifier2", 1L)); + assertDoesNotThrow(() -> goalRoomCreateService.leave(MEMBER.getIdentifier().getValue(), goalRoom.getId())); } @@ -942,24 +837,24 @@ static void setUp() { void 골룸을_나갈때_존재하지_않는_골룸일_경우_예외가_발생한다() { // given given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(member)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.empty()); // when // then - assertThatThrownBy(() -> goalRoomCreateService.leave("identifier2", 1L)) + assertThatThrownBy(() -> goalRoomCreateService.leave(MEMBER.getIdentifier().getValue(), 1L)) .isInstanceOf(NotFoundException.class); } @Test void 골룸을_나갈때_골룸이_진행중이면_예외가_발생한다() { // given - final GoalRoom goalRoom = new GoalRoom(1L, new GoalRoomName("골룸"), new LimitedMemberCount(3), - new RoadmapContent("content"), MEMBER); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(member)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.of(goalRoom)); @@ -967,23 +862,23 @@ static void setUp() { goalRoom.start(); // then - assertThatThrownBy(() -> goalRoomCreateService.leave("identifier2", 1L)) + assertThatThrownBy(() -> goalRoomCreateService.leave(MEMBER.getIdentifier().getValue(), goalRoom.getId())) .isInstanceOf(BadRequestException.class); } @Test void 골룸을_나갈때_골룸에_남아있는_사용자가_없으면_골룸이_삭제된다() { // given - final GoalRoom goalRoom = new GoalRoom(1L, new GoalRoomName("골룸"), new LimitedMemberCount(3), - new RoadmapContent("content"), MEMBER); + final int limitedMemberCount = 20; + final GoalRoom goalRoom = 골룸을_생성한다(1L, MEMBER, ROADMAP_CONTENT, limitedMemberCount); given(memberRepository.findByIdentifier(any())) - .willReturn(Optional.of(member)); + .willReturn(Optional.of(MEMBER)); given(goalRoomRepository.findById(anyLong())) .willReturn(Optional.of(goalRoom)); // when - goalRoomCreateService.leave("identifier2", 1L); + goalRoomCreateService.leave(MEMBER.getIdentifier().getValue(), goalRoom.getId()); // then verify(goalRoomRepository, times(1)).delete(goalRoom); @@ -992,40 +887,10 @@ static void setUp() { private Member 사용자를_생성한다(final Long memberId, final String identifier, final String password, final String nickname, final String email) { final MemberProfile memberProfile = new MemberProfile(Gender.MALE, email); - return new Member(memberId, new Identifier(identifier), null, new EncryptedPassword(new Password(password)), new Nickname(nickname), null, memberProfile); } - private Roadmap 로드맵을_생성한다(final Member creator) { - final RoadmapCategory category = new RoadmapCategory("게임"); - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmap; - } - - private List 로드맵_노드들을_생성한다() { - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - return List.of(roadmapNode1, roadmapNode2); - } - - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - - private List 노드_이미지들을_생성한다() { - return List.of( - new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), - new RoadmapNodeImage("node-image2.png", "node-image2-save-path", ImageContentType.PNG) - ); - } - private GoalRoom 골룸을_생성한다(final Long goalRoomId, final Member creator, final RoadmapContent roadmapContent, final Integer limitedMemberCount) { final GoalRoom goalRoom = new GoalRoom(goalRoomId, new GoalRoomName("골룸 이름"), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomReadServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomReadServiceTest.java index 015bb7194..b3102041c 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomReadServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomReadServiceTest.java @@ -2,13 +2,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; @@ -27,15 +23,6 @@ import co.kirikiri.domain.goalroom.vo.GoalRoomTodoContent; import co.kirikiri.domain.goalroom.vo.LimitedMemberCount; import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.member.domain.EncryptedPassword; import co.kirikiri.member.domain.Gender; import co.kirikiri.member.domain.Member; @@ -51,6 +38,16 @@ import co.kirikiri.persistence.goalroom.GoalRoomPendingMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; import co.kirikiri.persistence.goalroom.GoalRoomToDoCheckRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; import co.kirikiri.service.dto.goalroom.GoalRoomMemberSortTypeDto; import co.kirikiri.service.dto.goalroom.request.GoalRoomStatusTypeRequest; import co.kirikiri.service.dto.goalroom.response.CheckFeedResponse; @@ -66,18 +63,19 @@ import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomForListResponse; import co.kirikiri.service.dto.goalroom.response.MemberGoalRoomResponse; import co.kirikiri.service.goalroom.GoalRoomReadService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) class GoalRoomReadServiceTest { @@ -111,15 +109,28 @@ class GoalRoomReadServiceTest { @InjectMocks private GoalRoomReadService goalRoomReadService; + private static GoalRoomResponse 예상하는_골룸_응답을_생성한다() { + final List goalRoomNodeResponses = List.of( + new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(1L, "로드맵 1주차", TODAY, TEN_DAY_LATER, 10), + new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(2L, "로드맵 2주차", TWENTY_DAY_LAYER, THIRTY_DAY_LATER, 2)); + return new GoalRoomResponse("골룸", 1, 10, goalRoomNodeResponses, 31); + } + + private static GoalRoomCertifiedResponse 예상하는_로그인된_사용자의_골룸_응답을_생성한다(final Boolean isJoined, + final int currentMemberCount) { + final List goalRoomNodeResponses = List.of( + new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(1L, "로드맵 1주차", TODAY, TEN_DAY_LATER, 10), + new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(2L, "로드맵 2주차", TWENTY_DAY_LAYER, THIRTY_DAY_LATER, 2)); + return new GoalRoomCertifiedResponse("골룸", currentMemberCount, 10, goalRoomNodeResponses, 31, isJoined); + } + @Test void 골룸_아이디로_골룸_정보를_조회한다() { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); when(goalRoomRepository.findByIdWithRoadmapContent(any())) .thenReturn(Optional.of(goalRoom)); @@ -149,10 +160,8 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(GoalRoomRole.LEADER, LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, creator); @@ -177,10 +186,8 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); when(goalRoomRepository.findByIdWithRoadmapContent(any())) .thenReturn(Optional.of(goalRoom)); @@ -202,10 +209,8 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, @@ -231,10 +236,8 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); when(goalRoomRepository.findByIdWithRoadmapContent(any())) @@ -266,17 +269,16 @@ class GoalRoomReadServiceTest { @Test void 정상적으로_진행중인_골룸의_참여자를_조회한다() throws MalformedURLException { //given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Member follower = 사용자를_생성한다(2L); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); final GoalRoomMember goalRoomMemberCreator = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); - final GoalRoomMember goalRoomMemberFollower = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), + final GoalRoomMember goalRoomMemberFollower = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower); given(goalRoomRepository.findById(anyLong())) @@ -291,7 +293,7 @@ class GoalRoomReadServiceTest { GoalRoomMemberSortTypeDto.ACCOMPLISHMENT_RATE); //then - final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "name1", + final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "코끼리", "http://example.com/serverFilePath", 0.0); final GoalRoomMemberResponse expectedGoalRoomMemberResponse2 = new GoalRoomMemberResponse(2L, "name1", "http://example.com/serverFilePath", 0.0); @@ -303,17 +305,16 @@ class GoalRoomReadServiceTest { @Test void 정상적으로_완료된_골룸의_참여자를_조회한다() throws MalformedURLException { //given - final Member creator = 사용자를_생성한다(1L); final Member follower = 사용자를_생성한다(2L); - + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.complete(); final GoalRoomMember goalRoomMemberCreator = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); - final GoalRoomMember goalRoomMemberFollower = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), + final GoalRoomMember goalRoomMemberFollower = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower); given(goalRoomRepository.findById(anyLong())) @@ -328,7 +329,7 @@ class GoalRoomReadServiceTest { GoalRoomMemberSortTypeDto.ACCOMPLISHMENT_RATE); //then - final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "name1", + final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "코끼리", "http://example.com/serverFilePath", 0.0); final GoalRoomMemberResponse expectedGoalRoomMemberResponse2 = new GoalRoomMemberResponse(2L, "name1", "http://example.com/serverFilePath", 0.0); @@ -342,14 +343,13 @@ class GoalRoomReadServiceTest { //given final Member creator = 사용자를_생성한다(1L); final Member follower = 사용자를_생성한다(2L); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomPendingMember goalRoomMemberCreator = new GoalRoomPendingMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); - final GoalRoomPendingMember goalRoomMemberFollower = new GoalRoomPendingMember(GoalRoomRole.LEADER, + final GoalRoomPendingMember goalRoomMemberFollower = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower); given(goalRoomRepository.findById(anyLong())) @@ -389,9 +389,10 @@ class GoalRoomReadServiceTest { @Test void 골룸의_전체_투두리스트를_조회한다() { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomToDo firstGoalRoomTodo = new GoalRoomToDo(1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TEN_DAY_LATER)); @@ -437,9 +438,10 @@ class GoalRoomReadServiceTest { @Test void 골룸의_투두리스트_조회시_골룸에_참여하지_않은_사용자면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomToDo firstGoalRoomTodo = new GoalRoomToDo(1L, new GoalRoomTodoContent("투두 1"), new Period(TODAY, TEN_DAY_LATER)); @@ -467,8 +469,7 @@ class GoalRoomReadServiceTest { final RoadmapNode roadmapNode4 = new RoadmapNode("로드맵 4주차", "로드맵 4주차 내용"); final RoadmapNodes roadmapNodes = new RoadmapNodes( List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, roadmapNodes); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode( new Period(TODAY, TODAY.plusDays(10)), 5, roadmapNode1); @@ -533,8 +534,7 @@ class GoalRoomReadServiceTest { final RoadmapNode roadmapNode4 = new RoadmapNode("로드맵 4주차", "로드맵 4주차 내용"); final RoadmapNodes roadmapNodes = new RoadmapNodes( List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, roadmapNodes); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode( new Period(TODAY, TODAY.plusDays(10)), 5, roadmapNode1); @@ -586,8 +586,7 @@ class GoalRoomReadServiceTest { final RoadmapNode roadmapNode4 = new RoadmapNode("로드맵 4주차", "로드맵 4주차 내용"); final RoadmapNodes roadmapNodes = new RoadmapNodes( List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, roadmapNodes); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode( new Period(TODAY, TODAY.plusDays(10)), 5, roadmapNode1); @@ -665,10 +664,8 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); when(goalRoomRepository.findByIdWithContentAndTodos(anyLong())) .thenReturn(Optional.of(goalRoom)); @@ -687,10 +684,8 @@ class GoalRoomReadServiceTest { final Member creator = 크리에이터를_생성한다(); final Member member = 사용자를_생성한다(2L); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); when(goalRoomRepository.findByIdWithContentAndTodos(anyLong())) .thenReturn(Optional.of(goalRoom)); @@ -708,13 +703,12 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(creator, targetRoadmapContent); - 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom3 = 골룸을_생성한다(creator, targetRoadmapContent); - 골룸을_생성한다(creator, targetRoadmapContent); + final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); + 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); + 골룸을_생성한다(creator, roadmapContent); final Member member = 사용자를_생성한다(2L); goalRoom1.join(member); @@ -750,15 +744,15 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 사용자_골룸_목룩_조회_중_참여한_골룸이없으면_빈_리스트를_반환한다() { // given - final Member creator = 크리에이터를_생성한다(); + final Member member = 사용자를_생성한다(1L); when(memberRepository.findByIdentifier(any())) - .thenReturn(Optional.of(creator)); + .thenReturn(Optional.of(member)); when(goalRoomRepository.findByMember(any())) .thenReturn(Collections.emptyList()); // when - final List response = goalRoomReadService.findMemberGoalRooms("identifier1"); + final List response = goalRoomReadService.findMemberGoalRooms(member.getIdentifier().getValue()); // then assertThat(response).isEmpty(); @@ -768,13 +762,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV void 사용자_골룸_목록_중_모집_중인_상태만_조회한다() throws MalformedURLException { final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom2 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom3 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom4 = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom2 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom4 = 골룸을_생성한다(creator, roadmapContent); final Member member = 사용자를_생성한다(2L); goalRoom1.join(member); @@ -818,13 +810,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV void 사용자_골룸_목록_중_진행_중인_상태만_조회한다() throws MalformedURLException { final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom2 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom3 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom4 = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom2 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom4 = 골룸을_생성한다(creator, roadmapContent); final Member member = 사용자를_생성한다(2L); goalRoom1.join(member); @@ -875,13 +865,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV void 사용자_골룸_목록_중_종료된_상태만_조회한다() throws MalformedURLException { final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom2 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom3 = 골룸을_생성한다(creator, targetRoadmapContent); - final GoalRoom goalRoom4 = 골룸을_생성한다(creator, targetRoadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom2 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); + final GoalRoom goalRoom4 = 골룸을_생성한다(creator, roadmapContent); final Member member = 사용자를_생성한다(2L); goalRoom1.join(member); @@ -931,9 +919,10 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 골룸의_전체_노드를_조회한다() throws MalformedURLException { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); @@ -963,9 +952,10 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 골룸의_노드_조회시_골룸에_참여하지_않은_사용자면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); when(goalRoomRepository.findByIdWithNodes(1L)) .thenReturn(Optional.of(goalRoom)); @@ -991,12 +981,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 진행중인_골룸의_인증피드를_전체_조회한다() throws MalformedURLException { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Member follower = 사용자를_생성한다(2L); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, @@ -1026,11 +1015,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV // then final GoalRoomCheckFeedResponse goalRoomCheckFeedResponse1 = new GoalRoomCheckFeedResponse( - new MemberResponse(1L, "name1", "http://example.com/serverFilePath"), - new co.kirikiri.service.dto.goalroom.response.CheckFeedResponse(1L, "http://example.com/serverFilePath", "description1", LocalDate.now())); + new MemberResponse(1L, "코끼리", "http://example.com/serverFilePath"), + new CheckFeedResponse(1L, "http://example.com/serverFilePath", "description1", LocalDate.now())); final GoalRoomCheckFeedResponse goalRoomCheckFeedResponse2 = new GoalRoomCheckFeedResponse( - new MemberResponse(1L, "name1", "http://example.com/serverFilePath"), - new co.kirikiri.service.dto.goalroom.response.CheckFeedResponse(2L, "http://example.com/serverFilePath", "description2", LocalDate.now())); + new MemberResponse(1L, "코끼리", "http://example.com/serverFilePath"), + new CheckFeedResponse(2L, "http://example.com/serverFilePath", "description2", LocalDate.now())); final GoalRoomCheckFeedResponse goalRoomCheckFeedResponse3 = new GoalRoomCheckFeedResponse( new MemberResponse(2L, "name1", "http://example.com/serverFilePath"), new co.kirikiri.service.dto.goalroom.response.CheckFeedResponse(3L, "http://example.com/serverFilePath", "description3", LocalDate.now())); @@ -1045,11 +1034,10 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 모집중인_골룸의_인증피드를_조회시_빈_값을_반환한다() { // given - final Member creator = 사용자를_생성한다(1L); - + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); @@ -1070,13 +1058,13 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 종료된_골룸의_인증피드를_전체_조회시_모든_기간의_인증피드를_대상으로_반환한다() throws MalformedURLException { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Member follower = 사용자를_생성한다(2L); - final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.complete(); + final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -1104,11 +1092,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV // then final GoalRoomCheckFeedResponse goalRoomCheckFeedResponse1 = new GoalRoomCheckFeedResponse( - new MemberResponse(1L, "name1", "http://example.com/serverFilePath"), - new co.kirikiri.service.dto.goalroom.response.CheckFeedResponse(1L, "http://example.com/serverFilePath", "description1", LocalDate.now())); + new MemberResponse(1L, "코끼리", "http://example.com/serverFilePath"), + new CheckFeedResponse(1L, "http://example.com/serverFilePath", "description1", LocalDate.now())); final GoalRoomCheckFeedResponse goalRoomCheckFeedResponse2 = new GoalRoomCheckFeedResponse( - new MemberResponse(1L, "name1", "http://example.com/serverFilePath"), - new co.kirikiri.service.dto.goalroom.response.CheckFeedResponse(2L, "http://example.com/serverFilePath", "description2", LocalDate.now())); + new MemberResponse(1L, "코끼리", "http://example.com/serverFilePath"), + new CheckFeedResponse(2L, "http://example.com/serverFilePath", "description2", LocalDate.now())); final GoalRoomCheckFeedResponse goalRoomCheckFeedResponse3 = new GoalRoomCheckFeedResponse( new MemberResponse(2L, "name1", "http://example.com/serverFilePath"), new co.kirikiri.service.dto.goalroom.response.CheckFeedResponse(3L, "http://example.com/serverFilePath", "description3", LocalDate.now())); @@ -1123,12 +1111,12 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 골룸의_인증피드를_전체_조회시_현재_진행중인_노드가_없으면_빈_리스트를_반환한다() { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Member follower = 사용자를_생성한다(2L); - final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 진행중인_노드가_없는_골룸을_생성한다(creator, roadmapContent); - final GoalRoom goalRoom = 진행중인_노드가_없는_골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -1166,11 +1154,10 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 골룸의_인증피드를_전체_조회할_때_골룸에_참여하지_않은_회원이면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L); - + final Member creator = 크리에이터를_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); given(goalRoomRepository.findByIdWithNodes(anyLong())) .willReturn(Optional.of(goalRoom)); @@ -1200,11 +1187,13 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("name1"), private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); + return new Roadmap(1L, "로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, + RoadmapStatus.CREATED, creator.getId(), category, new RoadmapTags(new ArrayList<>())); + } + + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId) { final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmap; + return new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); } private List 로드맵_노드들을_생성한다() { @@ -1214,12 +1203,6 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("name1"), return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), @@ -1265,21 +1248,6 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("name1"), return goalRoom; } - private static GoalRoomResponse 예상하는_골룸_응답을_생성한다() { - final List goalRoomNodeResponses = List.of( - new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(1L, "로드맵 1주차", TODAY, TEN_DAY_LATER, 10), - new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(2L, "로드맵 2주차", TWENTY_DAY_LAYER, THIRTY_DAY_LATER, 2)); - return new GoalRoomResponse("골룸", 1, 10, goalRoomNodeResponses, 31); - } - - private static GoalRoomCertifiedResponse 예상하는_로그인된_사용자의_골룸_응답을_생성한다(final Boolean isJoined, - final int currentMemberCount) { - final List goalRoomNodeResponses = List.of( - new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(1L, "로드맵 1주차", TODAY, TEN_DAY_LATER, 10), - new co.kirikiri.service.dto.goalroom.response.GoalRoomRoadmapNodeResponse(2L, "로드맵 2주차", TWENTY_DAY_LAYER, THIRTY_DAY_LATER, 2)); - return new GoalRoomCertifiedResponse("골룸", currentMemberCount, 10, goalRoomNodeResponses, 31, isJoined); - } - private CheckFeed 인증피드를_생성한다(final String serverFilePath, final String description, final GoalRoomRoadmapNode goalRoomRoadmapNode, final GoalRoomMember goalRoomMember) { return new CheckFeed(serverFilePath, ImageContentType.PNG, "fileName", description, goalRoomRoadmapNode, diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomSchedulerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomSchedulerTest.java index 6d3366e83..8311fc144 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomSchedulerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/service/GoalRoomSchedulerTest.java @@ -5,9 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import co.kirikiri.common.type.ImageContentType; import co.kirikiri.domain.goalroom.GoalRoom; @@ -25,28 +23,29 @@ import co.kirikiri.member.domain.vo.Identifier; import co.kirikiri.member.domain.vo.Nickname; import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.persistence.goalroom.GoalRoomMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomPendingMemberRepository; import co.kirikiri.persistence.goalroom.GoalRoomRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; import co.kirikiri.service.scheduler.GoalRoomScheduler; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; @ExtendWith(MockitoExtension.class) class GoalRoomSchedulerTest { @@ -58,12 +57,12 @@ class GoalRoomSchedulerTest { @Mock private GoalRoomRepository goalRoomRepository; - @Mock - private GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; - @Mock private GoalRoomMemberRepository goalRoomMemberRepository; + @Mock + private GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; + @InjectMocks private GoalRoomScheduler goalRoomScheduler; @@ -72,11 +71,10 @@ class GoalRoomSchedulerTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "010-1234-5678"); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); - final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, targetRoadmapContent, 10); + final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, roadmapContent, 10); + final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, roadmapContent, 10); final Member follower1 = 사용자를_생성한다(2L, "identifier1", "password2!", "name1", "kirikiri@email.com"); final Member follower2 = 사용자를_생성한다(3L, "identifier2", "password3!", "name2", "kirikiri@email.com"); @@ -108,11 +106,10 @@ class GoalRoomSchedulerTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri@email.com"); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); - final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, targetRoadmapContent, 10); + final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, roadmapContent, 10); + final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, roadmapContent, 10); final Member follower1 = 사용자를_생성한다(2L, "identifier1", "password2!", "name1", "kirikiri@email.com"); final Member follower2 = 사용자를_생성한다(3L, "identifier2", "password3!", "name2", "kirikiri@email.com"); @@ -147,11 +144,13 @@ class GoalRoomSchedulerTest { private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); + return new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, + creator.getId(), category, new RoadmapTags(new ArrayList<>())); + } + + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId) { final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmap; + return new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); } private List 로드맵_노드들을_생성한다() { @@ -161,12 +160,6 @@ class GoalRoomSchedulerTest { return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java deleted file mode 100644 index cebdc55be..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java +++ /dev/null @@ -1,173 +0,0 @@ -package co.kirikiri.service; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -import co.kirikiri.domain.goalroom.GoalRoom; -import co.kirikiri.domain.goalroom.GoalRoomRoadmapNode; -import co.kirikiri.domain.goalroom.GoalRoomRoadmapNodes; -import co.kirikiri.domain.goalroom.vo.GoalRoomName; -import co.kirikiri.domain.goalroom.vo.LimitedMemberCount; -import co.kirikiri.domain.goalroom.vo.Period; -import co.kirikiri.member.domain.EncryptedPassword; -import co.kirikiri.member.domain.Gender; -import co.kirikiri.member.domain.Member; -import co.kirikiri.member.domain.MemberProfile; -import co.kirikiri.member.domain.vo.Identifier; -import co.kirikiri.member.domain.vo.Nickname; -import co.kirikiri.member.domain.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.persistence.goalroom.GoalRoomRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.service.scheduler.RoadmapScheduler; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import java.time.LocalDate; -import java.util.Collections; -import java.util.List; - -@ExtendWith(MockitoExtension.class) -class RoadmapSchedulerTest { - - private static final LocalDate TODAY = LocalDate.now(); - private static final LocalDate TEN_DAY_LATER = TODAY.plusDays(10); - - @Mock - private RoadmapRepository roadmapRepository; - - @Mock - private GoalRoomRepository goalRoomRepository; - - @InjectMocks - private RoadmapScheduler roadmapScheduler; - - @Test - void 삭제된_상태의_로드맵_삭제시_종료되지_않은_골룸이_있으면_삭제되지_않는다() { - // given - final Member member1 = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - final Member member2 = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password2!")), new Nickname("name2"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - - final RoadmapCategory category = new RoadmapCategory("여행"); - final RoadmapContent roadmapContent1_1 = new RoadmapContent("로드맵 본문2"); - final RoadmapContent roadmapContent1_2 = new RoadmapContent("로드맵 본문2 - 수정본"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵1 노드", "로드맵 노드 내용"); - roadmapContent1_1.addNodes(new RoadmapNodes(List.of(roadmapNode1))); - roadmapContent1_2.addNodes(new RoadmapNodes(List.of(roadmapNode1))); - final Roadmap roadmap1 = new Roadmap("로드맵2", "로드맵 설명2", 30, RoadmapDifficulty.DIFFICULT, member1, category); - roadmap1.addContent(roadmapContent1_1); - roadmap1.addContent(roadmapContent1_2); - - final GoalRoom goalRoom1_1 = new GoalRoom(new GoalRoomName("골룸2"), new LimitedMemberCount(10), - roadmapContent1_1, member2); - final GoalRoom goalRoom1_2 = new GoalRoom(new GoalRoomName("골룸2-1"), new LimitedMemberCount(10), - roadmapContent1_2, member2); - - final GoalRoomRoadmapNodes goalRoomRoadmapNodes1 = new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, roadmapNode1))); - goalRoom1_1.addAllGoalRoomRoadmapNodes(goalRoomRoadmapNodes1); - goalRoom1_2.addAllGoalRoomRoadmapNodes(goalRoomRoadmapNodes1); - - given(roadmapRepository.findWithRoadmapContentByStatus(any())) - .willReturn(List.of(roadmap1)); - given(goalRoomRepository.findByRoadmap(roadmap1)) - .willReturn(List.of(goalRoom1_1, goalRoom1_2)); - - // when - roadmap1.delete(); - goalRoom1_1.complete(); - - // then - assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); - verify(goalRoomRepository, never()).deleteAll(any()); - verify(roadmapRepository, never()).delete(any()); - } - - @Test - void 삭제된_상태의_로드맵_삭제시_골룸이_종료된지_3개월이_지나지_않으면_삭제되지_않는다() { - // given - final Member member1 = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - final Member member2 = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password2!")), new Nickname("name2"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - - final RoadmapCategory category = new RoadmapCategory("여행"); - final RoadmapContent roadmapContent1 = new RoadmapContent("로드맵 본문1"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵1 노드", "로드맵 노드 내용"); - roadmapContent1.addNodes(new RoadmapNodes(List.of(roadmapNode1))); - - final Roadmap roadmap1 = new Roadmap("로드맵1", "로드맵 설명1", 30, RoadmapDifficulty.DIFFICULT, member1, category); - roadmap1.addContent(roadmapContent1); - - final GoalRoom goalRoom1 = new GoalRoom(new GoalRoomName("골룸1"), new LimitedMemberCount(10), roadmapContent1, - member2); - final GoalRoomRoadmapNodes goalRoomRoadmapNodes1 = new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, roadmapNode1))); - goalRoom1.addAllGoalRoomRoadmapNodes(goalRoomRoadmapNodes1); - - given(roadmapRepository.findWithRoadmapContentByStatus(any())) - .willReturn(List.of(roadmap1)); - given(goalRoomRepository.findByRoadmap(roadmap1)) - .willReturn(List.of(goalRoom1)); - - // when - roadmap1.delete(); - goalRoom1.complete(); - - // then - assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); - verify(goalRoomRepository, never()).deleteAll(any()); - verify(roadmapRepository, never()).delete(any()); - } - - @Test - void 삭제된_상태의_로드맵이_없는_경우_삭제되지_않는다() { - // given - final Member member1 = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - final Member member2 = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password2!")), new Nickname("name2"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - - final RoadmapCategory category = new RoadmapCategory("여행"); - final RoadmapContent roadmapContent1 = new RoadmapContent("로드맵 본문1"); - final RoadmapNode roadmapNode = new RoadmapNode("로드맵 노드", "로드맵 노드 내용"); - final Roadmap roadmap1 = new Roadmap("로드맵1", "로드맵 설명1", 30, RoadmapDifficulty.DIFFICULT, member1, category); - roadmapContent1.addNodes(new RoadmapNodes(List.of(roadmapNode))); - roadmap1.addContent(roadmapContent1); - - final GoalRoom goalRoom1 = new GoalRoom(new GoalRoomName("골룸1"), new LimitedMemberCount(10), roadmapContent1, - member2); - - final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, roadmapNode))); - goalRoom1.addAllGoalRoomRoadmapNodes(goalRoomRoadmapNodes); - goalRoom1.complete(); - - given(roadmapRepository.findWithRoadmapContentByStatus(any())) - .willReturn(Collections.emptyList()); - - // when - // then - assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); - verify(goalRoomRepository, never()).findByRoadmap(any()); - verify(roadmapRepository, never()).deleteAll(any()); - } -}