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/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 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..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; @@ -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() + ); + }