From f1c14026071cbdfc425c2e4c3884cd6184a9db9f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Fri, 16 Aug 2024 11:28:34 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[REFACTOR]=20=EB=8D=B0=EC=9D=BC=EB=A6=AC=20?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EB=8B=A4=EC=A4=91=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20data=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/MemberDailyRoutineControllerV2.java | 17 +++++++++----- .../MemberDailyRoutineControllerV2Docs.java | 4 ++-- .../MemberDailyRoutinesCreateResponse.java | 22 +++++++++++++++++++ .../service/MemberRoutineCreateService.java | 13 ++++++++--- ...berDailyRoutinesCreateServiceResponse.java | 22 +++++++++++++++++++ 5 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/soptie/server/memberroutine/controller/v2/dto/response/MemberDailyRoutinesCreateResponse.java create mode 100644 src/main/java/com/soptie/server/memberroutine/service/dto/response/MemberDailyRoutinesCreateServiceResponse.java diff --git a/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java b/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java index be78e330..a24a1c51 100644 --- a/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java +++ b/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java @@ -1,21 +1,24 @@ package com.soptie.server.memberroutine.controller.v2; -import static com.soptie.server.common.dto.SuccessResponse.*; -import static com.soptie.server.memberroutine.message.MemberRoutineSuccessMassage.*; +import static com.soptie.server.common.dto.SuccessResponse.success; +import static com.soptie.server.memberroutine.message.MemberRoutineSuccessMassage.SUCCESS_CREATE_ROUTINE; +import static com.soptie.server.memberroutine.message.MemberRoutineSuccessMassage.SUCCESS_GET_ROUTINE; import java.security.Principal; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import com.soptie.server.common.dto.BaseResponse; import com.soptie.server.common.dto.SuccessResponse; import com.soptie.server.memberroutine.controller.v1.dto.request.MemberDailyRoutinesCreateRequest; import com.soptie.server.memberroutine.controller.v2.docs.MemberDailyRoutineControllerV2Docs; import com.soptie.server.memberroutine.controller.v2.dto.response.MemberDailyRoutineListAcquireResponseV2; +import com.soptie.server.memberroutine.controller.v2.dto.response.MemberDailyRoutinesCreateResponse; import com.soptie.server.memberroutine.service.MemberRoutineCreateService; import com.soptie.server.memberroutine.service.MemberRoutineReadService; import com.soptie.server.memberroutine.service.dto.request.MemberDailyRoutineListAcquireServiceRequest; @@ -42,12 +45,14 @@ public ResponseEntity> } @PostMapping - public ResponseEntity createMemberDailyRoutines( + @ResponseStatus(HttpStatus.OK) + public SuccessResponse createMemberDailyRoutines( Principal principal, MemberDailyRoutinesCreateRequest request ) { val memberId = Long.parseLong(principal.getName()); - memberRoutineCreateService.createDailyRoutines(memberId, request); - return ResponseEntity.ok(SuccessResponse.success(SUCCESS_CREATE_ROUTINE.getMessage())); + val response = MemberDailyRoutinesCreateResponse + .of(memberRoutineCreateService.createDailyRoutines(memberId, request)); + return SuccessResponse.success(SUCCESS_CREATE_ROUTINE.getMessage(), response); } } diff --git a/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java b/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java index 403705e2..5895c663 100644 --- a/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java +++ b/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java @@ -5,11 +5,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; -import com.soptie.server.common.dto.BaseResponse; import com.soptie.server.common.dto.ErrorResponse; import com.soptie.server.common.dto.SuccessResponse; import com.soptie.server.memberroutine.controller.v1.dto.request.MemberDailyRoutinesCreateRequest; import com.soptie.server.memberroutine.controller.v2.dto.response.MemberDailyRoutineListAcquireResponseV2; +import com.soptie.server.memberroutine.controller.v2.dto.response.MemberDailyRoutinesCreateResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -64,7 +64,7 @@ ResponseEntity> acquire description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity createMemberDailyRoutines( + SuccessResponse createMemberDailyRoutines( @Parameter(hidden = true) Principal principal, @RequestBody MemberDailyRoutinesCreateRequest request ); diff --git a/src/main/java/com/soptie/server/memberroutine/controller/v2/dto/response/MemberDailyRoutinesCreateResponse.java b/src/main/java/com/soptie/server/memberroutine/controller/v2/dto/response/MemberDailyRoutinesCreateResponse.java new file mode 100644 index 00000000..7eeb31f9 --- /dev/null +++ b/src/main/java/com/soptie/server/memberroutine/controller/v2/dto/response/MemberDailyRoutinesCreateResponse.java @@ -0,0 +1,22 @@ +package com.soptie.server.memberroutine.controller.v2.dto.response; + +import static lombok.AccessLevel.PRIVATE; + +import java.util.List; + +import com.soptie.server.memberroutine.service.dto.response.MemberDailyRoutinesCreateServiceResponse; + +import lombok.Builder; +import lombok.NonNull; + +@Builder(access = PRIVATE) +public record MemberDailyRoutinesCreateResponse( + @NonNull List ids +) { + + public static MemberDailyRoutinesCreateResponse of(MemberDailyRoutinesCreateServiceResponse response) { + return MemberDailyRoutinesCreateResponse.builder() + .ids(response.ids()) + .build(); + } +} diff --git a/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java b/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java index b8d43bd6..1d4fa3ea 100644 --- a/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java +++ b/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java @@ -1,6 +1,7 @@ package com.soptie.server.memberroutine.service; -import static com.soptie.server.routine.message.RoutineErrorCode.*; +import static com.soptie.server.routine.message.RoutineErrorCode.CANNOT_ADD_MEMBER_ROUTINE; +import static com.soptie.server.routine.message.RoutineErrorCode.DUPLICATED_ROUTINE; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,6 +14,7 @@ import com.soptie.server.memberroutine.service.dto.request.MemberDailyRoutineCreateServiceRequest; import com.soptie.server.memberroutine.service.dto.request.MemberHappinessRoutineCreateServiceRequest; import com.soptie.server.memberroutine.service.dto.response.MemberDailyRoutineCreateServiceResponse; +import com.soptie.server.memberroutine.service.dto.response.MemberDailyRoutinesCreateServiceResponse; import com.soptie.server.memberroutine.service.dto.response.MemberHappinessRoutineCreateServiceResponse; import com.soptie.server.routine.adapter.ChallengeFinder; import com.soptie.server.routine.adapter.RoutineFinder; @@ -41,10 +43,15 @@ public MemberDailyRoutineCreateServiceResponse createDailyRoutine(MemberDailyRou return MemberDailyRoutineCreateServiceResponse.of(savedMemberRoutine); } - public void createDailyRoutines(long memberId, MemberDailyRoutinesCreateRequest request) { + public MemberDailyRoutinesCreateServiceResponse createDailyRoutines( + long memberId, MemberDailyRoutinesCreateRequest request + ) { val member = memberFinder.findById(memberId); val routines = routineFinder.findDailyByIds(request.routineIds()); - routines.forEach(routine -> memberRoutineSaver.checkHasDeletedAndSave(member, routine)); + val memberRoutines = routines.stream() + .map(routine -> memberRoutineSaver.checkHasDeletedAndSave(member, routine)) + .toList(); + return MemberDailyRoutinesCreateServiceResponse.of(memberRoutines); } public MemberHappinessRoutineCreateServiceResponse createHappinessRoutine( diff --git a/src/main/java/com/soptie/server/memberroutine/service/dto/response/MemberDailyRoutinesCreateServiceResponse.java b/src/main/java/com/soptie/server/memberroutine/service/dto/response/MemberDailyRoutinesCreateServiceResponse.java new file mode 100644 index 00000000..b049e092 --- /dev/null +++ b/src/main/java/com/soptie/server/memberroutine/service/dto/response/MemberDailyRoutinesCreateServiceResponse.java @@ -0,0 +1,22 @@ +package com.soptie.server.memberroutine.service.dto.response; + +import static lombok.AccessLevel.PRIVATE; + +import java.util.List; + +import com.soptie.server.memberroutine.entity.MemberRoutine; + +import lombok.Builder; +import lombok.NonNull; + +@Builder(access = PRIVATE) +public record MemberDailyRoutinesCreateServiceResponse( + @NonNull List ids +) { + + public static MemberDailyRoutinesCreateServiceResponse of(List memberRoutines) { + return MemberDailyRoutinesCreateServiceResponse.builder() + .ids(memberRoutines.stream().map(MemberRoutine::getId).toList()) + .build(); + } +} From 0498f2f5bedda5d1076fdc1ce159f9a8a079e81e Mon Sep 17 00:00:00 2001 From: Chan531 Date: Fri, 16 Aug 2024 11:28:53 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]=20=EB=A3=A8=ED=8B=B4=20=EC=A4=91?= =?UTF-8?q?=EB=B3=B5=20=EC=B6=94=EA=B0=80=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/memberroutine/service/MemberRoutineCreateService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java b/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java index 1d4fa3ea..79b137bb 100644 --- a/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java +++ b/src/main/java/com/soptie/server/memberroutine/service/MemberRoutineCreateService.java @@ -48,6 +48,7 @@ public MemberDailyRoutinesCreateServiceResponse createDailyRoutines( ) { val member = memberFinder.findById(memberId); val routines = routineFinder.findDailyByIds(request.routineIds()); + routines.forEach(routine -> checkMemberHasSameRoutineAlready(member, routine)); val memberRoutines = routines.stream() .map(routine -> memberRoutineSaver.checkHasDeletedAndSave(member, routine)) .toList(); From d2210315dbbff4536dfda7c68924c3f0e58d6943 Mon Sep 17 00:00:00 2001 From: Chan531 Date: Fri, 16 Aug 2024 13:32:41 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[CHORE]=20Http=20Status=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v2/MemberDailyRoutineControllerV2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java b/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java index a24a1c51..0c29580c 100644 --- a/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java +++ b/src/main/java/com/soptie/server/memberroutine/controller/v2/MemberDailyRoutineControllerV2.java @@ -45,7 +45,7 @@ public ResponseEntity> } @PostMapping - @ResponseStatus(HttpStatus.OK) + @ResponseStatus(HttpStatus.CREATED) public SuccessResponse createMemberDailyRoutines( Principal principal, MemberDailyRoutinesCreateRequest request From 6d62d3a10ec5290113d4ea577a0416ea4340038f Mon Sep 17 00:00:00 2001 From: Chan531 Date: Fri, 16 Aug 2024 13:33:59 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[CHORE]=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v2/docs/MemberDailyRoutineControllerV2Docs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java b/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java index 5895c663..39544f05 100644 --- a/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java +++ b/src/main/java/com/soptie/server/memberroutine/controller/v2/docs/MemberDailyRoutineControllerV2Docs.java @@ -48,7 +48,7 @@ ResponseEntity> acquire description = "회원의 데일리 루틴을 다중으로 추가한다.", responses = { @ApiResponse( - responseCode = "200", + responseCode = "201", description = "성공", content = @Content(schema = @Schema(implementation = SuccessResponse.class))), @ApiResponse(