From b6df169ec4c3c295f4cd9b79009427c905e210fd Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 14:52:44 +0900 Subject: [PATCH 1/9] =?UTF-8?q?docs=20:=20=EB=AA=A8=EC=9E=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20Docs=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/space/group.adoc | 13 +++++++++++++ .../domain/space/controller/GroupController.java | 16 ++++++++-------- .../docs/space/GroupControllerDocsTest.java | 10 +++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/docs/asciidoc/api/space/group.adoc b/src/docs/asciidoc/api/space/group.adoc index 06e61c0..8c9a12b 100644 --- a/src/docs/asciidoc/api/space/group.adoc +++ b/src/docs/asciidoc/api/space/group.adoc @@ -52,6 +52,19 @@ include::{snippets}/participation-exit/form-parameters.adoc[] include::{snippets}/participation-exit/http-response.adoc[] include::{snippets}/participation-exit/response-fields.adoc[] +=== 모임 삭제 API + +==== HTTP Request Header +include::{snippets}/group-delete/request-headers.adoc[] + +==== HTTP Request FormParameter +include::{snippets}/group-delete/form-parameters.adoc[] +include::{snippets}/group-delete/http-request.adoc[] + +==== HTTP Response body +include::{snippets}/group-delete/http-response.adoc[] +include::{snippets}/group-delete/response-fields.adoc[] + === 모임원 내보내기 API ==== HTTP Request Headers diff --git a/src/main/java/com/moim/backend/domain/space/controller/GroupController.java b/src/main/java/com/moim/backend/domain/space/controller/GroupController.java index 946f11e..446e27f 100644 --- a/src/main/java/com/moim/backend/domain/space/controller/GroupController.java +++ b/src/main/java/com/moim/backend/domain/space/controller/GroupController.java @@ -20,7 +20,7 @@ public class GroupController { private final GroupService groupService; - // 모임 생성하기 + // 모임 생성 API @PostMapping("") public CustomResponseEntity createGroup( @RequestBody @Valid GroupRequest.Create request, @Login Users user @@ -34,7 +34,7 @@ public CustomResponseEntity readParticipateGroupByRegion(@ return CustomResponseEntity.success(groupService.readParticipateGroupByRegion(groupId)); } - // 모임 참여하기 + // 모임 참여 API @PostMapping("/participate") public CustomResponseEntity participateGroup( @RequestBody @Valid GroupRequest.Participate request, @Login Users user @@ -42,7 +42,7 @@ public CustomResponseEntity participateGroup( return CustomResponseEntity.success(groupService.participateGroup(request.toServiceRequest(), user)); } - // 모임 삭제하기 + // 모임 삭제 API @DeleteMapping("") public CustomResponseEntity deleteGroup( @RequestParam Long groupId, @Login Users user @@ -50,7 +50,7 @@ public CustomResponseEntity deleteGroup( return CustomResponseEntity.success(groupService.participateDelete(groupId, user)); } - // 모임 참여 정보 수정 + // 내 참여 정보 수정 API @PatchMapping("/participate") public CustomResponseEntity participateUpdate( @RequestBody @Valid GroupRequest.ParticipateUpdate request, @Login Users user @@ -58,7 +58,7 @@ public CustomResponseEntity participateUpdate( return CustomResponseEntity.success(groupService.participateUpdate(request.toServiceRequest(), user)); } - // 모임 나가기 + // 모임 나가기 API @DeleteMapping("/participate") public CustomResponseEntity participateExit( @RequestParam Long participateId, @Login Users user @@ -66,7 +66,7 @@ public CustomResponseEntity participateExit( return CustomResponseEntity.success(groupService.participateExit(participateId, user)); } - // 모임원 내보내기 (Admin) + // 모임원 내보내기 API @DeleteMapping("/participate/removal") public CustomResponseEntity participateRemoval( @RequestParam Long participateId, @Login Users user @@ -74,7 +74,7 @@ public CustomResponseEntity participateRemoval( return CustomResponseEntity.success(groupService.participateRemoval(participateId, user)); } - // 모임 추천 지역 조회하기 + // 모임 추천 지역 조회하기 API @GetMapping("/best-region") public CustomResponseEntity> getBestRegion( @RequestParam Long groupId @@ -82,7 +82,7 @@ public CustomResponseEntity> getBestRegion( return CustomResponseEntity.success(groupService.getBestRegion(groupId)); } - // 내 모임 확인하기 + // 내 모임 확인하기 API @GetMapping("/participate") public CustomResponseEntity> getMyParticipate( @Login Users user diff --git a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java index 146082a..06873f2 100644 --- a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java @@ -314,7 +314,7 @@ void participateRemoval() throws Exception { )); } - @DisplayName("모임 삭제하기 API") + @DisplayName("모임 삭제 API") @Test void groupDelete() throws Exception { // given @@ -335,6 +335,14 @@ void groupDelete() throws Exception { formParameters( parameterWithName("groupId") .description("그룹 ID") + ), + responseFields( + fieldWithPath("code").type(NUMBER) + .description("상태 코드"), + fieldWithPath("message").type(STRING) + .description("상태 메세지"), + fieldWithPath("data").type(JsonFieldType.NULL) + .description("Always NULL") ) )); } From 9572e598eb0e26f88195bbe563074644e2edd7bc Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 15:28:30 +0900 Subject: [PATCH 2/9] =?UTF-8?q?refactor=20:=20=EB=82=B4=20=EB=AA=A8?= =?UTF-8?q?=EC=9E=84=20=ED=99=95=EC=9D=B8=ED=95=98=EA=B8=B0=20API=20->=20?= =?UTF-8?q?=EB=AA=A8=EC=9E=84=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=ED=95=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/space/repository/GroupCustomRepository.java | 2 +- .../domain/space/repository/GroupRepositoryImpl.java | 2 +- .../backend/domain/space/response/GroupResponse.java | 4 +++- .../backend/domain/space/service/GroupService.java | 10 ++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java b/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java index 3bfc403..3e99c84 100644 --- a/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java +++ b/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java @@ -9,6 +9,6 @@ @Repository public interface GroupCustomRepository { Optional findByIdToFetchJoinBestPlace(Long groupId); - List myParticipationGroups(Long userId); + List findByGroupsByFetch(Long userId); Optional findByGroupParticipation(Long groupId); } diff --git a/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java b/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java index b91b0c8..7bcf4dc 100644 --- a/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java +++ b/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java @@ -32,7 +32,7 @@ public Optional findByIdToFetchJoinBestPlace(Long groupId) { } @Override - public List myParticipationGroups(Long userId) { + public List findByGroupsByFetch(Long userId) { return queryFactory .selectFrom(groups) .innerJoin(groups.participations, participation) diff --git a/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java b/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java index 2a0f80b..d6a222f 100644 --- a/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java +++ b/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java @@ -174,16 +174,18 @@ public static class MyParticipate { private String groupName; private String groupDate; private Integer groupParticipates; + private List participantNames; private List bestPlaces; public static GroupResponse.MyParticipate response( - Groups group, List bestPlaces + Groups group, List bestPlaces, List participantNames ) { return MyParticipate.builder() .groupId(group.getGroupId()) .groupName(group.getName()) .groupDate(group.getDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) .groupParticipates(group.getParticipations().size()) + .participantNames(participantNames) .bestPlaces(bestPlaces) .build(); } diff --git a/src/main/java/com/moim/backend/domain/space/service/GroupService.java b/src/main/java/com/moim/backend/domain/space/service/GroupService.java index 093bea2..2613f95 100644 --- a/src/main/java/com/moim/backend/domain/space/service/GroupService.java +++ b/src/main/java/com/moim/backend/domain/space/service/GroupService.java @@ -173,11 +173,13 @@ public List getBestRegion(Long groupId) { // 내 모임 확인하기 public List getMyParticipate(Users user) { - List groups = groupRepository.myParticipationGroups(user.getUserId()); + List groups = groupRepository.findByGroupsByFetch(user.getUserId()); return groups.stream() .map(group -> GroupResponse.MyParticipate.response( - group, groupBestPlaceToList(group)) - ).toList(); + group, + groupBestPlaceToList(group), + group.getParticipations().stream().map(Participation::getUserName).toList())) + .toList(); } // 모임 장소 추천 조회 리스트 API @@ -221,6 +223,7 @@ private static URI createNaverRequestUri(String local, String keyword) { .build() .toUri(); } + private void checkDuplicateParticipation(Groups group, Users user) { if (participationRepository.countByGroupAndUserId(group, user.getUserId()) > 0) { throw new CustomException(DUPLICATE_PARTICIPATION); @@ -246,7 +249,6 @@ private static void validateParticipationMyInfo(Users user, Participation myPart } - // method private static List getParticipantsByRegion(Groups group) { List regions = new ArrayList<>(); From 81b4c810493e086c6d4b3931831053b2a0db930f Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 15:28:47 +0900 Subject: [PATCH 3/9] =?UTF-8?q?test,=20docs=20:=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=EC=97=90=20=EB=A7=9E=EC=B6=B0=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20Docs=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/space/GroupControllerDocsTest.java | 16 ++++++++++------ .../space/repository/GroupRepositoryTest.java | 5 ++--- .../domain/space/service/GroupServiceTest.java | 6 ++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java index 06873f2..7801347 100644 --- a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java @@ -405,6 +405,7 @@ void getMyParticipate() throws Exception { .groupName("그룹1") .groupDate("2023-07-15") .groupParticipates(3) + .participantNames(List.of("양파쿵야", "주먹밥쿵야", "샐러리쿵야")) .bestPlaces( List.of( GroupResponse.BestPlaces.builder() @@ -427,7 +428,8 @@ void getMyParticipate() throws Exception { .groupId(2L) .groupName("그룹2") .groupDate("2023-07-28") - .groupParticipates(7) + .groupParticipates(3) + .participantNames(List.of("양파쿵야", "주먹밥쿵야", "샐러리쿵야")) .bestPlaces( List.of( GroupResponse.BestPlaces.builder() @@ -475,7 +477,9 @@ void getMyParticipate() throws Exception { .description("그룹 모임날짜"), fieldWithPath("data[].groupParticipates").type(NUMBER) .description("그룹 참여자 수 / Integer"), - fieldWithPath("data[].bestPlaces[]").type(JsonFieldType.ARRAY) + fieldWithPath("data[].participantNames[]").type(ARRAY) + .description("그룹 참여자 이름 리스트"), + fieldWithPath("data[].bestPlaces[]").type(ARRAY) .description("그룹 추천장소 현황"), fieldWithPath("data[].bestPlaces[].bestPlaceId").type(NUMBER) .description("그룹 추천장소 ID / Long"), @@ -636,15 +640,15 @@ void keywordCentralizedMeetingSpot() throws Exception { .description("홈페이지 URL"), fieldWithPath("data[].detail.tel").type(STRING) .description("전화번호"), - fieldWithPath("data[].detail.category[]").type(JsonFieldType.ARRAY) + fieldWithPath("data[].detail.category[]").type(ARRAY) .description("카테고리 목록 / List"), fieldWithPath("data[].detail.x").type(STRING) .description("위도"), fieldWithPath("data[].detail.y").type(STRING) .description("경도"), - fieldWithPath("data[].detail.thumUrls[]").type(JsonFieldType.ARRAY) + fieldWithPath("data[].detail.thumUrls[]").type(ARRAY) .description("상세 이미지 URL 목록 / List"), - fieldWithPath("data[].detail.menuInfo[]").type(JsonFieldType.ARRAY) + fieldWithPath("data[].detail.menuInfo[]").type(ARRAY) .description("메뉴 정보 목록 / List") ) )); @@ -672,7 +676,7 @@ void readParticipateGroupByRegion() throws Exception { .adminId(1L) .name("모이닷 팀 프로젝트") .date("2023-12-01") - .participantsByRegion(List.of(region1,region2,region3)) + .participantsByRegion(List.of(region1, region2, region3)) .build() ); diff --git a/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java b/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java index 4a1cb51..d0a1a05 100644 --- a/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java +++ b/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java @@ -11,7 +11,6 @@ import com.moim.backend.domain.space.entity.TransportationType; import com.moim.backend.domain.user.entity.Users; import com.moim.backend.domain.user.repository.UserRepository; -import com.moim.backend.global.common.exception.CustomException; import jakarta.persistence.EntityManager; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -58,7 +57,7 @@ class GroupRepositoryTest { @DisplayName("유저가 참여하고있는 모임의 정보를 fetchJoin 으로 데이터를 가져온다.") @Test - void fetchJoinParticipateMyGroupData() { + void findByGroupsByFetch() { // given Users admin1 = savedUser("admin1@test.com", "어드민1"); Users admin2 = savedUser("admin2@test.com", "어드민2"); @@ -90,7 +89,7 @@ void fetchJoinParticipateMyGroupData() { em.clear(); // when - List groups = groupRepository.myParticipationGroups(user1.getUserId()); + List groups = groupRepository.findByGroupsByFetch(user1.getUserId()); // then assertThat(groups).hasSize(3) diff --git a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java index d975a98..eeba468 100644 --- a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java +++ b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java @@ -455,8 +455,8 @@ void getMyParticipate() { savedParticipation(user1, group2, "양쿵", "아무데나", 36.23423, 127.32423, PUBLIC); savedParticipation(user1, group3, "양쿵", "아무데나", 36.23423, 127.32423, PUBLIC); - savedParticipation(user2, group1, "양쿵", "아무데나", 36.23423, 127.32423, PUBLIC); - savedParticipation(user2, group3, "양쿵", "아무데나", 36.23423, 127.32423, PUBLIC); + savedParticipation(user2, group1, "주쿵", "아무데나", 36.23423, 127.32423, PUBLIC); + savedParticipation(user2, group3, "주쿵", "아무데나", 36.23423, 127.32423, PUBLIC); em.flush(); em.clear(); @@ -471,6 +471,8 @@ void getMyParticipate() { .extracting("groupId", "groupName", "groupDate", "groupParticipates") .contains(group1.getGroupId(), "그룹1", "2023-07-10", 3); + assertThat(response.get(0).getParticipantNames()).isEqualTo(List.of("어드민","양쿵","주쿵")); + assertThat(response.get(0).getBestPlaces()) .hasSize(3) .extracting("bestPlaceName") From 5a2346b8ea3cc81efc4a59a34612f6505438eb36 Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 17:15:29 +0900 Subject: [PATCH 4/9] =?UTF-8?q?refactor=20:=20=ED=88=AC=ED=91=9C=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=EC=8B=9C=20=EC=9E=A5=EC=86=8C=EA=B0=80=20?= =?UTF-8?q?=ED=99=95=EC=A0=95=EB=90=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/groupvote/response/VoteResponse.java | 9 +++++++-- .../backend/domain/groupvote/service/VoteService.java | 8 ++++++++ .../com/moim/backend/domain/space/entity/Groups.java | 4 ++++ .../backend/docs/groupvote/VoteControllerDocsTest.java | 3 +++ .../domain/groupvote/service/VoteServiceTest.java | 8 ++++---- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/moim/backend/domain/groupvote/response/VoteResponse.java b/src/main/java/com/moim/backend/domain/groupvote/response/VoteResponse.java index 21dc472..9e02d55 100644 --- a/src/main/java/com/moim/backend/domain/groupvote/response/VoteResponse.java +++ b/src/main/java/com/moim/backend/domain/groupvote/response/VoteResponse.java @@ -1,5 +1,7 @@ package com.moim.backend.domain.groupvote.response; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; import com.moim.backend.domain.groupvote.entity.Vote; import com.moim.backend.domain.space.entity.BestPlace; import com.moim.backend.domain.space.entity.Groups; @@ -9,12 +11,12 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; + public class VoteResponse { @AllArgsConstructor @@ -53,6 +55,8 @@ public static class SelectResult { private Long groupId; private String groupName; private String groupDate; + @JsonInclude(value = NON_NULL) + private String confirmPlace; private Long voteId; private Boolean isClosed; private Boolean isAnonymous; @@ -76,6 +80,7 @@ public static VoteResponse.SelectResult response( .groupId(group.getGroupId()) .groupName(group.getName()) .groupDate(groupDate) + .confirmPlace(group.getPlace()) .voteId(vote.getVoteId()) .isClosed(vote.getIsClosed()) .isAnonymous(vote.getIsAnonymous()) diff --git a/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java b/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java index f87a90b..13c700c 100644 --- a/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java +++ b/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java @@ -21,6 +21,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -141,9 +142,16 @@ public VoteResponse.SelectResult conclusionVote(Long groupId, Users user) { // 투표 종료 vote.conclusionVote(); + // 가장 높은 투표를 받은 장소 선정 + BestPlace confirmPlace = group.getBestPlaces().stream() + .max(Comparator.comparing(bestPlace -> bestPlace.getSelectPlaces().size())) + .orElseThrow(() -> new CustomException(FAIL)); + group.confirmPlace(confirmPlace.getPlaceName()); + // 종료 이후 현재 추천된 장소들의 현황을 조회 List bestPlaces = selectPlaceRepository.findByVoteStatus(vote.getGroupId()); List voteStatuses = getVoteStatuses(user, bestPlaces); + return VoteResponse.SelectResult.response(group, vote, voteStatuses); } diff --git a/src/main/java/com/moim/backend/domain/space/entity/Groups.java b/src/main/java/com/moim/backend/domain/space/entity/Groups.java index 7011d55..735663e 100644 --- a/src/main/java/com/moim/backend/domain/space/entity/Groups.java +++ b/src/main/java/com/moim/backend/domain/space/entity/Groups.java @@ -34,4 +34,8 @@ public class Groups { @OneToMany(mappedBy = "group") private List bestPlaces; + + public void confirmPlace(String place) { + this.place = place; + } } diff --git a/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java b/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java index 3943036..61a0afe 100644 --- a/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java @@ -336,6 +336,7 @@ void conclusionVote() throws Exception { .groupId(1L) .groupName("모이닷 모임") .groupDate("2023-08-04") + .confirmPlace("성신여대입구역") .voteId(3L) .isClosed(true) .isAnonymous(true) @@ -376,6 +377,8 @@ void conclusionVote() throws Exception { .description("그룹 이름"), fieldWithPath("data.groupDate").type(JsonFieldType.STRING). description("그룹 날짜"), + fieldWithPath("data.confirmPlace").type(JsonFieldType.STRING). + description("확정된 모임 장소"), fieldWithPath("data.voteId").type(JsonFieldType.NUMBER) .description("투표 ID"), fieldWithPath("data.isClosed").type(JsonFieldType.BOOLEAN) diff --git a/src/test/java/com/moim/backend/domain/groupvote/service/VoteServiceTest.java b/src/test/java/com/moim/backend/domain/groupvote/service/VoteServiceTest.java index 0e8d58f..8faaa2b 100644 --- a/src/test/java/com/moim/backend/domain/groupvote/service/VoteServiceTest.java +++ b/src/test/java/com/moim/backend/domain/groupvote/service/VoteServiceTest.java @@ -325,7 +325,7 @@ void readSelectPlaceUsersWithNotVotedPlaceThrowException() { .contains(-2006, "해당 장소를 투표한 인원은 0명 입니다."); } - @DisplayName("어드민이 자신의 그룹의 투표를 종료한다.") + @DisplayName("어드민이 자신의 그룹의 투표를 종료하고 가장 높은 선택을 받은 장소가 선정된다.") @Test void conclusionVote() { // given @@ -353,10 +353,10 @@ void conclusionVote() { // then assertThat(response) - .extracting("groupId", "voteId", "groupName", "groupDate", "endAt", "isClosed") + .extracting("groupId", "voteId", "groupName", "groupDate", "endAt", "isClosed", "confirmPlace") .contains( group.getGroupId(), vote.getVoteId(), - group.getName(), "2023-07-10", "2023-08-03 12:00:00", true + group.getName(), "2023-07-10", "2023-08-03 12:00:00", true, "강남역" ); assertThat(response.getVoteStatuses()) @@ -374,7 +374,7 @@ void conclusionVote() { assertThat(validateVote.getIsClosed()).isTrue(); } - @DisplayName("어드민이 자신의 그룹의 투표를 종료한다.") + @DisplayName("일반 유저가 자신의 그룹의 투표를 종료하려할때 익셉션이 발생한다.") @Test void conclusionWithNotAdminThrowException() { // given From 0e65c5c73484128986c2b47f650e8f3c7f1dc303 Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 17:33:19 +0900 Subject: [PATCH 5/9] =?UTF-8?q?refactor,docs=20:=20=EB=82=B4=20=EB=AA=A8?= =?UTF-8?q?=EC=9E=84=20=ED=99=95=EC=9D=B8=ED=95=98=EA=B8=B0=20API=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 확정 장소 추가 응답 및 지역 리스트 단순화 --- .../domain/space/response/GroupResponse.java | 24 ++-------- .../domain/space/service/GroupService.java | 10 +--- .../docs/space/GroupControllerDocsTest.java | 46 ++++--------------- .../space/service/GroupServiceTest.java | 11 ++--- 4 files changed, 19 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java b/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java index d6a222f..4337e82 100644 --- a/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java +++ b/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java @@ -174,35 +174,21 @@ public static class MyParticipate { private String groupName; private String groupDate; private Integer groupParticipates; + private String confirmPlace; + private List bestPlaceNames; private List participantNames; - private List bestPlaces; public static GroupResponse.MyParticipate response( - Groups group, List bestPlaces, List participantNames + Groups group, List bestPlaceNames, List participantNames ) { return MyParticipate.builder() .groupId(group.getGroupId()) .groupName(group.getName()) .groupDate(group.getDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) .groupParticipates(group.getParticipations().size()) + .confirmPlace(group.getPlace()) + .bestPlaceNames(bestPlaceNames) .participantNames(participantNames) - .bestPlaces(bestPlaces) - .build(); - } - } - - @Getter - @NoArgsConstructor - @AllArgsConstructor - @Builder - public static class BestPlaces { - private Long bestPlaceId; - private String bestPlaceName; - - public static GroupResponse.BestPlaces response(BestPlace bestPlace) { - return GroupResponse.BestPlaces.builder() - .bestPlaceId(bestPlace.getBestPlaceId()) - .bestPlaceName(bestPlace.getPlaceName()) .build(); } } diff --git a/src/main/java/com/moim/backend/domain/space/service/GroupService.java b/src/main/java/com/moim/backend/domain/space/service/GroupService.java index 2613f95..c2ebd49 100644 --- a/src/main/java/com/moim/backend/domain/space/service/GroupService.java +++ b/src/main/java/com/moim/backend/domain/space/service/GroupService.java @@ -177,7 +177,7 @@ public List getMyParticipate(Users user) { return groups.stream() .map(group -> GroupResponse.MyParticipate.response( group, - groupBestPlaceToList(group), + group.getBestPlaces().stream().map(BestPlace::getPlaceName).toList(), group.getParticipations().stream().map(Participation::getUserName).toList())) .toList(); } @@ -378,12 +378,4 @@ private Participation getParticipate(Long id) { () -> new CustomException(NOT_FOUND_PARTICIPATE) ); } - - private static List groupBestPlaceToList(Groups group) { - // 로직상 NPE 가 발생할 수 없음 - List bestPlaces = group.getBestPlaces(); - return bestPlaces.stream() - .map(GroupResponse.BestPlaces::response) - .toList(); - } } diff --git a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java index 7801347..215521a 100644 --- a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java @@ -405,23 +405,9 @@ void getMyParticipate() throws Exception { .groupName("그룹1") .groupDate("2023-07-15") .groupParticipates(3) + .confirmPlace("none") + .bestPlaceNames(List.of("종로5가역","종로3가역","동대문역")) .participantNames(List.of("양파쿵야", "주먹밥쿵야", "샐러리쿵야")) - .bestPlaces( - List.of( - GroupResponse.BestPlaces.builder() - .bestPlaceId(764L) - .bestPlaceName("종로5가역") - .build(), - GroupResponse.BestPlaces.builder() - .bestPlaceId(765L) - .bestPlaceName("종로3가역") - .build(), - GroupResponse.BestPlaces.builder() - .bestPlaceId(763L) - .bestPlaceName("동대문역") - .build() - ) - ) .build(); GroupResponse.MyParticipate data2 = GroupResponse.MyParticipate.builder() @@ -429,23 +415,9 @@ void getMyParticipate() throws Exception { .groupName("그룹2") .groupDate("2023-07-28") .groupParticipates(3) + .confirmPlace("교대역") + .bestPlaceNames(List.of("강남역","교대역","역삼역")) .participantNames(List.of("양파쿵야", "주먹밥쿵야", "샐러리쿵야")) - .bestPlaces( - List.of( - GroupResponse.BestPlaces.builder() - .bestPlaceId(737L) - .bestPlaceName("강남역") - .build(), - GroupResponse.BestPlaces.builder() - .bestPlaceId(736L) - .bestPlaceName("교대역") - .build(), - GroupResponse.BestPlaces.builder() - .bestPlaceId(738L) - .bestPlaceName("역삼역") - .build() - ) - ) .build(); given(groupService.getMyParticipate(any())) @@ -477,14 +449,12 @@ void getMyParticipate() throws Exception { .description("그룹 모임날짜"), fieldWithPath("data[].groupParticipates").type(NUMBER) .description("그룹 참여자 수 / Integer"), + fieldWithPath("data[].confirmPlace").type(STRING) + .description("그룹 확정 장소 / 미확정 : 'none' "), fieldWithPath("data[].participantNames[]").type(ARRAY) .description("그룹 참여자 이름 리스트"), - fieldWithPath("data[].bestPlaces[]").type(ARRAY) - .description("그룹 추천장소 현황"), - fieldWithPath("data[].bestPlaces[].bestPlaceId").type(NUMBER) - .description("그룹 추천장소 ID / Long"), - fieldWithPath("data[].bestPlaces[].bestPlaceName").type(STRING) - .description("그룹 추천장소 이름") + fieldWithPath("data[].bestPlaceNames[]").type(ARRAY) + .description("그룹 추천장소 현황 리스트") ) )); } diff --git a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java index eeba468..33facbb 100644 --- a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java +++ b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java @@ -122,7 +122,7 @@ void participateAdmin() { ) .contains( saveGroup.getGroupId(), admin.getUserId(), "커피나무", - "어드민", 37.591043, 127.019721,"PUBLIC" + "어드민", 37.591043, 127.019721, "PUBLIC" ); assertThat(participation.getPassword()).isEqualTo(encrypt("2345")); @@ -468,14 +468,13 @@ void getMyParticipate() { assertThat(response).hasSize(3); assertThat(response.get(0)) - .extracting("groupId", "groupName", "groupDate", "groupParticipates") - .contains(group1.getGroupId(), "그룹1", "2023-07-10", 3); + .extracting("groupId", "groupName", "groupDate", "groupParticipates", "confirmPlace") + .contains(group1.getGroupId(), "그룹1", "2023-07-10", 3, "none"); - assertThat(response.get(0).getParticipantNames()).isEqualTo(List.of("어드민","양쿵","주쿵")); + assertThat(response.get(0).getParticipantNames()).isEqualTo(List.of("어드민", "양쿵", "주쿵")); - assertThat(response.get(0).getBestPlaces()) + assertThat(response.get(0).getBestPlaceNames()) .hasSize(3) - .extracting("bestPlaceName") .contains("의정부역", "서울역", "개봉역"); } From ee76e92cf57f6a07a955ddb6d70b982fbf703b51 Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 20:44:33 +0900 Subject: [PATCH 6/9] =?UTF-8?q?refactor=20:=20=EB=82=B4=20=EB=AA=A8?= =?UTF-8?q?=EC=9E=84=20=ED=99=95=EC=9D=B8=ED=95=98=EA=B8=B0=20API=20->=20?= =?UTF-8?q?=EC=96=B4=EB=93=9C=EB=AF=BC=20=EB=84=A4=EC=9E=84=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/space/repository/GroupCustomRepository.java | 2 +- .../domain/space/repository/GroupRepositoryImpl.java | 2 +- .../moim/backend/domain/space/response/GroupResponse.java | 4 +++- .../moim/backend/domain/space/service/GroupService.java | 7 ++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java b/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java index 3e99c84..54db54c 100644 --- a/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java +++ b/src/main/java/com/moim/backend/domain/space/repository/GroupCustomRepository.java @@ -9,6 +9,6 @@ @Repository public interface GroupCustomRepository { Optional findByIdToFetchJoinBestPlace(Long groupId); - List findByGroupsByFetch(Long userId); + List findByGroupsFetch(Long userId); Optional findByGroupParticipation(Long groupId); } diff --git a/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java b/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java index 7bcf4dc..d950c1e 100644 --- a/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java +++ b/src/main/java/com/moim/backend/domain/space/repository/GroupRepositoryImpl.java @@ -32,7 +32,7 @@ public Optional findByIdToFetchJoinBestPlace(Long groupId) { } @Override - public List findByGroupsByFetch(Long userId) { + public List findByGroupsFetch(Long userId) { return queryFactory .selectFrom(groups) .innerJoin(groups.participations, participation) diff --git a/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java b/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java index 4337e82..c6d2028 100644 --- a/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java +++ b/src/main/java/com/moim/backend/domain/space/response/GroupResponse.java @@ -172,6 +172,7 @@ public static GroupResponse.Exit response(Boolean isDeletedSpace, String message public static class MyParticipate { private Long groupId; private String groupName; + private String groupAdminName; private String groupDate; private Integer groupParticipates; private String confirmPlace; @@ -179,11 +180,12 @@ public static class MyParticipate { private List participantNames; public static GroupResponse.MyParticipate response( - Groups group, List bestPlaceNames, List participantNames + Groups group, String groupAdminName, List bestPlaceNames, List participantNames ) { return MyParticipate.builder() .groupId(group.getGroupId()) .groupName(group.getName()) + .groupAdminName(groupAdminName) .groupDate(group.getDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) .groupParticipates(group.getParticipations().size()) .confirmPlace(group.getPlace()) diff --git a/src/main/java/com/moim/backend/domain/space/service/GroupService.java b/src/main/java/com/moim/backend/domain/space/service/GroupService.java index c2ebd49..5acbec8 100644 --- a/src/main/java/com/moim/backend/domain/space/service/GroupService.java +++ b/src/main/java/com/moim/backend/domain/space/service/GroupService.java @@ -173,10 +173,15 @@ public List getBestRegion(Long groupId) { // 내 모임 확인하기 public List getMyParticipate(Users user) { - List groups = groupRepository.findByGroupsByFetch(user.getUserId()); + List groups = groupRepository.findByGroupsFetch(user.getUserId()); return groups.stream() .map(group -> GroupResponse.MyParticipate.response( group, + group.getParticipations().stream() + .filter(participation -> participation.getUserId().equals(group.getAdminId())) + .map(Participation::getUserName).findFirst().orElseThrow( + () -> new CustomException(NOT_FOUND_PARTICIPATE) + ), group.getBestPlaces().stream().map(BestPlace::getPlaceName).toList(), group.getParticipations().stream().map(Participation::getUserName).toList())) .toList(); From aeb954715791c2c6fd07acff7192b76443be849b Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sat, 19 Aug 2023 20:44:46 +0900 Subject: [PATCH 7/9] =?UTF-8?q?docs,=20test=20:=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20=EB=B0=8F=20docs=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moim/backend/docs/space/GroupControllerDocsTest.java | 4 ++++ .../backend/domain/space/repository/GroupRepositoryTest.java | 2 +- .../moim/backend/domain/space/service/GroupServiceTest.java | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java index 215521a..0e9aa50 100644 --- a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java @@ -403,6 +403,7 @@ void getMyParticipate() throws Exception { GroupResponse.MyParticipate data1 = GroupResponse.MyParticipate.builder() .groupId(1L) .groupName("그룹1") + .groupAdminName("양파쿵야") .groupDate("2023-07-15") .groupParticipates(3) .confirmPlace("none") @@ -413,6 +414,7 @@ void getMyParticipate() throws Exception { GroupResponse.MyParticipate data2 = GroupResponse.MyParticipate.builder() .groupId(2L) .groupName("그룹2") + .groupAdminName("주먹밥쿵야") .groupDate("2023-07-28") .groupParticipates(3) .confirmPlace("교대역") @@ -445,6 +447,8 @@ void getMyParticipate() throws Exception { .description("그룹 ID"), fieldWithPath("data[].groupName").type(STRING) .description("그룹 이름"), + fieldWithPath("data[].groupAdminName").type(STRING) + .description("그룹 모임장 이름"), fieldWithPath("data[].groupDate").type(STRING) .description("그룹 모임날짜"), fieldWithPath("data[].groupParticipates").type(NUMBER) diff --git a/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java b/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java index d0a1a05..f3b481d 100644 --- a/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java +++ b/src/test/java/com/moim/backend/domain/space/repository/GroupRepositoryTest.java @@ -89,7 +89,7 @@ void findByGroupsByFetch() { em.clear(); // when - List groups = groupRepository.findByGroupsByFetch(user1.getUserId()); + List groups = groupRepository.findByGroupsFetch(user1.getUserId()); // then assertThat(groups).hasSize(3) diff --git a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java index 33facbb..fa88a56 100644 --- a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java +++ b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java @@ -468,8 +468,8 @@ void getMyParticipate() { assertThat(response).hasSize(3); assertThat(response.get(0)) - .extracting("groupId", "groupName", "groupDate", "groupParticipates", "confirmPlace") - .contains(group1.getGroupId(), "그룹1", "2023-07-10", 3, "none"); + .extracting("groupId", "groupName", "groupAdminName", "groupDate", "groupParticipates", "confirmPlace") + .contains(group1.getGroupId(), "어드민", "그룹1", "2023-07-10", 3, "none"); assertThat(response.get(0).getParticipantNames()).isEqualTo(List.of("어드민", "양쿵", "주쿵")); From b7b7942c401f13eb731b83a7f1fabe2667608c1d Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Sun, 20 Aug 2023 12:45:55 +0900 Subject: [PATCH 8/9] =?UTF-8?q?chore=20:=20=EB=A7=A4=ED=95=91=20=EC=A3=BC?= =?UTF-8?q?=EC=86=8C=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=EA=B8=B0=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/health_check.sh | 2 +- src/docs/asciidoc/api/groupvote/vote.adoc | 11 ++------ src/docs/asciidoc/api/space/group.adoc | 2 +- .../groupvote/controller/VoteController.java | 13 +++++----- .../domain/groupvote/service/VoteService.java | 8 +++--- .../space/controller/GroupController.java | 2 +- .../domain/space/service/GroupService.java | 7 ----- .../user/controller/UserController.java | 6 +++++ .../groupvote/VoteControllerDocsTest.java | 10 +++---- .../docs/space/GroupControllerDocsTest.java | 20 +++++++------- .../controller/VoteControllerTest.java | 12 ++++----- .../space/controller/GroupControllerTest.java | 26 +++++++++---------- 12 files changed, 56 insertions(+), 63 deletions(-) diff --git a/scripts/health_check.sh b/scripts/health_check.sh index f04ca27..df44533 100644 --- a/scripts/health_check.sh +++ b/scripts/health_check.sh @@ -22,7 +22,7 @@ echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..." for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10 do echo "> #${RETRY_COUNT} trying..." - RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/api/v1/version) + RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/auth/success) if [ ${RESPONSE_CODE} -eq 200 ]; then echo "> New WAS successfully running" diff --git a/src/docs/asciidoc/api/groupvote/vote.adoc b/src/docs/asciidoc/api/groupvote/vote.adoc index 910709b..3247a23 100644 --- a/src/docs/asciidoc/api/groupvote/vote.adoc +++ b/src/docs/asciidoc/api/groupvote/vote.adoc @@ -20,16 +20,9 @@ include::{snippets}/select-vote/request-headers.adoc[] include::{snippets}/select-vote/path-parameters.adoc[] -==== Request Parameters -[source,http,options="nowrap"] ----- -POST /api/v1/group/1/vote/select?bestPlaceIds=1,3 HTTP/1.1 -Authorization: JWT AccessToken -Content-Type: application/x-www-form-urlencoded -Host: localhost:8080 -Content-Length: 29 ----- +==== Request FormParameters include::{snippets}/select-vote/form-parameters.adoc[] +include::{snippets}/select-vote/http-request.adoc[] ==== HTTP ResponseBody include::{snippets}/select-vote/http-response.adoc[] diff --git a/src/docs/asciidoc/api/space/group.adoc b/src/docs/asciidoc/api/space/group.adoc index 8c9a12b..c8fc622 100644 --- a/src/docs/asciidoc/api/space/group.adoc +++ b/src/docs/asciidoc/api/space/group.adoc @@ -103,7 +103,7 @@ include::{snippets}/my-participate/response-fields.adoc[] include::{snippets}/read-bestPlace-keyword/query-parameters.adoc[] [source,http,options="nowrap"] ---- -GET /api/v1/group/best-region/place?x=127.232943&y=37.6823811&local=성신여대입구역AD&keyword=식당 HTTP/1.1 +GET /group/best-region/place?x=127.232943&y=37.6823811&local=성신여대입구역AD&keyword=식당 HTTP/1.1 Host: localhost:8080 ---- diff --git a/src/main/java/com/moim/backend/domain/groupvote/controller/VoteController.java b/src/main/java/com/moim/backend/domain/groupvote/controller/VoteController.java index d4dbf8d..14afd14 100644 --- a/src/main/java/com/moim/backend/domain/groupvote/controller/VoteController.java +++ b/src/main/java/com/moim/backend/domain/groupvote/controller/VoteController.java @@ -1,6 +1,5 @@ package com.moim.backend.domain.groupvote.controller; -import com.moim.backend.domain.groupvote.entity.Vote; import com.moim.backend.domain.groupvote.request.VoteRequest; import com.moim.backend.domain.groupvote.response.VoteResponse; import com.moim.backend.domain.groupvote.service.VoteService; @@ -16,11 +15,11 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/group") +@RequestMapping("/group") public class VoteController { private final VoteService voteService; - // 투표 생성(시작) + // 투표 생성 API @PostMapping("/{groupId}/vote") public CustomResponseEntity createVote( @PathVariable Long groupId, @@ -29,7 +28,7 @@ public CustomResponseEntity createVote( return CustomResponseEntity.success(voteService.createVote(request.toServiceRequest(), groupId, user)); } - // 투표 읽기 + // 투표 읽기 API @GetMapping("/{groupId}/vote") public CustomResponseEntity readVote( @PathVariable Long groupId, @Login Users user @@ -38,7 +37,7 @@ public CustomResponseEntity readVote( } // TODO: 동시성 문제가 발생할 것 같다 - // 투표 하기 + // 투표 참여 API @PostMapping("/{groupId}/vote/select") public CustomResponseEntity selectVote( @PathVariable Long groupId, @RequestParam List bestPlaceIds, @Login Users user @@ -48,7 +47,7 @@ public CustomResponseEntity selectVote( ); } - // 해당 장소 투표한 인원 리스트 조회하기 + // 해당 장소 투표한 인원 리스트 조회하기 API @GetMapping("/{groupId}/vote/select") public CustomResponseEntity> readSelectPlaceUsers( @PathVariable Long groupId, @RequestParam Long bestPlaceId, @Login Users user @@ -58,7 +57,7 @@ public CustomResponseEntity> readSelectPlaceU ); } - // 투표 종료하기 + // 투표 종료하기 API @PatchMapping("/{groupId}/vote") public CustomResponseEntity conclusionVote( @PathVariable Long groupId, @Login Users user diff --git a/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java b/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java index 13c700c..ddde56f 100644 --- a/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java +++ b/src/main/java/com/moim/backend/domain/groupvote/service/VoteService.java @@ -39,6 +39,7 @@ public class VoteService { private final BestPlaceRepository bestPlaceRepository; private final SelectPlaceRepository selectPlaceRepository; + // 투표 생성 API @Transactional public VoteResponse.Create createVote(VoteServiceRequest.Create request, Long groupId, Users user) { Groups group = getGroups(groupId); @@ -60,6 +61,7 @@ public VoteResponse.Create createVote(VoteServiceRequest.Create request, Long gr return VoteResponse.Create.response(vote); } + // 투표 참여 API @Transactional public VoteResponse.SelectResult selectVote(Long groupId, List bestPlaceIds, Users user, LocalDateTime now) { // 투표 개설 및 투표에 대한 유효성 검증 @@ -92,11 +94,9 @@ public VoteResponse.SelectResult selectVote(Long groupId, List bestPlaceId return VoteResponse.SelectResult.response(group, vote, voteStatuses); } + // 투표 읽기 API public VoteResponse.SelectResult readVote(Long groupId, Users user) { Groups group = getGroups(groupId); - - // TODO: 어떤 방식이 프론트엔드에서 처리하기 편한지 확인해봐야 할 것 같음 - // 투표가 개설되지 않은 상태면 Exception 발생 Vote vote = getVote(groupId); // 투표 이후 현재 추천된 장소들의 현황을 조회 @@ -105,6 +105,7 @@ public VoteResponse.SelectResult readVote(Long groupId, Users user) { return VoteResponse.SelectResult.response(group, vote, voteStatuses); } + // 해당 장소 투표한 인원 리스트 조회하기 API public List readSelectPlaceUsers(Long groupId, Long bestPlaceId, Users user) { // 그룹의 추천장소와 투표 리스트를 fetch 조회 Groups group = groupRepository.findByIdToFetchJoinBestPlace(groupId) @@ -131,6 +132,7 @@ public List readSelectPlaceUsers(Long groupId, Lon }).toList(); } + // 투표 종료하기 API @Transactional public VoteResponse.SelectResult conclusionVote(Long groupId, Users user) { Groups group = getGroups(groupId); diff --git a/src/main/java/com/moim/backend/domain/space/controller/GroupController.java b/src/main/java/com/moim/backend/domain/space/controller/GroupController.java index 446e27f..480c513 100644 --- a/src/main/java/com/moim/backend/domain/space/controller/GroupController.java +++ b/src/main/java/com/moim/backend/domain/space/controller/GroupController.java @@ -15,7 +15,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/group") +@RequestMapping("/group") public class GroupController { private final GroupService groupService; diff --git a/src/main/java/com/moim/backend/domain/space/service/GroupService.java b/src/main/java/com/moim/backend/domain/space/service/GroupService.java index 5acbec8..aff8bad 100644 --- a/src/main/java/com/moim/backend/domain/space/service/GroupService.java +++ b/src/main/java/com/moim/backend/domain/space/service/GroupService.java @@ -132,13 +132,6 @@ public GroupResponse.Exit participateExit(Long participateId, Users user) { return GroupResponse.Exit.response(false, "모임에서 나갔습니다."); } - private Vote getVote(Groups group) { - return voteRepository.findByGroupId(group.getGroupId()).orElseThrow( - () -> new CustomException(NOT_CREATED_VOTE) - ); - } - - // 모임원 내보내기 @Transactional public Void participateRemoval(Long participateId, Users user) { diff --git a/src/main/java/com/moim/backend/domain/user/controller/UserController.java b/src/main/java/com/moim/backend/domain/user/controller/UserController.java index 7a3902e..5283976 100644 --- a/src/main/java/com/moim/backend/domain/user/controller/UserController.java +++ b/src/main/java/com/moim/backend/domain/user/controller/UserController.java @@ -25,6 +25,12 @@ public class UserController { private final UserService userService; + // 배포 검증용 API + @GetMapping("/success") + public CustomResponseEntity checkServerStatus() { + return CustomResponseEntity.success("Server On!"); + } + // 소셜 로그인 API @GetMapping("/signin") public CustomResponseEntity loginByOAuth( diff --git a/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java b/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java index 61a0afe..d46b7b0 100644 --- a/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/groupvote/VoteControllerDocsTest.java @@ -61,7 +61,7 @@ void createVote() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.post("/api/v1/group/{groupId}/vote", 1L) + RestDocumentationRequestBuilders.post("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -133,7 +133,7 @@ void selectVote() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.post("/api/v1/group/{groupId}/vote/select", 1L) + RestDocumentationRequestBuilders.post("/group/{groupId}/vote/select", 1L) .header("Authorization", "JWT AccessToken") .param("bestPlaceIds", bestPlaceIds) ) @@ -210,7 +210,7 @@ void readVote() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.get("/api/v1/group/{groupId}/vote", 1L) + RestDocumentationRequestBuilders.get("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") ) .andDo(print()) @@ -291,7 +291,7 @@ void readSelectPlaceUsers() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.get("/api/v1/group/{groupId}/vote/select", 1L) + RestDocumentationRequestBuilders.get("/group/{groupId}/vote/select", 1L) .header("Authorization", "JWT AccessToken") .param("bestPlaceId", "1") ) @@ -351,7 +351,7 @@ void conclusionVote() throws Exception { // when// then mockMvc.perform( - RestDocumentationRequestBuilders.patch("/api/v1/group/{groupId}/vote", 1L) + RestDocumentationRequestBuilders.patch("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") ) .andDo(print()) diff --git a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java index 0e9aa50..8a93313 100644 --- a/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java +++ b/src/test/java/com/moim/backend/docs/space/GroupControllerDocsTest.java @@ -62,7 +62,7 @@ void createGroup() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.post("/api/v1/group") + RestDocumentationRequestBuilders.post("/group") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -125,7 +125,7 @@ void participationGroup() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.post("/api/v1/group/participate") + RestDocumentationRequestBuilders.post("/group/participate") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -198,7 +198,7 @@ void participationUpdate() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.patch("/api/v1/group/participate") + RestDocumentationRequestBuilders.patch("/group/participate") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -252,7 +252,7 @@ void participationExit() throws Exception { ); // when // then mockMvc.perform( - RestDocumentationRequestBuilders.delete("/api/v1/group/participate") + RestDocumentationRequestBuilders.delete("/group/participate") .header("Authorization", "JWT AccessToken") .param("participateId", String.valueOf(1L)) ) @@ -287,7 +287,7 @@ void participateRemoval() throws Exception { // given // when // then mockMvc.perform( - RestDocumentationRequestBuilders.delete("/api/v1/group/participate/removal") + RestDocumentationRequestBuilders.delete("/group/participate/removal") .header("Authorization", "JWT AccessToken") .param("participateId", String.valueOf(1L)) ) @@ -320,7 +320,7 @@ void groupDelete() throws Exception { // given // when// then mockMvc.perform( - RestDocumentationRequestBuilders.delete("/api/v1/group") + RestDocumentationRequestBuilders.delete("/group") .header("Authorization", "JWT AccessToken") .param("groupId", String.valueOf(1L)) ) @@ -368,7 +368,7 @@ void getBestRegion() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.get("/api/v1/group/best-region") + RestDocumentationRequestBuilders.get("/group/best-region") .param("groupId", String.valueOf(14L)) ) .andDo(print()) @@ -427,7 +427,7 @@ void getMyParticipate() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group/participate") + MockMvcRequestBuilders.get("/group/participate") .header("Authorization", "JWT AccessToken") ) .andDo(print()) @@ -569,7 +569,7 @@ void keywordCentralizedMeetingSpot() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.get("/api/v1/group/best-region/place") + RestDocumentationRequestBuilders.get("/group/best-region/place") .param("x", "127.232943") .param("y", "37.6823811") .param("local", "성신여대입구역") @@ -656,7 +656,7 @@ void readParticipateGroupByRegion() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group") + MockMvcRequestBuilders.get("/group") .param("groupId", "1") ) .andDo(print()) diff --git a/src/test/java/com/moim/backend/domain/groupvote/controller/VoteControllerTest.java b/src/test/java/com/moim/backend/domain/groupvote/controller/VoteControllerTest.java index d209349..a63f23d 100644 --- a/src/test/java/com/moim/backend/domain/groupvote/controller/VoteControllerTest.java +++ b/src/test/java/com/moim/backend/domain/groupvote/controller/VoteControllerTest.java @@ -26,7 +26,7 @@ void createVote() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group/{groupId}/vote", 1L) + MockMvcRequestBuilders.post("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -44,7 +44,7 @@ void createVoteWithNotInsertAnonymousThrowException() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group/{groupId}/vote", 1L) + MockMvcRequestBuilders.post("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -62,7 +62,7 @@ void selectVote() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group/{groupId}/vote/select", 1L) + MockMvcRequestBuilders.post("/group/{groupId}/vote/select", 1L) .header("Authorization", "JWT AccessToken") .param("bestPlaceIds", StringUtils.collectionToCommaDelimitedString(bestPlaceIds)) ) @@ -76,7 +76,7 @@ void readVote() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group/{groupId}/vote", 1L) + MockMvcRequestBuilders.get("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") ) .andDo(print()) @@ -89,7 +89,7 @@ void readSelectPlaceUsers() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group/{groupId}/vote/select", 1L) + MockMvcRequestBuilders.get("/group/{groupId}/vote/select", 1L) .header("Authorization", "JWT AccessToken") .param("bestPlaceId", "1") ) @@ -104,7 +104,7 @@ void conclusionVote() throws Exception { // when// then mockMvc.perform( - MockMvcRequestBuilders.patch("/api/v1/group/{groupId}/vote", 1L) + MockMvcRequestBuilders.patch("/group/{groupId}/vote", 1L) .header("Authorization", "JWT AccessToken") ) .andDo(print()) diff --git a/src/test/java/com/moim/backend/domain/space/controller/GroupControllerTest.java b/src/test/java/com/moim/backend/domain/space/controller/GroupControllerTest.java index c131efa..d68952e 100644 --- a/src/test/java/com/moim/backend/domain/space/controller/GroupControllerTest.java +++ b/src/test/java/com/moim/backend/domain/space/controller/GroupControllerTest.java @@ -27,7 +27,7 @@ void createGroup() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group") + MockMvcRequestBuilders.post("/group") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -45,7 +45,7 @@ void createGroupBlankGroupNameException() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group") + MockMvcRequestBuilders.post("/group") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -63,7 +63,7 @@ void participationGroup() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group/participate") + MockMvcRequestBuilders.post("/group/participate") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -81,7 +81,7 @@ void participationGroupFailsWhenLatitudeNotProvided() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.post("/api/v1/group/participate") + MockMvcRequestBuilders.post("/group/participate") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -99,7 +99,7 @@ void participationUpdate() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.patch("/api/v1/group/participate") + MockMvcRequestBuilders.patch("/group/participate") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -117,7 +117,7 @@ void participationUpdateFailsWhenUserNameNotProvided() throws Exception { // when // then mockMvc.perform( - MockMvcRequestBuilders.patch("/api/v1/group/participate") + MockMvcRequestBuilders.patch("/group/participate") .header("Authorization", "JWT AccessToken") .content(objectMapper.writeValueAsString(request)) .contentType(MediaType.APPLICATION_JSON) @@ -132,7 +132,7 @@ void participationExit() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.delete("/api/v1/group/participate") + MockMvcRequestBuilders.delete("/group/participate") .header("Authorization", "JWT AccessToken") .param("participateId", String.valueOf(123L)) ) @@ -146,7 +146,7 @@ void failWhenParticipantIdNotProvided() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.delete("/api/v1/group/participate") + MockMvcRequestBuilders.delete("/group/participate") .header("Authorization", "JWT AccessToken") ) .andDo(print()) @@ -159,7 +159,7 @@ void participateRemoval() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.delete("/api/v1/group/participate/removal") + MockMvcRequestBuilders.delete("/group/participate/removal") .header("Authorization", "JWT AccessToken") .param("participateId", String.valueOf(1L)) ) @@ -173,7 +173,7 @@ void groupDelete() throws Exception { // given // when// then mockMvc.perform( - MockMvcRequestBuilders.delete("/api/v1/group") + MockMvcRequestBuilders.delete("/group") .header("Authorization", "JWT AccessToken") .param("groupId", String.valueOf(1L)) ) @@ -187,7 +187,7 @@ void getMyParticipate() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group/participate") + MockMvcRequestBuilders.get("/group/participate") .header("Authorization", "JWT AccessToken") ) .andDo(print()) @@ -200,7 +200,7 @@ void keywordCentralizedMeetingSpot() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group/best-region/place") + MockMvcRequestBuilders.get("/group/best-region/place") .param("x", "127.232943") .param("y", "37.6823811") .param("local", "성신여대입구역") @@ -216,7 +216,7 @@ void readParticipateGroupByRegion() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/api/v1/group") + MockMvcRequestBuilders.get("/group") .param("groupId", "1") ) .andDo(print()) From 748a1e588d70e27d53152046877adf0ce3f76a9e Mon Sep 17 00:00:00 2001 From: Hyun Woo Date: Mon, 21 Aug 2023 13:52:07 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix,=20test=20:=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B2=84=20API=20=EC=9D=91=EB=8B=B5=EC=9D=B4=20=EC=9C=A0?= =?UTF-8?q?=EB=8F=99=EC=A0=81=EC=9E=84=EC=97=90=20=EB=94=B0=EB=9D=BC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=EA=B0=80=20?= =?UTF-8?q?=EC=9C=A0=EC=97=B0=ED=95=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/service/GroupServiceTest.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java index fa88a56..41147d8 100644 --- a/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java +++ b/src/test/java/com/moim/backend/domain/space/service/GroupServiceTest.java @@ -513,21 +513,14 @@ void keywordCentralizedMeetingSpot() throws UnsupportedEncodingException { // then assertThat(response) - .extracting("title", "detail.x", "detail.y", "detail.homePageUrl", "distance") - .contains( - tuple("랠리쉬커피", "127.0166246", "37.5944971", "https://www.instagram.com/relishcoffee_", "성신여대입구역(으)로부터 192m"), - tuple("도쿄빙수 성신여대점", "127.0181725", "37.5920195", "https://instagram.com/tokyobingsu_sungshin?igshid=113a9wlh7mmb8", "성신여대입구역(으)로부터 150m"), - tuple("Los Dias", "127.0188944", "37.5901777", "http://pf.kakao.com/_cDqxixj", "성신여대입구역(으)로부터 344m"), - tuple("753 베이글 비스트로 성신여대점", "127.0200490", "37.5945812", "https://www.instagram.com/753_bagel_bistro", "성신여대입구역(으)로부터 354m"), - tuple("서울노마드", "127.0119483", "37.5915893", "http://instagram.com/seoulnomad_official", "성신여대입구역(으)로부터 442m"), - tuple("써리얼 벗 나이스", "127.0186908", "37.5945515", "https://www.instagram.com/surreal.b.nice", "성신여대입구역(으)로부터 262m"), - tuple("맬크", "127.0168510", "37.5950775", "https://www.instagram.com/melc.cake", "성신여대입구역(으)로부터 257m"), - tuple("루틴", "127.0201489", "37.5917147", "http://instagram.com/cafe.routine", "성신여대입구역(으)로부터 321m"), - tuple("더홈서울", "127.0174049", "37.5888662", "http://instagram.com/the_home_seoul", "성신여대입구역(으)로부터 437m"), - tuple("본크레페", "127.0183100", "37.5920357", "http://www.instagram.com/_bon_crepe_/", "성신여대입구역(으)로부터 159m"), - tuple("소설원 서가", "127.0099785", "37.5903636", "", "성신여대입구역(으)로부터 653m"), - tuple("모블러", "127.0204521", "37.5950653", "https://smartstore.naver.com/moblerpatisserie", "성신여대입구역(으)로부터 414m") - ); + .hasSize(12) + .allSatisfy(place -> { + assertThat(place.getTitle()).isNotNull(); + assertThat(place.getDetail().getX()).isNotNull(); + assertThat(place.getDetail().getY()).isNotNull(); + assertThat(place.getDetail().getAddress()).isNotNull(); + assertThat(place.getDistance()).isNotNull(); + }); } @DisplayName("유저가 해당 모임의 참여자 정보들을 조회한다.")