From 9e2b70c43f94f24850d659fac148eb886ead08bf Mon Sep 17 00:00:00 2001 From: uhyunglee Date: Wed, 29 May 2024 20:12:14 +0900 Subject: [PATCH 1/4] [Refactor] Modify User Join --- .../commonplant/domain/user/controller/UserController.java | 2 +- .../commonplant/domain/user/controller/UserSwagger.java | 3 ++- .../umc/commonplant/domain/user/service/UserService.java | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) 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 8ab1566..59e43c1 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 @@ -20,7 +20,7 @@ public class UserController implements UserSwagger{ private final JwtService jwtService; @PostMapping(value = "/user", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) //join - public ResponseEntity join(@RequestPart("user") UserDto.join req, @RequestPart(value ="image", required = false)MultipartFile image){ + public ResponseEntity join(@RequestPart("user") UserDto.join req, @RequestParam(value ="image", required = false)MultipartFile image){ log.info("join"); String token = userService.joinUser(req, image); diff --git a/src/main/java/com/umc/commonplant/domain/user/controller/UserSwagger.java b/src/main/java/com/umc/commonplant/domain/user/controller/UserSwagger.java index 8e4bddd..8690e3b 100644 --- a/src/main/java/com/umc/commonplant/domain/user/controller/UserSwagger.java +++ b/src/main/java/com/umc/commonplant/domain/user/controller/UserSwagger.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; @@ -22,7 +23,7 @@ public ResponseEntity join( @Parameter( name = "image", description = "프로필 이미지" - )@RequestPart(value = "image", required = false)MultipartFile image + )@RequestParam(value = "image", required = false)MultipartFile image ); @Operation(summary = "유저 조회", description = "유저조회 API 호출") @Parameter(name = "name", description="조회할 유저 이름",example = "김커먼", required = true) diff --git a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java index d6d3469..a4acbbf 100644 --- a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java +++ b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java @@ -46,7 +46,12 @@ public String joinUser(UserDto.join req, MultipartFile image){ }else{ //join String uuid = UuidUtil.generateType1UUID(); - String imageUrl = imageService.saveImage(image); + String imageUrl = ""; + if(!image.isEmpty()) + imageUrl = imageService.saveImage(image); + +// String uuid = UuidUtil.generateType1UUID(); +// String imageUrl = imageService.saveImage(image); User user = User.builder() .name(req.getName()) From d4ef2a8b4bc0917c140ccd3ea46aa0ed8e6bdcb9 Mon Sep 17 00:00:00 2001 From: sonshn Date: Wed, 29 May 2024 20:20:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Fix]=20Plant=20=EC=A1=B0=ED=9A=8C/?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B4=80=EB=A0=A8=20Response=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 --- .../plant/controller/PlantController.java | 14 +++--- .../domain/plant/dto/PlantDto.java | 43 +++++++++++++++++-- .../domain/plant/service/PlantService.java | 31 +++++++++---- 3 files changed, 70 insertions(+), 18 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 20fc168..9af3aaa 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 @@ -99,28 +99,28 @@ public ResponseEntity updateWateredDate(@PathVariable Long plantId String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); - String nickname = plantService.updateWateredDate(user, plantIdx); + PlantDto.updateWateredDateRes wateredDateUpdatedPlant = plantService.updateWateredDate(user, plantIdx); - return ResponseEntity.ok(new JsonResponse(true, 200, "updateWateredDate", nickname)); + return ResponseEntity.ok(new JsonResponse(true, 200, "wateredDateUpdatedPlant", wateredDateUpdatedPlant)); } /** * [GET] /plant/update - * @return 수정하기 전 식물의 애칭 + * @return 수정하기 전 식물의 정보 */ @GetMapping("/plant/update/{plantIdx}") public ResponseEntity getUpdatedPlant(@PathVariable Long plantIdx){ String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); - String nickname = plantService.getUpdatedPlant(user, plantIdx).getNickname(); + PlantDto.updatePlantRes beforeUpdatedPlant = plantService.getUpdatedPlant(user, plantIdx); - return ResponseEntity.ok(new JsonResponse(true, 200, "getUpdatedPlant", nickname)); + return ResponseEntity.ok(new JsonResponse(true, 200, "beforeUpdatedPlant", beforeUpdatedPlant)); } /** * [PUT] /plant/update - * @return 수정한 식물의 애칭 + * @return 수정한 식물의 정보 */ @PutMapping(value = "/plant/update/{plantIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity updatePlant(@PathVariable Long plantIdx, @@ -129,7 +129,7 @@ public ResponseEntity updatePlant(@PathVariable Long plantIdx, String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); - String updatedPlant = plantService.updatePlant(user, plantIdx, updatePlantReq, file); + PlantDto.updatePlantRes updatedPlant = plantService.updatePlant(user, plantIdx, updatePlantReq, file); return ResponseEntity.ok(new JsonResponse(true, 200, "updatePlant", updatedPlant)); } 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 8de0bb8..1b700a9 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 @@ -43,30 +43,49 @@ public static class createPlantReq{ @NoArgsConstructor @Getter public static class getPlantRes{ + private Long plantIdx; + @Schema(description = "식물도감에 저장된 식물의 종 이름(학술명)", example = "몬스테라 카스테니안") private String name; + @Schema(description = "식물의 닉네임", example = "몬테") private String nickname; - + @Schema(description = "식물이 있는 장소의 이름", example = "카페") private String place; - + @Schema(description = "식물의 이미지 url 문자열") private String imgUrl; - + @Schema(description = "식물과 함께한 날짜", example = "1") private Long countDate; + @Schema(description = "다음 물주기 D-Day 까지 남은 날짜", example = "10") private Long remainderDate; // Memo + @Schema(description = "식물에 작성된 메모 리스트") private List memoList; // Info + @Schema(description = "학술명", example = "Monstera carstenianum") private String scientificName; + @Schema(description = "식물의 물주는 주기 (Information 에 저장된 권장 주기)", example = "10") private Long waterDay; + @Schema(description = "빛의 강도", example = "밝은 곳을 좋아해요!") private String sunlight; + @Schema(description = "최저 온도", example = "16") private Long tempMin; + @Schema(description = "최고 온도", example = "20") private Long tempMax; + @Schema(description = "습도", example = "70% 이상") private String humidity; + @Schema( + description = "식물이 등록된 날짜", + example = "2024.01.29" + ) @JsonFormat(pattern = "yyyy.MM.dd") private LocalDateTime createdAt; + @Schema( + description = "사용자가 마지막으로 물을 준 날짜", + example = "2024.01.29" + ) @JsonFormat(pattern = "yyyy.MM.dd") private LocalDateTime wateredDate; } @@ -78,6 +97,7 @@ public static class getPlantRes{ @NoArgsConstructor @Getter public static class getPlantListRes{ + private Long plantIdx; private String nickname; private String imgUrl; private String place; @@ -86,6 +106,7 @@ public static class getPlantListRes{ @Builder public getPlantListRes(Plant plant, String place, String member, Long remainderDate){ + this.plantIdx = plant.getPlantIdx(); this.nickname = plant.getNickname(); this.imgUrl = plant.getImgUrl(); this.place = place; @@ -101,6 +122,7 @@ public getPlantListRes(Plant plant, String place, String member, Long remainderD @NoArgsConstructor @Getter public static class getMyGardenPlantListRes{ + private Long plantIdx; private String plantName; private String nickname; private String imgUrl; @@ -111,6 +133,7 @@ public static class getMyGardenPlantListRes{ @Builder public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMemo){ + this.plantIdx = plant.getPlantIdx(); this.plantName = plant.getPlantName(); this.nickname = plant.getNickname(); this.imgUrl = plant.getImgUrl(); @@ -124,6 +147,7 @@ public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMem @NoArgsConstructor @Data public static class updatePlantReq{ + private Long plantIdx; private String nickname; } @@ -134,7 +158,20 @@ public static class updatePlantReq{ @NoArgsConstructor @Getter public static class updatePlantRes{ + private Long plantIdx; private String nickname; private String imgUrl; } + + /** + * 식물 D-Day 업데이트 + */ + @AllArgsConstructor + @NoArgsConstructor + @Getter + public static class updateWateredDateRes{ + private Long plantIdx; + private Long remainderDate; + } + } 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 2e39efa..98714c7 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 @@ -43,6 +43,7 @@ public class PlantService { /** * createPlant: 식물 추가 + * @param user * @param req * @param plantImage * @return @@ -122,8 +123,8 @@ public String createPlant(User user, PlantDto.createPlantReq req, MultipartFile /** * getPlant: 식물 조회 - * @param plantIdx * @param user + * @param plantIdx * @return */ @Transactional @@ -154,6 +155,7 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) { // log.info("getMemoList: " + getAllMemoList); PlantDto.getPlantRes getPlantRes = new PlantDto.getPlantRes( + plant.getPlantIdx(), plant.getPlantName(), plant.getNickname(), plant.getPlace().getName(), @@ -202,12 +204,12 @@ public Long getRemainderDate(Plant plant){ /** * updateWateredDate: 식물의 D-Day 업데이트 - * @param plantIdx * @param user + * @param plantIdx * @return */ @Transactional - public String updateWateredDate(User user, Long plantIdx) { + public PlantDto.updateWateredDateRes updateWateredDate(User user, Long plantIdx) { Plant plant = plantRepository.findByPlantIdx(plantIdx) .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT)); @@ -218,8 +220,14 @@ public String updateWateredDate(User user, Long plantIdx) { // TODO: 마지막으로 물 준 날짜 plant.setWateredDate(LocalDateTime.now()); + plantRepository.save(plant); + + Long remainderDate = getRemainderDate(plant); - return plantRepository.save(plant).getNickname(); + return new PlantDto.updateWateredDateRes( + plant.getPlantIdx(), + remainderDate + ); } /** @@ -326,13 +334,14 @@ public List getMyGardenPlantList(String placeC /** * updatePlant: 식물 수정 + * @param user * @param plantIdx - * @param nickname + * @param req * @param plantImage * @return */ @Transactional - public String updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req, MultipartFile plantImage) { + public PlantDto.updatePlantRes updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req, MultipartFile plantImage) { Plant plant = plantRepository.findByPlantIdx(plantIdx) .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT)); @@ -362,8 +371,13 @@ public String updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req, } plant.updatePlant(imgUrl, plantNickname); + plantRepository.save(plant); - return plantRepository.save(plant).getNickname(); + return new PlantDto.updatePlantRes( + plant.getPlantIdx(), + plantNickname, + imgUrl + ); } /** @@ -372,7 +386,7 @@ public String updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req, * @param plantIdx * @return */ - @Transactional + @Transactional(readOnly = true) public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) { Plant plant = plantRepository.findByPlantIdx(plantIdx) @@ -383,6 +397,7 @@ public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) { placeService.belongUserOnPlace(user, plantPlace.getCode()); return new PlantDto.updatePlantRes( + plant.getPlantIdx(), plant.getNickname(), plant.getImgUrl() ); From ca91f7b85f09db62d9249dac73b27ab3b6ea2d12 Mon Sep 17 00:00:00 2001 From: uhyunglee Date: Wed, 29 May 2024 20:30:38 +0900 Subject: [PATCH 3/4] [Fix] Fix checkNameDuplication return value --- .../com/umc/commonplant/domain/user/service/UserService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java index a4acbbf..20dec95 100644 --- a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java +++ b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java @@ -68,12 +68,12 @@ public String joinUser(UserDto.join req, MultipartFile image){ } @Transactional(readOnly = true) public boolean checkNameDuplication(String name){ - boolean nameDuplicate = userRepository.existsByname(name); + boolean nameDuplicate = userRepository.existsByname(name); // 검색안되면 false (사용가능한 이름) if(nameDuplicate) throw new BadRequestException(EXIST_NAME); if(name.length() < 2 || name.length() > 10) throw new BadRequestException(NOT_VALID_LENGTH); - return nameDuplicate; + return !nameDuplicate; } public User getUserByName(String name){ From c481a0b21b1d41833a980b957af8155d6d8ed90e Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 29 May 2024 22:34:19 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Chore]=20getPlaceBelongUser=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 --- .../domain/place/controller/PlaceContoller.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java b/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java index 5c6b6f8..8bcc17a 100644 --- a/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java +++ b/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java @@ -33,6 +33,7 @@ public class PlaceContoller implements PlaceSwagger{ @GetMapping("/health") public ResponseEntity healthCheck(){ + log.info("[API] healthCheck"); return ResponseEntity.ok("health check ok"); } @@ -42,6 +43,7 @@ public ResponseEntity healthCheck(){ consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity createPlace(@RequestPart("place") PlaceDto.createPlaceReq req, @RequestPart(value = "image", required = false) MultipartFile image) { + log.info("[API] createPlace"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); String placeCode = placeService.create(user, req, image); @@ -51,6 +53,7 @@ public ResponseEntity createPlace(@RequestPart("place") PlaceDto.c @GetMapping("/{code}") public ResponseEntity getPlace(@PathVariable("code") String code) { + log.info("[API] getPlace"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); placeService.userOnPlace(user, code); @@ -62,6 +65,7 @@ public ResponseEntity getPlace(@PathVariable("code") String code) @GetMapping("/weather/{code}") public ResponseEntity getPlaceWeather(@PathVariable("code") String code) { + log.info("[API] getPlaceWeather"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); PlaceDto.getPlaceGridRes placeGrid = placeService.getPlaceGrid(user, code); @@ -71,6 +75,7 @@ public ResponseEntity getPlaceWeather(@PathVariable("code") String // //친구 요청 @PostMapping("/friends") public ResponseEntity newFriends(@RequestBody PlaceDto.newFriendsReq req){ + log.info("[API] newFriends"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -93,6 +98,7 @@ public ResponseEntity newFriends(@RequestBody PlaceDto.newFriendsR // 메인페이지 @GetMapping("/myGarden") public ResponseEntity getMyGarden(){ + log.info("[API] getMyGarden"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); String name = user.getName(); @@ -110,6 +116,7 @@ public ResponseEntity getMyGarden(){ // 사용자가 속한 장소 리스트 @GetMapping("/user") public ResponseEntity getPlaceBelongUser(){ + log.info("[API] getPlaceBelongUser"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -121,6 +128,7 @@ public ResponseEntity getPlaceBelongUser(){ // 친구 리스트 조회 @GetMapping("/{code}/friends") public ResponseEntity getPlaceFriends(@PathVariable String code){ + log.info("[API] getPlaceFriends"); String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid);