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/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); 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 1b700a9..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 @@ -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") @@ -147,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; } /** @@ -160,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 98714c7..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 @@ -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); } } @@ -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(), @@ -361,21 +368,42 @@ 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; if (plantImage.getSize() > 0) { - imgUrl = plant.getImgUrl(); + imageService.deleteFileInS3(plant.getImgUrl()); + + imgUrl = imageService.saveImage(plantImage); } else { 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 ); } @@ -399,6 +427,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/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)); 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, "등록되지 않은 식물입니다."),