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

[develop-v2] main merge #197

Merged
merged 4 commits into from
Jun 11, 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 @@ -42,6 +42,8 @@ public enum BaseResponseStatus {
ALREADY_DELETED_PUZZLE(false, HttpStatus.CONFLICT, "이미 μ‚­μ œλœ puzzle μž…λ‹ˆλ‹€."),
NO_PUZZLER(false, HttpStatus.FORBIDDEN, "ν•΄λ‹Ή 퍼즐의 νΌμ¦λŸ¬κ°€ μ•„λ‹™λ‹ˆλ‹€."),
TOO_LONG_CONTENT(false, HttpStatus.BAD_REQUEST, "νΌμ¦ν”ΌμŠ€μ˜ κΈΈμ΄λŠ” 100자 μ΄ν•˜μ—¬μ•Ό ν•©λ‹ˆλ‹€."),
BLANK_PUZZLE_CONTENT(false, HttpStatus.BAD_REQUEST, "퍼즐 λ‚΄μš©μ΄ λΉ„μ—ˆμŠ΅λ‹ˆλ‹€."),
ALREADY_HAS_ALBUM(false, HttpStatus.CONFLICT, "이미 앨범이 λ§Œλ“€μ–΄μ§„ νΌμ¦μž…λ‹ˆλ‹€."),


// group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,12 @@ public BaseResponse<String> editGroup(Long groupIdx, MultipartFile image, EditGr
userTeamRepository.save(userTeam);
}
}

if (image != null) {//TODO: 이미지 μ‚­μ œ 및 μ—…λ‘œλ“œ μ„€μ • ν›„ λ™μž‘ ν™•μΈν•˜κΈ°
// delete previous image
if (image != null && !image.isEmpty()) {
imageService.deleteImage(group.getTeamImage());

// upload new image
String imagePath = imageService.uploadImage("group", image);
group.modifyImage(imagePath);
} else throw new BaseException(NULL_GROUP_IMAGE);
String newImagePath = imageService.uploadImage("group", image);
group.modifyImage(newImagePath);
}
groupRepository.save(group);
return new BaseResponse<>(SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BaseResponse<GroupEditViewResponse> getGroupEditView(@PathVariable Long g

// [κ΄€λ¦¬μž] κ·Έλ£Ή μˆ˜μ •
@PatchMapping("/{groupIdx}/edit")
public BaseResponse<String> editGroup(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart EditGroupRequest editGroupRequest) {
public BaseResponse<String> editGroup(@PathVariable Long groupIdx, @RequestPart(required = false) MultipartFile image, @RequestPart EditGroupRequest editGroupRequest) {
try {
return groupService.editGroup(groupIdx, image, editGroupRequest);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,24 @@ private PuzzleLocation convertAddressToCoordinates(String address) throws JsonPr
}

// [μž‘μ„±μž] 퍼즐 μˆ˜μ •
public BaseResponse<String> editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile newImage, EditPuzzleRequest editPuzzleRequest) {
public BaseResponse<String> editPuzzle(Long groupIdx, Long puzzleIdx, MultipartFile newImage, EditPuzzleRequest editPuzzleRequest) throws IOException {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Puzzle puzzle = puzzleRepository.findById(puzzleIdx).orElseThrow(() -> new BaseException(INVALID_PUZZLE_IDX));
validateWriter(user, puzzle);
if (albumRepository.existsByPuzzle(puzzle)) throw new BaseException(ALREADY_HAS_ALBUM);

if (editPuzzleRequest.content() != null) {
if (!editPuzzleRequest.content().equals("") && !editPuzzleRequest.content().equals(" "))
puzzle.editContent(editPuzzleRequest.content());
else throw new BaseException(BLANK_PUZZLE_CONTENT);
}
if (newImage != null && !newImage.isEmpty()) {
imageService.deleteImage(puzzle.getPuzzleImage());

String newImagePath = imageService.uploadImage("puzzle", newImage);
puzzle.modifyImage(newImagePath);
}
puzzleRepository.save(puzzle);
return new BaseResponse<>(SUCCESS);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ public void delete() {
this.setStatus(INACTIVE);
}
public void addPuzzleImage(String puzzleImage) { this.puzzleImage = puzzleImage; }
public void modifyImage(String puzzleImage) {this.puzzleImage = puzzleImage;}
public void editContent(String content) { this.content = content;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public BaseResponse<CreatePuzzleResponse> createPuzzle(@PathVariable Long groupI
// [μž‘μ„±μž] 퍼즐 μˆ˜μ •
@GetMapping("/{puzzleIdx}/edit")
public BaseResponse<String> editPuzzle(@PathVariable("groupIdx") Long groupIdx, @PathVariable("puzzleIdx") Long puzzleIdx, @RequestPart MultipartFile newImage, @RequestPart EditPuzzleRequest editPuzzleRequest) {
return puzzleService.editPuzzle(groupIdx, puzzleIdx, newImage, editPuzzleRequest);
try {
return puzzleService.editPuzzle(groupIdx, puzzleIdx, newImage, editPuzzleRequest);
} catch (IOException e) {
throw new BaseException(IMAGE_UPLOAD_FAIL);
}
}

// [μž‘μ„±μž] 퍼즐 μ‚­μ œ
Expand Down
Loading