Skip to content

Commit

Permalink
Merge pull request #149 from UMC-CommonPlant/feat/#148_Place
Browse files Browse the repository at this point in the history
[Feat] updatePlace
  • Loading branch information
sonshn authored Oct 14, 2024
2 parents 46afb37 + 1481d89 commit 2c0aa07
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ public ResponseEntity<JsonResponse> getPlaceFriends(@PathVariable String code){
}

// 장소 수정
// @PutMapping("/update/{code}")
// public ResponseEntity<JsonResponse> 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<JsonResponse> 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));
}

// 장소 삭제
// - 장소 탈퇴시
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public ResponseEntity<JsonResponse> createPlace(
@Parameter(description = "장소 대표 이미지") @RequestPart(value = "image", required = false) MultipartFile image
);

@Operation(summary = "updatePlace", description = "장소 수정")
public ResponseEntity<JsonResponse> 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<JsonResponse> getPlace(
@Parameter(description = "place code", example = "XFGEDS") @PathVariable("code") String code
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,29 @@ public static class createPlaceReq{
@AllArgsConstructor
@NoArgsConstructor
@Data
@Schema(description = "장소 생성 관련 Request")
@Schema(description = "장소 수정 관련 Request")
public static class updatePlaceReq{
@Schema(description = "장소 이름" , example = "우리집 거실")
private String name;
@Schema(description = "장소 주소" , example = "서울특별시 노원구 광운로 20")
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,34 @@ public List<PlaceDto.getPlaceFriends> 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<String, String> 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()
);
}



Expand Down

0 comments on commit 2c0aa07

Please sign in to comment.