From 485b0d25b6bf03647fde70d2e72d9c5ef7816831 Mon Sep 17 00:00:00 2001 From: sonshn Date: Mon, 14 Oct 2024 17:42:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]:=20Place=20-=20=EC=9E=A5=EC=86=8C=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 --- .../place/controller/PlaceContoller.java | 22 ++++++------ .../domain/place/dto/PlaceDto.java | 15 ++++++++ .../domain/place/entity/Place.java | 4 +++ .../domain/place/service/PlaceService.java | 34 +++++++++++++++---- 4 files changed, 58 insertions(+), 17 deletions(-) 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 8bcc17a..a8dd4f2 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 @@ -139,17 +139,17 @@ public ResponseEntity getPlaceFriends(@PathVariable String code){ } // 장소 수정 -// @PutMapping("/update/{code}") -// public ResponseEntity updatePlace(@PathVariable String code, -// @RequestPart(value = "place") PlaceDto.updatePlaceReq req, -// @RequestPart(value = "image") MultipartFile image){ -// String uuid = jwtService.resolveToken(); -// User user = userService.getUser(uuid); -// -// String placeCode = placeService.update(user, code, req, image); -// return ResponseEntity.ok(new JsonResponse(true, 200, "createPlace", placeCode)); -// -// } + @PutMapping("/update/{code}") + public ResponseEntity updatePlace(@PathVariable String code, + @RequestPart(value = "place") PlaceDto.updatePlaceReq req, + @RequestPart(value = "image") MultipartFile image){ + log.info("[API] updatePlace"); + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + PlaceDto.updatePlaceRes updatedPlace = placeService.updatePlace(user, code, req, image); + return ResponseEntity.ok(new JsonResponse(true, 200, "updatePlace", updatedPlace)); + } // 장소 삭제 // - 장소 탈퇴시 diff --git a/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java b/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java index 376e770..282b3fe 100644 --- a/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java +++ b/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java @@ -35,6 +35,21 @@ public static class updatePlaceReq{ private String address; } + @AllArgsConstructor + @NoArgsConstructor + @Data + @Schema(description = "장소 생성 관련 Response") + public static class updatePlaceRes{ + @Schema(description = "장소 코드" , example = "aBcDeF") + private String code; + @Schema(description = "장소 이름" , example = "우리집 거실") + private String name; + @Schema(description = "장소 주소" , example = "서울특별시 노원구 광운로 20") + private String address; + @Schema(description = "장소 이미지") + private String imgUrl; + } + @AllArgsConstructor @NoArgsConstructor @Data diff --git a/src/main/java/com/umc/commonplant/domain/place/entity/Place.java b/src/main/java/com/umc/commonplant/domain/place/entity/Place.java index 3726c84..c34e4ae 100644 --- a/src/main/java/com/umc/commonplant/domain/place/entity/Place.java +++ b/src/main/java/com/umc/commonplant/domain/place/entity/Place.java @@ -54,4 +54,8 @@ public Place(String name, User owner, String gridX, String gridY, String address this.imgUrl = imgUrl; this.code = code; } + + public void setPlaceIdx(Long placeIdx) { + this.placeIdx = placeIdx; + } } diff --git a/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java b/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java index 440b28b..7f98a8d 100644 --- a/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java +++ b/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java @@ -162,12 +162,34 @@ public List getPlaceFriends(String code) { return friends; } -// public String update(User user, String code, PlaceDto.updatePlaceReq req, MultipartFile image) { -// userOnPlace(user, code); -// Place oldPlace = placeRepository.getPlaceByCode(code).orElseThrow(() -> new BadRequestException(NOT_FOUND_PLACE_CODE)); -// -// -// } + @Transactional + public PlaceDto.updatePlaceRes updatePlace(User user, String code, PlaceDto.updatePlaceReq req, MultipartFile image) { + Place place = getPlaceByCode(code); + belongUserOnPlace(user, code); + + HashMap gridXY = openApiService.getGridXYFromAddress(req.getAddress()); + + String imgUrl = imageService.saveImage(image); + + Place newPlaceInfo = Place.builder() + .name(req.getName()) + .address(req.getAddress()) + .code(code) + .gridX(gridXY.get("x")) + .gridY(gridXY.get("y")) + .imgUrl(imgUrl) + .owner(place.getOwner()) + .build(); + newPlaceInfo.setPlaceIdx(place.getPlaceIdx()); + placeRepository.save(newPlaceInfo); + + return new PlaceDto.updatePlaceRes( + newPlaceInfo.getCode(), + newPlaceInfo.getName(), + newPlaceInfo.getAddress(), + newPlaceInfo.getImgUrl() + ); + } From 40d4b5ed171868f63d395badbe5bcf8356da017f Mon Sep 17 00:00:00 2001 From: sonshn Date: Mon, 14 Oct 2024 17:43:35 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Fix]:=20Place=20-=20PlaceDTO=20=EC=84=A4?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/umc/commonplant/domain/place/dto/PlaceDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java b/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java index 282b3fe..f9ddd41 100644 --- a/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java +++ b/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java @@ -27,7 +27,7 @@ public static class createPlaceReq{ @AllArgsConstructor @NoArgsConstructor @Data - @Schema(description = "장소 생성 관련 Request") + @Schema(description = "장소 수정 관련 Request") public static class updatePlaceReq{ @Schema(description = "장소 이름" , example = "우리집 거실") private String name; @@ -38,7 +38,7 @@ public static class updatePlaceReq{ @AllArgsConstructor @NoArgsConstructor @Data - @Schema(description = "장소 생성 관련 Response") + @Schema(description = "장소 수정 관련 Response") public static class updatePlaceRes{ @Schema(description = "장소 코드" , example = "aBcDeF") private String code; From 1481d8954f2148adc99699d49f960f5d1c59c2a0 Mon Sep 17 00:00:00 2001 From: sonshn Date: Mon, 14 Oct 2024 17:53:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Feat]:=20Place=20-=20Swagger=EC=97=90=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EC=88=98=EC=A0=95=20=EC=84=A4=EB=AA=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commonplant/domain/place/controller/PlaceSwagger.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/umc/commonplant/domain/place/controller/PlaceSwagger.java b/src/main/java/com/umc/commonplant/domain/place/controller/PlaceSwagger.java index 6f180c7..9dbdb90 100644 --- a/src/main/java/com/umc/commonplant/domain/place/controller/PlaceSwagger.java +++ b/src/main/java/com/umc/commonplant/domain/place/controller/PlaceSwagger.java @@ -20,6 +20,13 @@ public ResponseEntity createPlace( @Parameter(description = "장소 대표 이미지") @RequestPart(value = "image", required = false) MultipartFile image ); + @Operation(summary = "updatePlace", description = "장소 수정") + public ResponseEntity updatePlace( + @Parameter(description = "place code", example = "XFGEDS") @PathVariable("code") String code, + @Parameter(description = "장소 수정 요청 정보", required = true) @RequestPart("place") PlaceDto.updatePlaceReq updatePlaceReq, + @Parameter(description = "장소 대표 이미지") @RequestPart(value = "image", required = false) MultipartFile image + ); + @Operation(summary = "getPlace", description = "장소 코드로 장소 정보 조회") public ResponseEntity getPlace( @Parameter(description = "place code", example = "XFGEDS") @PathVariable("code") String code