From 927d5d88a4cc9bca66bfd381dfe74147b1953871 Mon Sep 17 00:00:00 2001 From: kunsanglee <85242378+kunsanglee@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:55:57 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20application.yml=20metrics=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#269)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/main/resources/application.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 175faf021..425a2c5a0 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -39,7 +39,7 @@ management: endpoints: web: exposure: - include: logfile + include: logfile, metrics logging: level: @@ -47,6 +47,11 @@ logging: org.springframework.web: debug server.haengdong: debug + file: + name: logs/spring-boot-application.log + path: logs + config: classpath:logback-spring.xml + server: servlet: encoding: From 18f132c78bd187757077932ca5673fcdbeac0744 Mon Sep 17 00:00:00 2001 From: Juhwan Kim <13selfesteem91@naver.com> Date: Fri, 9 Aug 2024 10:26:31 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20CI/CD=20=EC=88=99=EC=A0=9C=20(#290)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/server/haengdong/HaengdongApplication.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/server/haengdong/HaengdongApplication.java b/server/src/main/java/server/haengdong/HaengdongApplication.java index 31b6e46e7..0072a5a11 100644 --- a/server/src/main/java/server/haengdong/HaengdongApplication.java +++ b/server/src/main/java/server/haengdong/HaengdongApplication.java @@ -1,12 +1,15 @@ package server.haengdong; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +@Slf4j @SpringBootApplication public class HaengdongApplication { public static void main(String[] args) { + log.error("################### 안녕하세요. CI/CD 테스트입니다. ###################"); SpringApplication.run(HaengdongApplication.class, args); } From 97fc7fb6c0d783d6900e6566927aa7177f9b6dfc Mon Sep 17 00:00:00 2001 From: Juhwan Kim <13selfesteem91@naver.com> Date: Fri, 9 Aug 2024 10:38:06 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20CI/CD=20=EC=88=99=EC=A0=9C=20(#291)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/server/haengdong/presentation/EventController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 6c143b181..356d5216d 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -2,6 +2,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseCookie; @@ -23,6 +24,7 @@ import server.haengdong.presentation.response.MembersResponse; import server.haengdong.presentation.response.StepsResponse; +@Slf4j @RequiredArgsConstructor @EnableConfigurationProperties(CookieProperties.class) @RestController @@ -34,6 +36,8 @@ public class EventController { @PostMapping("/api/events") public ResponseEntity saveEvent(@Valid @RequestBody EventSaveRequest request) { + log.error("################### 안녕하세요. CI/CD 테스트입니다. ###################"); + EventResponse eventResponse = EventResponse.of(eventService.saveEvent(request.toAppRequest())); String jwtToken = authService.createToken(eventResponse.eventId()); From 1feb2d615789202b4b99de18ad63f604a8ad3561 Mon Sep 17 00:00:00 2001 From: Arachne <66822642+Arachneee@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:49:14 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=ED=96=89=EC=82=AC=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=20=EC=9D=B8=EC=9B=90=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20api=20=EC=88=98=EC=A0=95=20(#268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 회원 이름 변경 api 여러명으로 추가 * style: 메소드 순서 변경 --- server/src/docs/asciidoc/event.adoc | 11 +- .../haengdong/application/EventService.java | 51 +++++-- .../request/MemberNameUpdateAppRequest.java | 7 + .../request/MemberNamesUpdateAppRequest.java | 8 ++ .../request/MemberUpdateAppRequest.java | 4 - .../exception/HaengdongErrorCode.java | 1 + .../presentation/EventController.java | 9 +- .../request/MemberNameUpdateRequest.java | 18 +++ .../request/MemberNamesUpdateRequest.java | 16 +++ .../request/MemberUpdateRequest.java | 15 -- .../application/EventServiceTest.java | 78 ++++++++++- .../docs/EventControllerDocsTest.java | 130 +++++++++--------- .../presentation/EventControllerTest.java | 13 +- 13 files changed, 256 insertions(+), 105 deletions(-) create mode 100644 server/src/main/java/server/haengdong/application/request/MemberNameUpdateAppRequest.java create mode 100644 server/src/main/java/server/haengdong/application/request/MemberNamesUpdateAppRequest.java delete mode 100644 server/src/main/java/server/haengdong/application/request/MemberUpdateAppRequest.java create mode 100644 server/src/main/java/server/haengdong/presentation/request/MemberNameUpdateRequest.java create mode 100644 server/src/main/java/server/haengdong/presentation/request/MemberNamesUpdateRequest.java delete mode 100644 server/src/main/java/server/haengdong/presentation/request/MemberUpdateRequest.java diff --git a/server/src/docs/asciidoc/event.adoc b/server/src/docs/asciidoc/event.adoc index 253120e52..72511b91b 100644 --- a/server/src/docs/asciidoc/event.adoc +++ b/server/src/docs/asciidoc/event.adoc @@ -106,6 +106,15 @@ operation::updateEventMemberName[snippets="path-parameters,http-request,request- [source,json,options="nowrap"] ---- [ + + { + "code":"MEMBER_NAME_CHANGE_DUPLICATE", + "message":"중복된 참여 인원 이름 변경 요청이 존재합니다." + }, + { + "code":"MEMBER_NOT_EXIST", + "message":"현재 참여하고 있지 않는 인원이 존재합니다." + }, { "code":"REQUEST_EMPTY", "message":"멤버 이름은 공백일 수 없습니다." @@ -128,7 +137,7 @@ operation::updateEventMemberName[snippets="path-parameters,http-request,request- }, { "code":"TOKEN_EXPIRED", - "message":"토큰이 존재하지 않습니다." + "message":"만료된 토큰입니다." }, { "code":"TOKEN_INVALID", diff --git a/server/src/main/java/server/haengdong/application/EventService.java b/server/src/main/java/server/haengdong/application/EventService.java index 3408a6215..57109a721 100644 --- a/server/src/main/java/server/haengdong/application/EventService.java +++ b/server/src/main/java/server/haengdong/application/EventService.java @@ -3,12 +3,14 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import server.haengdong.application.request.EventAppRequest; import server.haengdong.application.request.EventLoginAppRequest; -import server.haengdong.application.request.MemberUpdateAppRequest; +import server.haengdong.application.request.MemberNameUpdateAppRequest; +import server.haengdong.application.request.MemberNamesUpdateAppRequest; import server.haengdong.application.response.ActionAppResponse; import server.haengdong.application.response.EventAppResponse; import server.haengdong.application.response.EventDetailAppResponse; @@ -100,22 +102,55 @@ public MembersAppResponse findAllMembers(String token) { } @Transactional - public void updateMember(String token, String memberName, MemberUpdateAppRequest request) { + public void updateMember(String token, MemberNamesUpdateAppRequest request) { Event event = getEvent(token); - String updatedMemberName = request.name(); - validateMemberNameUnique(event, updatedMemberName); + List members = request.members(); - memberActionRepository.findAllByAction_EventAndMemberName(event, memberName) - .forEach(memberAction -> memberAction.updateMemberName(updatedMemberName)); + validateBeforeNames(members, event); + validateAfterNames(members, event); + + members.forEach(member -> updateMemberName(event, member.before(), member.after())); + } + + private void validateBeforeNames(List members, Event event) { + List beforeNames = members.stream() + .map(MemberNameUpdateAppRequest::before) + .toList(); + if (beforeNames.size() != Set.copyOf(beforeNames).size()) { + throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_CHANGE_DUPLICATE); + } + beforeNames.forEach(beforeName -> validateBeforeMemberNameExist(event, beforeName)); + } + + private void validateBeforeMemberNameExist(Event event, String beforeName) { + boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, beforeName); + if (!isMemberNameExist) { + throw new HaengdongException(HaengdongErrorCode.MEMBER_NOT_EXIST); + } + } + + private void validateAfterNames(List members, Event event) { + List afterNames = members.stream() + .map(MemberNameUpdateAppRequest::after) + .toList(); + if (afterNames.size() != Set.copyOf(afterNames).size()) { + throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_CHANGE_DUPLICATE); + } + afterNames.forEach(afterName -> validateAfterMemberNameNotExist(event, afterName)); } - private void validateMemberNameUnique(Event event, String updatedMemberName) { - boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, updatedMemberName); + private void validateAfterMemberNameNotExist(Event event, String afterName) { + boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, afterName); if (isMemberNameExist) { throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_DUPLICATE); } } + private void updateMemberName(Event event, String beforeName, String afterName) { + memberActionRepository.findAllByAction_EventAndMemberName(event, beforeName) + .forEach(memberAction -> memberAction.updateMemberName(afterName)); + } + public void validatePassword(EventLoginAppRequest request) throws HaengdongException { Event event = getEvent(request.token()); if (event.isSamePassword(request.password())) { diff --git a/server/src/main/java/server/haengdong/application/request/MemberNameUpdateAppRequest.java b/server/src/main/java/server/haengdong/application/request/MemberNameUpdateAppRequest.java new file mode 100644 index 000000000..d629d3a02 --- /dev/null +++ b/server/src/main/java/server/haengdong/application/request/MemberNameUpdateAppRequest.java @@ -0,0 +1,7 @@ +package server.haengdong.application.request; + +public record MemberNameUpdateAppRequest( + String before, + String after +) { +} diff --git a/server/src/main/java/server/haengdong/application/request/MemberNamesUpdateAppRequest.java b/server/src/main/java/server/haengdong/application/request/MemberNamesUpdateAppRequest.java new file mode 100644 index 000000000..cd0c00544 --- /dev/null +++ b/server/src/main/java/server/haengdong/application/request/MemberNamesUpdateAppRequest.java @@ -0,0 +1,8 @@ +package server.haengdong.application.request; + +import java.util.List; + +public record MemberNamesUpdateAppRequest( + List members +) { +} diff --git a/server/src/main/java/server/haengdong/application/request/MemberUpdateAppRequest.java b/server/src/main/java/server/haengdong/application/request/MemberUpdateAppRequest.java deleted file mode 100644 index cbef9dda9..000000000 --- a/server/src/main/java/server/haengdong/application/request/MemberUpdateAppRequest.java +++ /dev/null @@ -1,4 +0,0 @@ -package server.haengdong.application.request; - -public record MemberUpdateAppRequest(String name) { -} diff --git a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java index bd0866d00..8af8d31e5 100644 --- a/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java +++ b/server/src/main/java/server/haengdong/exception/HaengdongErrorCode.java @@ -25,6 +25,7 @@ public enum HaengdongErrorCode { MEMBER_NAME_DUPLICATE("중복된 행사 참여 인원 이름이 존재합니다."), MEMBER_NOT_EXIST("현재 참여하고 있지 않는 인원이 존재합니다."), MEMBER_ALREADY_EXIST("현재 참여하고 있는 인원이 존재합니다."), + MEMBER_NAME_CHANGE_DUPLICATE("중복된 참여 인원 이름 변경 요청이 존재합니다."), MEMBER_ACTION_NOT_FOUND("존재하지 않는 멤버 액션입니다."), MEMBER_ACTION_STATUS_INVALID("멤버 액션은 IN, OUT만 가능합니다. 입력한 멤버 액션: %s"), diff --git a/server/src/main/java/server/haengdong/presentation/EventController.java b/server/src/main/java/server/haengdong/presentation/EventController.java index 356d5216d..bbca6aa51 100644 --- a/server/src/main/java/server/haengdong/presentation/EventController.java +++ b/server/src/main/java/server/haengdong/presentation/EventController.java @@ -18,7 +18,7 @@ import server.haengdong.infrastructure.auth.CookieProperties; import server.haengdong.presentation.request.EventLoginRequest; import server.haengdong.presentation.request.EventSaveRequest; -import server.haengdong.presentation.request.MemberUpdateRequest; +import server.haengdong.presentation.request.MemberNamesUpdateRequest; import server.haengdong.presentation.response.EventDetailResponse; import server.haengdong.presentation.response.EventResponse; import server.haengdong.presentation.response.MembersResponse; @@ -69,13 +69,12 @@ public ResponseEntity findAllMembers(@PathVariable("eventId") S return ResponseEntity.ok(response); } - @PutMapping("/api/events/{eventId}/members/{memberName}") + @PutMapping("/api/events/{eventId}/members/nameChange") public ResponseEntity updateMember( @PathVariable("eventId") String token, - @PathVariable("memberName") String memberName, - @Valid @RequestBody MemberUpdateRequest request + @Valid @RequestBody MemberNamesUpdateRequest request ) { - eventService.updateMember(token, memberName, request.toAppRequest()); + eventService.updateMember(token, request.toAppRequest()); return ResponseEntity.ok().build(); } diff --git a/server/src/main/java/server/haengdong/presentation/request/MemberNameUpdateRequest.java b/server/src/main/java/server/haengdong/presentation/request/MemberNameUpdateRequest.java new file mode 100644 index 000000000..3cd2294ca --- /dev/null +++ b/server/src/main/java/server/haengdong/presentation/request/MemberNameUpdateRequest.java @@ -0,0 +1,18 @@ +package server.haengdong.presentation.request; + +import jakarta.validation.constraints.NotBlank; +import server.haengdong.application.request.MemberNameUpdateAppRequest; + +public record MemberNameUpdateRequest( + + @NotBlank(message = "멤버 이름은 공백일 수 없습니다.") + String before, + + @NotBlank(message = "멤버 이름은 공백일 수 없습니다.") + String after +) { + + public MemberNameUpdateAppRequest toAppRequest() { + return new MemberNameUpdateAppRequest(before, after); + } +} diff --git a/server/src/main/java/server/haengdong/presentation/request/MemberNamesUpdateRequest.java b/server/src/main/java/server/haengdong/presentation/request/MemberNamesUpdateRequest.java new file mode 100644 index 000000000..c67e1b699 --- /dev/null +++ b/server/src/main/java/server/haengdong/presentation/request/MemberNamesUpdateRequest.java @@ -0,0 +1,16 @@ +package server.haengdong.presentation.request; + +import jakarta.validation.Valid; +import java.util.List; +import server.haengdong.application.request.MemberNamesUpdateAppRequest; + +public record MemberNamesUpdateRequest( + @Valid List members +) { + + public MemberNamesUpdateAppRequest toAppRequest() { + return new MemberNamesUpdateAppRequest(members.stream() + .map(MemberNameUpdateRequest::toAppRequest) + .toList()); + } +} diff --git a/server/src/main/java/server/haengdong/presentation/request/MemberUpdateRequest.java b/server/src/main/java/server/haengdong/presentation/request/MemberUpdateRequest.java deleted file mode 100644 index 412457750..000000000 --- a/server/src/main/java/server/haengdong/presentation/request/MemberUpdateRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package server.haengdong.presentation.request; - -import jakarta.validation.constraints.NotBlank; -import server.haengdong.application.request.MemberUpdateAppRequest; - -public record MemberUpdateRequest( - - @NotBlank(message = "멤버 이름은 공백일 수 없습니다.") - String name -) { - - public MemberUpdateAppRequest toAppRequest() { - return new MemberUpdateAppRequest(name); - } -} diff --git a/server/src/test/java/server/haengdong/application/EventServiceTest.java b/server/src/test/java/server/haengdong/application/EventServiceTest.java index f5694efa1..407fa1457 100644 --- a/server/src/test/java/server/haengdong/application/EventServiceTest.java +++ b/server/src/test/java/server/haengdong/application/EventServiceTest.java @@ -14,7 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import server.haengdong.application.request.EventAppRequest; -import server.haengdong.application.request.MemberUpdateAppRequest; +import server.haengdong.application.request.MemberNameUpdateAppRequest; +import server.haengdong.application.request.MemberNamesUpdateAppRequest; import server.haengdong.application.response.ActionAppResponse; import server.haengdong.application.response.EventAppResponse; import server.haengdong.application.response.EventDetailAppResponse; @@ -119,7 +120,7 @@ void findAllMembersTest() { assertThat(membersAppResponse.memberNames()).containsExactlyInAnyOrder("토다리", "쿠키"); } - @DisplayName("행사 참여 인원의 이름을 변경한다.") + @DisplayName("행사 참여 인원들의 이름을 변경한다.") @Test void updateMember() { Event event = Fixture.EVENT1; @@ -134,13 +135,16 @@ void updateMember() { memberAction1, memberAction2, memberAction3, memberAction4, memberAction5, memberAction6 )); - eventService.updateMember(event.getToken(), "쿠키", new MemberUpdateAppRequest("쿡쿡")); + eventService.updateMember(event.getToken(), new MemberNamesUpdateAppRequest(List.of( + new MemberNameUpdateAppRequest("쿠키", "쿡쿡"), + new MemberNameUpdateAppRequest("토다리", "토쟁이") + ))); List foundMemberActions = memberActionRepository.findAllByEvent(event); assertThat(foundMemberActions) .extracting(MemberAction::getId, MemberAction::getMemberName) .contains( - tuple(memberAction1.getId(), "토다리"), + tuple(memberAction1.getId(), "토쟁이"), tuple(memberAction2.getId(), "쿡쿡"), tuple(memberAction3.getId(), "웨디"), tuple(memberAction4.getId(), "쿡쿡"), @@ -149,7 +153,7 @@ void updateMember() { ); } - @DisplayName("참여 인원 이름을 이미 존재하는 행사 참여 인원과 동일한 이름으로 변경할 수 없다.") + @DisplayName("이미 존재하는 인원의 이름으로 변경할 수 없다.") @Test void updateMember1() { Event event = Fixture.EVENT1; @@ -159,7 +163,69 @@ void updateMember1() { eventRepository.save(event); memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); - assertThatThrownBy(() -> eventService.updateMember(event.getToken(), "쿠키", new MemberUpdateAppRequest("토다리"))) + MemberNamesUpdateAppRequest appRequest = new MemberNamesUpdateAppRequest(List.of( + new MemberNameUpdateAppRequest("쿠키", "쿡쿡"), + new MemberNameUpdateAppRequest("웨디", "토다리") + )); + + assertThatThrownBy(() -> eventService.updateMember(event.getToken(), appRequest)) + .isInstanceOf(HaengdongException.class); + } + + @DisplayName("존재하지 않는 인원은 변경할 수 없다.") + @Test + void updateMember2() { + Event event = Fixture.EVENT1; + MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); + MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); + MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + eventRepository.save(event); + memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); + + MemberNamesUpdateAppRequest appRequest = new MemberNamesUpdateAppRequest(List.of( + new MemberNameUpdateAppRequest("쿡쿡", "토쟁이"), + new MemberNameUpdateAppRequest("웨디", "말복") + )); + + assertThatThrownBy(() -> eventService.updateMember(event.getToken(), appRequest)) + .isInstanceOf(HaengdongException.class); + } + + @DisplayName("변경 전 참여 인원 이름이 중복될 수 없다.") + @Test + void updateMember3() { + Event event = Fixture.EVENT1; + MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); + MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); + MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + eventRepository.save(event); + memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); + + MemberNamesUpdateAppRequest appRequest = new MemberNamesUpdateAppRequest(List.of( + new MemberNameUpdateAppRequest("쿠키", "쿡쿡"), + new MemberNameUpdateAppRequest("쿠키", "토쟁이") + )); + + assertThatThrownBy(() -> eventService.updateMember(event.getToken(), appRequest)) + .isInstanceOf(HaengdongException.class); + } + + @DisplayName("변경 후 참여 인원 이름이 중복될 수 없다.") + @Test + void updateMember4() { + Event event = Fixture.EVENT1; + MemberAction memberAction1 = new MemberAction(new Action(event, 1L), "토다리", IN, 1L); + MemberAction memberAction2 = new MemberAction(new Action(event, 2L), "쿠키", IN, 1L); + MemberAction memberAction3 = new MemberAction(new Action(event, 3L), "웨디", IN, 2L); + eventRepository.save(event); + memberActionRepository.saveAll(List.of(memberAction1, memberAction2, memberAction3)); + + MemberNamesUpdateAppRequest appRequest = new MemberNamesUpdateAppRequest(List.of( + new MemberNameUpdateAppRequest("쿠키", "쿡쿡"), + new MemberNameUpdateAppRequest("토다리", "쿡쿡") + )); + + assertThatThrownBy(() -> eventService.updateMember(event.getToken(), appRequest)) .isInstanceOf(HaengdongException.class); } } diff --git a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java index 67095aae9..fef6ce106 100644 --- a/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java +++ b/server/src/test/java/server/haengdong/docs/EventControllerDocsTest.java @@ -44,7 +44,8 @@ import server.haengdong.presentation.EventController; import server.haengdong.presentation.request.EventLoginRequest; import server.haengdong.presentation.request.EventSaveRequest; -import server.haengdong.presentation.request.MemberUpdateRequest; +import server.haengdong.presentation.request.MemberNameUpdateRequest; +import server.haengdong.presentation.request.MemberNamesUpdateRequest; public class EventControllerDocsTest extends RestDocsSupport { @@ -135,15 +136,15 @@ void findAllMembersTest() throws Exception { .andExpect(jsonPath("$.memberNames[1]").value("쿠키")) .andDo( document("findAllEventMember", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - pathParameters( - parameterWithName("eventId").description("행사 ID") - ), - responseFields( - fieldWithPath("memberNames").type(JsonFieldType.ARRAY) - .description("행사 참여자 목록") - ) + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + pathParameters( + parameterWithName("eventId").description("행사 ID") + ), + responseFields( + fieldWithPath("memberNames").type(JsonFieldType.ARRAY) + .description("행사 참여자 목록") + ) ) ); } @@ -152,29 +153,34 @@ void findAllMembersTest() throws Exception { @Test void updateMember() throws Exception { String token = "TOKEN"; - MemberUpdateRequest memberUpdateRequest = new MemberUpdateRequest("변경된 이름"); - String requestBody = objectMapper.writeValueAsString(memberUpdateRequest); + MemberNamesUpdateRequest memberNameUpdateRequest = new MemberNamesUpdateRequest(List.of( + new MemberNameUpdateRequest("토다링", "토쟁이"), + new MemberNameUpdateRequest("감자", "고구마") + )); - mockMvc.perform(put("/api/events/{eventId}/members/{memberName}", token, "변경 전 이름") - .cookie(EVENT_COOKIE) - .contentType(MediaType.APPLICATION_JSON) - .content(requestBody)) + String requestBody = objectMapper.writeValueAsString(memberNameUpdateRequest); + + mockMvc.perform(put("/api/events/{eventId}/members/nameChange", token) + .cookie(EVENT_COOKIE) + .contentType(MediaType.APPLICATION_JSON) + .content(requestBody)) .andDo(print()) .andExpect(status().isOk()) .andDo( document("updateEventMemberName", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - pathParameters( - parameterWithName("eventId").description("행사 ID"), - parameterWithName("memberName").description("참여자 이름") - ), - requestCookies( - cookieWithName("eventToken").description("행사 관리자 토큰") - ), - requestFields( - fieldWithPath("name").type(JsonFieldType.STRING).description("수정할 참여자 이름") - ) + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + pathParameters( + parameterWithName("eventId").description("행사 ID") + ), + requestCookies( + cookieWithName("eventToken").description("행사 관리자 토큰") + ), + requestFields( + fieldWithPath("members").type(JsonFieldType.ARRAY).description("수정할 참여자 목록"), + fieldWithPath("members[].before").type(JsonFieldType.STRING).description("수정 전 참여자 이름"), + fieldWithPath("members[].after").type(JsonFieldType.STRING).description("수정 후 참여자 이름") + ) ) ); } @@ -189,25 +195,25 @@ void loginEvent() throws Exception { given(authService.getTokenName()).willReturn("eventToken"); mockMvc.perform(post("/api/events/{eventId}/login", token) - .contentType(MediaType.APPLICATION_JSON) - .content(requestBody)) + .contentType(MediaType.APPLICATION_JSON) + .content(requestBody)) .andDo(print()) .andExpect(cookie().value("eventToken", "jwtToken")) .andExpect(status().isOk()) .andDo( document("eventLogin", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - pathParameters( - parameterWithName("eventId").description("행사 ID") - ), - requestFields( - fieldWithPath("password").type(JsonFieldType.STRING) - .description("행사 비밀 번호") - ), - responseCookies( - cookieWithName("eventToken").description("행사 관리자용 토큰") - ) + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + pathParameters( + parameterWithName("eventId").description("행사 ID") + ), + requestFields( + fieldWithPath("password").type(JsonFieldType.STRING) + .description("행사 비밀 번호") + ), + responseCookies( + cookieWithName("eventToken").description("행사 관리자용 토큰") + ) ) ); } @@ -225,7 +231,7 @@ void findActions() throws Exception { given(eventService.findActions(token)).willReturn(actionAppResponses); mockMvc.perform(get("/api/events/{eventId}/actions", token) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.steps[0].type").value(equalTo("IN"))) @@ -255,25 +261,25 @@ void findActions() throws Exception { .andDo( document("findActions", - preprocessRequest(prettyPrint()), - preprocessResponse(prettyPrint()), - pathParameters( - parameterWithName("eventId").description("행사 ID") - ), - responseFields( - fieldWithPath("steps[].type").type(JsonFieldType.STRING) - .description("액션 유형 [BILL, IN, OUT]"), - fieldWithPath("steps[].members").type(JsonFieldType.ARRAY) - .description("해당 step에 참여한 참여자 목록"), - fieldWithPath("steps[].actions[].actionId").type(JsonFieldType.NUMBER) - .description("액션 ID"), - fieldWithPath("steps[].actions[].name").type(JsonFieldType.STRING) - .description("참여자 액션일 경우 참여자 이름, 지출 액션일 경우 지출 내역 이름"), - fieldWithPath("steps[].actions[].price").type(JsonFieldType.NUMBER).optional() - .description("참여자 액션일 경우 null, 지출 액션일 경우 지출 금액"), - fieldWithPath("steps[].actions[].sequence").type(JsonFieldType.NUMBER) - .description("액션 순서") - ) + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + pathParameters( + parameterWithName("eventId").description("행사 ID") + ), + responseFields( + fieldWithPath("steps[].type").type(JsonFieldType.STRING) + .description("액션 유형 [BILL, IN, OUT]"), + fieldWithPath("steps[].members").type(JsonFieldType.ARRAY) + .description("해당 step에 참여한 참여자 목록"), + fieldWithPath("steps[].actions[].actionId").type(JsonFieldType.NUMBER) + .description("액션 ID"), + fieldWithPath("steps[].actions[].name").type(JsonFieldType.STRING) + .description("참여자 액션일 경우 참여자 이름, 지출 액션일 경우 지출 내역 이름"), + fieldWithPath("steps[].actions[].price").type(JsonFieldType.NUMBER).optional() + .description("참여자 액션일 경우 null, 지출 액션일 경우 지출 금액"), + fieldWithPath("steps[].actions[].sequence").type(JsonFieldType.NUMBER) + .description("액션 순서") + ) ) ); } diff --git a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java index 4ba7bc4a9..fcfe48d01 100644 --- a/server/src/test/java/server/haengdong/presentation/EventControllerTest.java +++ b/server/src/test/java/server/haengdong/presentation/EventControllerTest.java @@ -21,7 +21,8 @@ import server.haengdong.application.response.MembersAppResponse; import server.haengdong.presentation.request.EventLoginRequest; import server.haengdong.presentation.request.EventSaveRequest; -import server.haengdong.presentation.request.MemberUpdateRequest; +import server.haengdong.presentation.request.MemberNameUpdateRequest; +import server.haengdong.presentation.request.MemberNamesUpdateRequest; class EventControllerTest extends ControllerTestSupport { @@ -77,10 +78,14 @@ void findAllMembersTest() throws Exception { @Test void updateMember() throws Exception { String token = "TOKEN"; - MemberUpdateRequest memberUpdateRequest = new MemberUpdateRequest("변경된 이름"); - String requestBody = objectMapper.writeValueAsString(memberUpdateRequest); + MemberNamesUpdateRequest memberNameUpdateRequest = new MemberNamesUpdateRequest(List.of( + new MemberNameUpdateRequest("토다링", "토쟁이"), + new MemberNameUpdateRequest("감자", "고구마") + )); - mockMvc.perform(put("/api/events/{eventId}/members/{memberName}", token, "변경 전 이름") + String requestBody = objectMapper.writeValueAsString(memberNameUpdateRequest); + + mockMvc.perform(put("/api/events/{eventId}/members/nameChange", token) .contentType(MediaType.APPLICATION_JSON) .content(requestBody)) .andDo(print())