Skip to content

Commit

Permalink
Merge pull request #197 from lemonssoju/develop-v2
Browse files Browse the repository at this point in the history
[develop-v2] main merge
  • Loading branch information
JoongHyun-Kim authored Jun 11, 2024
2 parents e1b5067 + 02ae3ac commit c2a6c3a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
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

0 comments on commit c2a6c3a

Please sign in to comment.