Skip to content

Commit

Permalink
Merge pull request #178 from lemonssoju/fix/88-uploadAlbumImage
Browse files Browse the repository at this point in the history
[fix/88-uploadAlbumImage] 추억 이미지를 multipartFile로 전달받는 로직으로 수정
  • Loading branch information
JoongHyun-Kim authored Jun 3, 2024
2 parents adacd6a + 48c20ff commit 3dd4d7e
Show file tree
Hide file tree
Showing 2 changed files with 20 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 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

0 comments on commit 3dd4d7e

Please sign in to comment.