Skip to content

Commit

Permalink
[CHORE] link default img s3 url #151
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 committed May 2, 2024
1 parent 6b72b07 commit 89bdcf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class AlbumController {
private final AlbumService albumService;
private final S3Service s3Service;

private static final String DEFAULT_ALBUM_IMG = "default_img.png";

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ApiResponse createAlbum(@Valid @RequestBody final CreateAlbumRequestDto request, final Principal principal, HttpServletResponse response) {
Expand Down Expand Up @@ -70,6 +72,7 @@ public ApiResponse deleteAlbum(@PathVariable final Long albumId, final Principal
@GetMapping
@ResponseStatus(HttpStatus.OK)
public ApiResponse<List<AlbumResponseDto>> getAlbumList(final Principal principal) {
return ApiResponse.success(GET_ALBUM_LIST_SUCCESS, albumService.getAlbumList(getUserFromPrincial(principal)));
String defaultImgUrl = s3Service.getS3ImgUrl(ALBUM_PREFIX.getValue(), DEFAULT_ALBUM_IMG);
return ApiResponse.success(GET_ALBUM_LIST_SUCCESS, albumService.getAlbumList(defaultImgUrl, getUserFromPrincial(principal)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,24 @@ public String deleteAlbum(final Long albumId, final Long userId) {
return album.getImgUrl();
}

public List<AlbumResponseDto> getAlbumList(final Long userId) {
public List<AlbumResponseDto> getAlbumList(final String defaultImgUrl, final Long userId) {
User user = getUserById(userId);
Parentchild parentchild = getParentchildByUser(user);
List<Album> albumList = albumRepository.findAllByParentchildOrderByCreatedAtDesc(
parentchild);

// Album을 아직 한번도 등록하지 않은 경우
if (albumList.isEmpty() && !parentchild.isFirstAlbumUpload() && !parentchild.isDeleteSampleAlbum()) {
return List.of(AlbumResponseDto.of(createAlbumExample()));
return List.of(AlbumResponseDto.of(createAlbumExample(defaultImgUrl)));
}

return albumList.stream()
.map(AlbumResponseDto::of)
.collect(Collectors.toList());
}

private Album createAlbumExample() {
return new Album(0L, "사진의 제목을 입력할 수 있어요", "사진에 대해 소개해요",
"https://i1.sndcdn.com/artworks-l2lCmUXC61XR2HM5-gwB8Vg-t500x500.jpg", "직성자"); // TODO 기획 측에서 전달받은 이미지 url로 변경
private Album createAlbumExample(final String defaultImgUrl) {
return new Album(0L, "사진의 제목을 입력할 수 있어요", "사진에 대해 소개해요", defaultImgUrl, "직성자");
}

private User getUserById(Long userId) { // TODO userId -> Parentchild 한번에 가져오기
Expand Down

0 comments on commit 89bdcf1

Please sign in to comment.