From aa5f768f1aa9b6a03e593e106231beff7df0cf80 Mon Sep 17 00:00:00 2001 From: uhyunglee Date: Wed, 5 Jun 2024 20:14:14 +0900 Subject: [PATCH 1/5] [Log] Logging User Domain --- .../commonplant/domain/oauth/controller/OAuthController.java | 2 ++ .../commonplant/domain/user/controller/UserController.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java index 4ea2098..2bf8eb9 100644 --- a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java +++ b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java @@ -22,6 +22,7 @@ public class OAuthController implements OAuthSwagger{ @GetMapping("/login/{provider}") public ResponseEntity login(@RequestParam("accessToken") String accessToken, @PathVariable String provider){ + log.info("[API] Social Login"); log.info("accessToken : " + accessToken); String token = oAuthService.oAuthLogin(accessToken, provider); String email = oAuthService.kakaoLogin(accessToken); @@ -34,6 +35,7 @@ public ResponseEntity login(@RequestParam("accessToken") String ac @GetMapping("/api/token") public ResponseEntity validToken(){ + log.info("[API] Validate Token"); String token = jwtService.getJwt(); boolean isValid = jwtService.validateToken(token); diff --git a/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java b/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java index 59e43c1..d1b0cca 100644 --- a/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java +++ b/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java @@ -21,19 +21,21 @@ public class UserController implements UserSwagger{ @PostMapping(value = "/user", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) //join public ResponseEntity join(@RequestPart("user") UserDto.join req, @RequestParam(value ="image", required = false)MultipartFile image){ - log.info("join"); + log.info("[API] Join User"); String token = userService.joinUser(req, image); return ResponseEntity.ok(new JsonResponse(true, 200, "join", token)); } @GetMapping("/user/{name}") // 회원정보 조회 public ResponseEntity getUserByName(@PathVariable String name){ + log.info("[API] Get User Info"); User user = userService.getUserByName(name); return ResponseEntity.ok(new JsonResponse(true, 200, "getUser", user)); } @GetMapping("/user/{name}/exists") public ResponseEntity checkNameDuplicate(@PathVariable String name){ + log.info("[API] Check Duplicated Name"); boolean checkName = userService.checkNameDuplication(name); return ResponseEntity.ok(new JsonResponse(true, 200, "사용가능한 이름입니다.", checkName)); From f31e0658408dfe590f9feb13cd09aa4d0a06b075 Mon Sep 17 00:00:00 2001 From: sonshn Date: Wed, 19 Jun 2024 17:03:00 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Chore]=20Plant=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=EC=97=90=20Log=20Message=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plant/controller/PlantController.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java b/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java index 9af3aaa..299140a 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java +++ b/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java @@ -28,12 +28,13 @@ public class PlantController implements PlantSwagger { /** * [POST] 식물 추가 - * [POST] /plant/add * @return 추가한 식물의 애칭 */ @PostMapping(value = "/plant/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity createPlant(@RequestPart("plant") PlantDto.createPlantReq createPlantReq, @RequestPart("image") MultipartFile file) { + log.info("[API] createPlant - 식물 추가"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -48,6 +49,8 @@ public ResponseEntity createPlant(@RequestPart("plant") PlantDto.c */ @GetMapping("/plant/{plantIdx}") public ResponseEntity getPlantCard(@PathVariable Long plantIdx) { + log.info("[API]: getPlantCard - 식물 조회"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -63,6 +66,8 @@ public ResponseEntity getPlantCard(@PathVariable Long plantIdx) { */ @GetMapping("/user/plantList") public ResponseEntity getPlantList() { + log.info("[API]: getPlantList - 같은 사람이 키우는 식물 리스트 조회"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -96,6 +101,8 @@ public ResponseEntity getPlantList() { */ @PutMapping("/plant/update/wateredDate/{plantIdx}") public ResponseEntity updateWateredDate(@PathVariable Long plantIdx){ + log.info("[API]: updateWateredDate - 식물의 D-Day 업데이트"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -105,11 +112,13 @@ public ResponseEntity updateWateredDate(@PathVariable Long plantId } /** - * [GET] /plant/update + * [GET] 식물을 수정할 때 뜨는 조회 화면 * @return 수정하기 전 식물의 정보 */ @GetMapping("/plant/update/{plantIdx}") public ResponseEntity getUpdatedPlant(@PathVariable Long plantIdx){ + log.info("[API]: getUpdatedPlant - 식물을 수정할 때 뜨는 조회 화면"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -119,13 +128,15 @@ public ResponseEntity getUpdatedPlant(@PathVariable Long plantIdx) } /** - * [PUT] /plant/update + * [PUT] 식물 수정 * @return 수정한 식물의 정보 */ @PutMapping(value = "/plant/update/{plantIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity updatePlant(@PathVariable Long plantIdx, @RequestPart("plant") PlantDto.updatePlantReq updatePlantReq, @RequestPart("image") MultipartFile file){ + log.info("[API] updatePlant - 식물 수정"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -135,12 +146,14 @@ public ResponseEntity updatePlant(@PathVariable Long plantIdx, } /** - * [DELETE] /plant/delete + * [DELETE] 식물 삭제 * @param plantIdx * @return 삭제한 식물의 닉네임 */ @DeleteMapping("/plant/delete/{plantIdx}") public ResponseEntity deletePlant(@PathVariable Long plantIdx){ + log.info("[API] deletePlant - 식물 삭제"); + String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); From 74ed9365f583b964692015b8f260ed8f1d118f0c Mon Sep 17 00:00:00 2001 From: sonshn Date: Wed, 19 Jun 2024 21:20:16 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[Fix]=20=EC=8B=9D=EB=AC=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C:=20=EC=8B=9D=EB=AC=BC=20=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=ED=8C=81=EB=8F=84=20=EC=A1=B0=ED=9A=8C=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/umc/commonplant/domain/plant/dto/PlantDto.java | 2 ++ .../umc/commonplant/domain/plant/service/PlantService.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java b/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java index 1b700a9..e14017a 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java +++ b/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java @@ -66,6 +66,8 @@ public static class getPlantRes{ private String scientificName; @Schema(description = "식물의 물주는 주기 (Information 에 저장된 권장 주기)", example = "10") private Long waterDay; + @Schema(description = "관리 팁", example = "물을 좋아하나 과습에 주의하세요!") + private String tip; @Schema(description = "빛의 강도", example = "밝은 곳을 좋아해요!") private String sunlight; @Schema(description = "최저 온도", example = "16") diff --git a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java index 98714c7..81e8c77 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java +++ b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java @@ -154,6 +154,12 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) { // log.info("getMemoList: " + getAllMemoList); + String tip = null; + + if(!infoResponse.get(0).getTip().isEmpty()) { + tip = infoResponse.get(0).getTip(); + } + PlantDto.getPlantRes getPlantRes = new PlantDto.getPlantRes( plant.getPlantIdx(), plant.getPlantName(), @@ -165,6 +171,7 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) { getAllMemoList, infoResponse.get(0).getScientificName(), infoResponse.get(0).getWater_day(), + tip, infoResponse.get(0).getSunlight(), infoResponse.get(0).getTemp_min(), infoResponse.get(0).getTemp_max(), From be5b860f2d9985d9f550764dcfcf3e825ff54e88 Mon Sep 17 00:00:00 2001 From: sonshn Date: Sat, 29 Jun 2024 15:56:57 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Fix]=20=EC=8B=9D=EB=AC=BC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95:=20=EB=AC=BC=20=EC=A3=BC=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EA=B0=84=20=EA=B0=92=EB=8F=84=20=EB=B3=80=EA=B2=BD=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/plant/controller/PlantSwagger.java | 2 +- .../domain/plant/dto/PlantDto.java | 5 ++++ .../domain/plant/entity/Plant.java | 3 ++- .../domain/plant/service/PlantService.java | 26 ++++++++++++++++--- .../global/exception/ErrorResponseStatus.java | 4 +-- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/umc/commonplant/domain/plant/controller/PlantSwagger.java b/src/main/java/com/umc/commonplant/domain/plant/controller/PlantSwagger.java index f39a344..6cce5a5 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/controller/PlantSwagger.java +++ b/src/main/java/com/umc/commonplant/domain/plant/controller/PlantSwagger.java @@ -77,7 +77,7 @@ public ResponseEntity updatePlant ( ) @PathVariable Long plantIdx, @Parameter( name = "nickname", - description = "식물의 새로운 닉네임", + description = "식물의 새로운 닉네임과 물 주기 기간 값", required = true ) @RequestPart("plant") PlantDto.updatePlantReq updatePlantReq, @Parameter( diff --git a/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java b/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java index e14017a..4263da8 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java +++ b/src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java @@ -149,8 +149,12 @@ public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMem @NoArgsConstructor @Data public static class updatePlantReq{ + @Schema(description = "수정하는 식물의 인덱스 값") private Long plantIdx; + @Schema(description = "식물의 새로운 닉네임", example = "머니볼") private String nickname; + @Schema(description = "식물의 새로운 물주기 기간 값. 입력은 문자열로 받음.", example = "15") + private String waterCycle; } /** @@ -162,6 +166,7 @@ public static class updatePlantReq{ public static class updatePlantRes{ private Long plantIdx; private String nickname; + private int waterCycle; private String imgUrl; } diff --git a/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java b/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java index 8142fec..ed6cce0 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java +++ b/src/main/java/com/umc/commonplant/domain/plant/entity/Plant.java @@ -49,9 +49,10 @@ public Plant(Place place, String plantName, String nickname, int waterCycle, Str /** * 식물 수정 API 관련 메소드 */ - public void updatePlant(String imgUrl, String nickname) { + public void updatePlant(String imgUrl, String nickname, int waterCycle) { this.imgUrl = imgUrl; this.nickname = nickname; + this.waterCycle = waterCycle; } /** diff --git a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java index 81e8c77..4a2a8a7 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java +++ b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java @@ -91,11 +91,11 @@ public String createPlant(User user, PlantDto.createPlantReq req, MultipartFile waterCycle = req.getWaterCycle(); if(waterCycle.charAt(0) == 0) { - throw new BadRequestException(ErrorResponseStatus.REGEX_VALIDATION_ERROR); + throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR); } else if(req.getWaterCycle().matches("^[1-9]\\d*$")){ castedWaterCycle = Integer.parseInt(waterCycle); } else { - throw new BadRequestException(ErrorResponseStatus.REGEX_VALIDATION_ERROR); + throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR); } } @@ -368,6 +368,24 @@ public PlantDto.updatePlantRes updatePlant(User user, Long plantIdx, PlantDto.up throw new BadRequestException(ErrorResponseStatus.LONG_PLANT_NICKNAME); } + // TODO: 식물의 물 주기 기간 + String waterCycle = null; + int castedWaterCycle = 0; + + if(String.valueOf(req.getWaterCycle()).isEmpty()){ + throw new BadRequestException(ErrorResponseStatus.EMPTY_PLANT_WATERED_DATE); + } else { + waterCycle = req.getWaterCycle(); + + if(waterCycle.charAt(0) == 0) { + throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR); + } else if(req.getWaterCycle().matches("^[1-9]\\d*$")){ + castedWaterCycle = Integer.parseInt(waterCycle); + } else { + throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR); + } + } + // TODO: imgUrl String imgUrl = null; @@ -377,12 +395,13 @@ public PlantDto.updatePlantRes updatePlant(User user, Long plantIdx, PlantDto.up throw new BadRequestException(ErrorResponseStatus.NO_SELECTED_PLANT_IMAGE); } - plant.updatePlant(imgUrl, plantNickname); + plant.updatePlant(imgUrl, plantNickname, castedWaterCycle); plantRepository.save(plant); return new PlantDto.updatePlantRes( plant.getPlantIdx(), plantNickname, + castedWaterCycle, imgUrl ); } @@ -406,6 +425,7 @@ public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) { return new PlantDto.updatePlantRes( plant.getPlantIdx(), plant.getNickname(), + plant.getWaterCycle(), plant.getImgUrl() ); } diff --git a/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java b/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java index 30e212c..352db69 100644 --- a/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java +++ b/src/main/java/com/umc/commonplant/global/exception/ErrorResponseStatus.java @@ -27,8 +27,8 @@ public enum ErrorResponseStatus { NO_PLANT_NICKNAME(false, 4201, "식물의 애칭을 입력해 주세요!"), LONG_PLANT_NICKNAME(false, 4202, "식물의 애칭은 10자 이하로 설정해주세요!"), NO_SELECTED_PLANT_IMAGE(false,4203, "식물의 이미지를 선택해주세요!"), - REGEX_VALIDATION_ERROR(false, 4204, "정확한 물 주기 값을 입력해주세요!"), - + EMPTY_PLANT_WATERED_DATE(false, 4204, "식물의 새로운 물 주기 기간을 입력해주세요!"), + PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR(false, 4205, "정확한 물 주기 기간 값을 입력해주세요!"), // 4300 : Memo PLANT_NOT_FOUND(false, 4300, "등록되지 않은 식물입니다."), From 980d5c5a0bb381111b3cb07dc08b0d50f54ec5c2 Mon Sep 17 00:00:00 2001 From: sonshn Date: Thu, 4 Jul 2024 20:06:36 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[Fix]=20=EC=8B=9D=EB=AC=BC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95:=20=EC=8B=9D=EB=AC=BC=EC=9D=98=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=8F=84=20=EB=B3=80=EA=B2=BD=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/commonplant/domain/plant/service/PlantService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java index 4a2a8a7..a3c6724 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java +++ b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java @@ -390,7 +390,9 @@ public PlantDto.updatePlantRes updatePlant(User user, Long plantIdx, PlantDto.up String imgUrl = null; if (plantImage.getSize() > 0) { - imgUrl = plant.getImgUrl(); + imageService.deleteFileInS3(plant.getImgUrl()); + + imgUrl = imageService.saveImage(plantImage); } else { throw new BadRequestException(ErrorResponseStatus.NO_SELECTED_PLANT_IMAGE); }