diff --git a/src/main/java/com/lesso/neverland/album/application/AlbumService.java b/src/main/java/com/lesso/neverland/album/application/AlbumService.java index 61af60c..30c1032 100644 --- a/src/main/java/com/lesso/neverland/album/application/AlbumService.java +++ b/src/main/java/com/lesso/neverland/album/application/AlbumService.java @@ -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.*; @@ -19,14 +23,17 @@ public class AlbumService { private final GroupRepository groupRepository; private final AlbumRepository albumRepository; + private final ImageService imageService; // 추억 이미지 등록 - public BaseResponse uploadAlbumImage(Long groupIdx, Long albumIdx, AlbumImageRequest albumImageRequest) { + public BaseResponse 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); diff --git a/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java b/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java index 4ba7339..a00f5fa 100644 --- a/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java +++ b/src/main/java/com/lesso/neverland/album/presentation/AlbumController.java @@ -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 @@ -18,8 +22,12 @@ public class AlbumController { // 추억 이미지 등록 @PostMapping("/{albumIdx}/image") - public BaseResponse uploadAlbumImage(@PathVariable("groupIdx") Long groupIdx, @PathVariable("albumIdx") Long albumIdx, @RequestBody AlbumImageRequest albumImageRequest) { - return albumService.uploadAlbumImage(groupIdx, albumIdx, albumImageRequest); + public BaseResponse 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); + } } // 앨범 상세 조회