Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build] updatePlace #150

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading