Skip to content

Commit

Permalink
[CHORE] User의 Parentchild null 여부에 대한 예외처리 #133
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 committed Feb 28, 2024
1 parent 674cf96 commit 67a875d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class AlbumService {
public Long createAlbum(final CreateAlbumRequestDto request, final String imgUrl, final Long userId) {

User user = getUserById(userId);
Parentchild parentchild = user.getParentChild();
Parentchild parentchild = getParentchildByUser(user);

Album album = Album.builder()
.title(request.getTitle())
.content(request.getContent())
Expand All @@ -48,19 +49,21 @@ public Long createAlbum(final CreateAlbumRequestDto request, final String imgUrl
public String deleteAlbum(final Long albumId, final Long userId) {

User user = getUserById(userId);
Parentchild parentchild = getParentchildByUser(user);
Album album = getAlbumById(albumId);

album.deleteParentchild();
user.getParentChild().deleteAlbum(album);
parentchild.deleteAlbum(album);
albumRepository.delete(album);

return album.getImgUrl();
}

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

return albumList.stream()
.map(AlbumResponseDto::of)
Expand All @@ -78,4 +81,13 @@ private Album getAlbumById(Long albumId) {
() -> new CustomException(ErrorType.NOT_FOUND_ALBUM)
);
}

private Parentchild getParentchildByUser(User user) {
Parentchild parentchild = user.getParentChild();
if (parentchild == null) {
throw new CustomException(ErrorType.USER_HAVE_NO_PARENTCHILD);
}

return parentchild;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public enum ErrorType {
FAIL_TO_SEND_PUSH_ALARM(HttpStatus.INTERNAL_SERVER_ERROR, "푸시 알림 메세지 전송에 실패했습니다."),
FAIL_TO_GET_IMAGE_PRE_SIGNED_URL(HttpStatus.INTERNAL_SERVER_ERROR, "PreSigned Url을 가져오는 데 실패했습니다."),
FAIL_TO_DELETE_IMAGE(HttpStatus.INTERNAL_SERVER_ERROR, "S3 버킷에서 이미지를 삭제하는 데 실패했습니다."),
S3_BUCKET_GET_IMAGE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "이미지를 불러오는 데 실패했습니다."),
S3_BUCKET_GET_IMAGE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "S3 버킷에서 이미지를 불러오는 데 실패했습니다."),

// ETC
INDEX_OUT_OF_BOUNDS(HttpStatus.INTERNAL_SERVER_ERROR, "인덱스 범위를 초과했습니다."),
Expand Down

0 comments on commit 67a875d

Please sign in to comment.