Skip to content

Commit

Permalink
Merge pull request #177 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 3, 2024
2 parents 7fbe14f + 3dd4d7e commit 6c72b01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import com.lesso.neverland.comment.dto.CommentDto;
import com.lesso.neverland.common.base.BaseException;
import com.lesso.neverland.common.base.BaseResponse;
import com.lesso.neverland.common.image.ImageService;
import com.lesso.neverland.group.domain.Team;
import com.lesso.neverland.group.repository.GroupRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

import static com.lesso.neverland.common.base.BaseResponseStatus.*;
Expand All @@ -19,14 +23,17 @@
public class AlbumService {
private final GroupRepository groupRepository;
private final AlbumRepository albumRepository;
private final ImageService imageService;

// 추억 이미지 등록
public BaseResponse<String> uploadAlbumImage(Long groupIdx, Long albumIdx, AlbumImageRequest albumImageRequest) {
public BaseResponse<String> uploadAlbumImage(Long groupIdx, Long albumIdx, MultipartFile image) throws IOException {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
Album album = albumRepository.findById(albumIdx).orElseThrow(() -> new BaseException(INVALID_ALBUM_IDX));
if (!album.getPuzzle().getTeam().equals(group)) throw new BaseException(NO_GROUP_ALBUM);

album.saveAlbumImage(albumImageRequest.albumImage());
String imagePath = imageService.uploadImage("album", image);

album.saveAlbumImage(imagePath);
albumRepository.save(album);

return new BaseResponse<>(SUCCESS);
Expand All @@ -42,6 +49,7 @@ public BaseResponse<AlbumDetailResponse> getAlbumDetail(Long groupIdx, Long albu
.map(puzzleMember -> puzzleMember.getUser().getProfile().getNickname()).toList();

List<CommentDto> commentList = album.getComments().stream()
.filter(comment -> "active".equals(comment.getStatus()))
.map(comment -> new CommentDto(
comment.getCommentIdx(),
comment.getUser().getProfile().getNickname(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.lesso.neverland.album.application.AlbumService;
import com.lesso.neverland.album.dto.AlbumDetailResponse;
import com.lesso.neverland.album.dto.AlbumImageRequest;
import com.lesso.neverland.common.base.BaseException;
import com.lesso.neverland.common.base.BaseResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

import static com.lesso.neverland.common.base.BaseResponseStatus.IMAGE_UPLOAD_FAIL;
import static com.lesso.neverland.common.constants.RequestURI.album;

@RestController
Expand All @@ -18,8 +22,12 @@ public class AlbumController {

// 추억 이미지 등록
@PostMapping("/{albumIdx}/image")
public BaseResponse<String> uploadAlbumImage(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx, @RequestBody AlbumImageRequest albumImageRequest) {
return albumService.uploadAlbumImage(groupIdx, albumIdx, albumImageRequest);
public BaseResponse<String> uploadAlbumImage(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx, @RequestPart MultipartFile image) {
try {
return albumService.uploadAlbumImage(groupIdx, albumIdx, image);
} catch (IOException e) {
throw new BaseException(IMAGE_UPLOAD_FAIL);
}
}

// 앨범 상세 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ private static void validateWriter(User user, Comment comment) {
if (!comment.getUser().equals(user)) throw new BaseException(NO_COMMENT_WRITER);
if (comment.getStatus().equals(INACTIVE)) throw new BaseException(ALREADY_DELETED_COMMENT);
}

private static void validateGroupMember(User user) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public BaseResponse<String> modifyComment(@PathVariable Long commentIdx, @Reques
return commentService.modifyComment(commentIdx, modifyCommentRequest);
}

// [작성자] 댓글 삭제
@PatchMapping("/{commentIdx}/delete")
public BaseResponse<?> deleteComment(@PathVariable Long commentIdx) {
return commentService.deleteComment(commentIdx);
Expand Down

0 comments on commit 6c72b01

Please sign in to comment.