From 89dfc14fa58db5f5c8c70c87343c77845fe3bc6f Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Thu, 14 Nov 2024 02:54:10 +0900 Subject: [PATCH 1/4] =?UTF-8?q?#119=20[feat]=20:=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EB=AA=A9=EC=9D=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/side/onetime/domain/Event.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/side/onetime/domain/Event.java b/src/main/java/side/onetime/domain/Event.java index b14ed97..24793c7 100644 --- a/src/main/java/side/onetime/domain/Event.java +++ b/src/main/java/side/onetime/domain/Event.java @@ -55,4 +55,8 @@ public Event(UUID eventId, String title, String startTime, String endTime, Categ this.endTime = endTime; this.category = category; } + + public void updateTitle(String title) { + this.title = title; + } } \ No newline at end of file From ace836b37e8a0c965242d7227877074c113d5e10 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Thu, 14 Nov 2024 02:55:04 +0900 Subject: [PATCH 2/4] =?UTF-8?q?#119=20[feat]=20:=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EA=B0=80=20=ED=95=B4=EB=8B=B9=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EC=9D=98=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=9D=B8=EC=A7=80=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/side/onetime/service/EventService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/side/onetime/service/EventService.java b/src/main/java/side/onetime/service/EventService.java index c51fab1..cdbc667 100644 --- a/src/main/java/side/onetime/service/EventService.java +++ b/src/main/java/side/onetime/service/EventService.java @@ -7,6 +7,7 @@ import side.onetime.domain.enums.Category; import side.onetime.domain.enums.EventStatus; import side.onetime.dto.event.request.CreateEventRequest; +import side.onetime.dto.event.request.ModifyUserCreatedEventTitleRequest; import side.onetime.dto.event.response.*; import side.onetime.exception.CustomException; import side.onetime.exception.status.EventErrorStatus; @@ -305,6 +306,19 @@ public List getUserParticipatedEvents(String // 유저가 생성한 이벤트 삭제 메서드 @Transactional public void removeUserCreatedEvent(String authorizationHeader, String eventId) { + EventParticipation eventParticipation = verifyUserIsEventCreator(authorizationHeader, eventId); + eventRepository.deleteEvent(eventParticipation.getEvent()); + } + + // 유저가 생성한 이벤트 제목 수정 메서드 + @Transactional + public void modifyUserCreatedEventTitle(String authorizationHeader, String eventId, ModifyUserCreatedEventTitleRequest modifyUserCreatedEventTitleRequest) { + EventParticipation eventParticipation = verifyUserIsEventCreator(authorizationHeader, eventId); + eventParticipation.getEvent().updateTitle(modifyUserCreatedEventTitleRequest.title()); + } + + // 유저가 이벤트의 생성자인지 검증하는 메서드 + private EventParticipation verifyUserIsEventCreator(String authorizationHeader, String eventId) { User user = jwtUtil.getUserFromHeader(authorizationHeader); Event event = eventRepository.findByEventId(UUID.fromString(eventId)) .orElseThrow(() -> new CustomException(EventErrorStatus._NOT_FOUND_EVENT)); @@ -314,10 +328,9 @@ public void removeUserCreatedEvent(String authorizationHeader, String eventId) { throw new CustomException(EventParticipationErrorStatus._NOT_FOUND_EVENT_PARTICIPATION); } if (!EventStatus.CREATOR.equals(eventParticipation.getEventStatus())) { - // 해당 이벤트의 생성자가 아닌 경우 throw new CustomException(EventParticipationErrorStatus._IS_NOT_USERS_CREATED_EVENT_PARTICIPATION); } - eventRepository.deleteEvent(event); + return eventParticipation; } } \ No newline at end of file From 3122be0409c87e7a3c5cd95c2b012afeb4a16cbb Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Thu, 14 Nov 2024 02:55:43 +0900 Subject: [PATCH 3/4] =?UTF-8?q?#119=20[feat]=20:=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EB=8A=94=20=EC=83=9D=EC=84=B1=ED=95=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EB=AA=A9=EC=9D=84=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onetime/controller/EventController.java | 21 +++++++++++++++++++ .../ModifyUserCreatedEventTitleRequest.java | 13 ++++++++++++ .../global/common/status/SuccessStatus.java | 1 + 3 files changed, 35 insertions(+) create mode 100644 src/main/java/side/onetime/dto/event/request/ModifyUserCreatedEventTitleRequest.java diff --git a/src/main/java/side/onetime/controller/EventController.java b/src/main/java/side/onetime/controller/EventController.java index 921235d..f88ee8a 100644 --- a/src/main/java/side/onetime/controller/EventController.java +++ b/src/main/java/side/onetime/controller/EventController.java @@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import side.onetime.dto.event.request.CreateEventRequest; +import side.onetime.dto.event.request.ModifyUserCreatedEventTitleRequest; import side.onetime.dto.event.response.*; import side.onetime.global.common.ApiResponse; import side.onetime.global.common.status.SuccessStatus; @@ -128,4 +129,24 @@ public ResponseEntity> removeUserCreatedEvent( eventService.removeUserCreatedEvent(authorizationHeader, eventId); return ApiResponse.onSuccess(SuccessStatus._REMOVE_USER_CREATED_EVENT); } + + /** + * 유저가 생성한 이벤트 제목 수정 API + * + * 이 API는 인증된 유저가 생성한 특정 이벤트의 제목을 수정합니다. + * + * @param authorizationHeader 인증된 유저의 토큰 + * @param eventId 제목을 수정할 이벤트의 ID + * @param modifyUserCreatedEventTitleRequest 새로운 제목 정보가 담긴 요청 데이터 + * @return 수정 성공 여부 + */ + @PutMapping("/{event_id}") + public ResponseEntity> modifyUserCreatedEventTitle( + @RequestHeader("Authorization") String authorizationHeader, + @PathVariable("event_id") String eventId, + @Valid @RequestBody ModifyUserCreatedEventTitleRequest modifyUserCreatedEventTitleRequest) { + + eventService.modifyUserCreatedEventTitle(authorizationHeader, eventId, modifyUserCreatedEventTitleRequest); + return ApiResponse.onSuccess(SuccessStatus._MODIFY_USER_CREATED_EVENT_TITLE); + } } \ No newline at end of file diff --git a/src/main/java/side/onetime/dto/event/request/ModifyUserCreatedEventTitleRequest.java b/src/main/java/side/onetime/dto/event/request/ModifyUserCreatedEventTitleRequest.java new file mode 100644 index 0000000..6cf98e6 --- /dev/null +++ b/src/main/java/side/onetime/dto/event/request/ModifyUserCreatedEventTitleRequest.java @@ -0,0 +1,13 @@ +package side.onetime.dto.event.request; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import jakarta.validation.constraints.NotBlank; + +@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record ModifyUserCreatedEventTitleRequest( + @NotBlank(message = "변경할 제목은 필수 값입니다.") String title +) { +} \ No newline at end of file diff --git a/src/main/java/side/onetime/global/common/status/SuccessStatus.java b/src/main/java/side/onetime/global/common/status/SuccessStatus.java index c139209..a649526 100644 --- a/src/main/java/side/onetime/global/common/status/SuccessStatus.java +++ b/src/main/java/side/onetime/global/common/status/SuccessStatus.java @@ -19,6 +19,7 @@ public enum SuccessStatus implements BaseCode { _GET_MOST_POSSIBLE_TIME(HttpStatus.OK, "200", "가장 많이 되는 시간 조회에 성공했습니다."), _GET_USER_PARTICIPATED_EVENTS(HttpStatus.OK, "200", "유저 참여 이벤트 목록 조회에 성공했습니다."), _REMOVE_USER_CREATED_EVENT(HttpStatus.OK, "200", "유저가 생성한 이벤트 삭제에 성공했습니다."), + _MODIFY_USER_CREATED_EVENT_TITLE(HttpStatus.OK, "200", "유저가 생성한 이벤트 제목 수정에 성공했습니다."), // Member _REGISTER_MEMBER(HttpStatus.CREATED, "201", "멤버 등록에 성공했습니다."), _LOGIN_MEMBER(HttpStatus.OK, "200", "멤버 로그인에 성공했습니다."), From f080ed98c14135dbbcd0512a1d9dbcbc3e1aa304 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Thu, 14 Nov 2024 02:59:59 +0900 Subject: [PATCH 4/4] =?UTF-8?q?#119=20[feat]=20:=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EB=AA=A9=20=EC=88=98=EC=A0=95=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=ED=95=98=EC=97=AC=20=EB=AC=B8=EC=84=9C=ED=99=94?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onetime/event/EventControllerTest.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/test/java/side/onetime/event/EventControllerTest.java b/src/test/java/side/onetime/event/EventControllerTest.java index e7f1d4f..0dd9f82 100644 --- a/src/test/java/side/onetime/event/EventControllerTest.java +++ b/src/test/java/side/onetime/event/EventControllerTest.java @@ -19,6 +19,7 @@ import side.onetime.domain.enums.Category; import side.onetime.domain.enums.EventStatus; import side.onetime.dto.event.request.CreateEventRequest; +import side.onetime.dto.event.request.ModifyUserCreatedEventTitleRequest; import side.onetime.dto.event.response.*; import side.onetime.service.EventService; import side.onetime.util.JwtUtil; @@ -385,4 +386,54 @@ public void removeUserCreatedEvent() throws Exception { ) )); } -} + + @Test + @DisplayName("유저가 생성한 이벤트 제목을 수정한다.") + public void modifyUserCreatedEventTitle() throws Exception { + // given + String eventId = UUID.randomUUID().toString(); + ModifyUserCreatedEventTitleRequest request = new ModifyUserCreatedEventTitleRequest("수정할 이벤트 제목"); + + String requestContent = new ObjectMapper().writeValueAsString(request); + + Mockito.doNothing().when(eventService).modifyUserCreatedEventTitle(anyString(), anyString(), any(ModifyUserCreatedEventTitleRequest.class)); + + // when + ResultActions resultActions = this.mockMvc.perform(RestDocumentationRequestBuilders.put("/api/v1/events/{event_id}", eventId) + .header(HttpHeaders.AUTHORIZATION, "Bearer sampleToken") + .contentType(MediaType.APPLICATION_JSON) + .content(requestContent) + .accept(MediaType.APPLICATION_JSON)); + + // then + resultActions + .andExpect(status().isOk()) + .andExpect(jsonPath("$.is_success").value(true)) + .andExpect(jsonPath("$.code").value("200")) + .andExpect(jsonPath("$.message").value("유저가 생성한 이벤트 제목 수정에 성공했습니다.")) + + // docs + .andDo(MockMvcRestDocumentationWrapper.document("event/modify-user-created-event-title", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + resource( + ResourceSnippetParameters.builder() + .tag("Event API") + .description("유저가 생성한 이벤트 제목을 수정한다.") + .pathParameters( + parameterWithName("event_id").description("수정할 이벤트의 ID [예시 : dd099816-2b09-4625-bf95-319672c25659]") + ) + .requestFields( + fieldWithPath("title").type(JsonFieldType.STRING).description("새로운 이벤트 제목") + ) + .responseFields( + fieldWithPath("is_success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("code").type(JsonFieldType.STRING).description("응답 코드"), + fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지") + ) + .responseSchema(Schema.schema("ModifyUserCreatedEventTitleResponseSchema")) + .build() + ) + )); + } +} \ No newline at end of file