Skip to content

Commit

Permalink
fix: 작성자 저장 에러 핸들링
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Nov 7, 2024
1 parent ac5b0c8 commit a70b108
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
@AllArgsConstructor
public enum AlbumErrorCode implements BaseErrorCode {
ALBUM_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 앨범이 존재하지 않습니다."),
ALBUM_SHARE_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 공유 데이터가 존재하지 않습니다.");
ALBUM_SHARE_NOT_FOUND(HttpStatus.BAD_REQUEST, "400", "해당 공유 데이터가 존재하지 않습니다."),
USER_ALREADY_OWNED_ALBUM(HttpStatus.CONFLICT, "409", "사용자가 이미 이 앨범을 소유하고 있습니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,23 @@ public Long saveShareTable(String email, Long albumId) {
@Override
public void saveNewData(String email, Long token) {

JpaAlbumShare albumShare = albumShareRepository.findById(token).orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_SHARE_NOT_FOUND));
// albumShare 가져오기
JpaAlbumShare albumShare = albumShareRepository.findById(token)
.orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_SHARE_NOT_FOUND));

// jpaUser 가져오기
JpaUser jpaUser = userRepository.findByUserEmail(email)
.orElseThrow(() -> new UserCustomException(UserErrorCode.NO_USER_INFO));

// albumShare의 user와 jpaUser가 같은지 비교
if (albumShare.getUser().equals(jpaUser)) {
throw new AlbumCustomException(AlbumErrorCode.USER_ALREADY_OWNED_ALBUM);
}

// 앨범 저장
JpaAlbum album = albumRepository.findById(albumShare.getAlbum().getId()).orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_NOT_FOUND));
JpaAlbum album = albumRepository.findById(albumShare.getAlbum().getId())
.orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_NOT_FOUND));

JpaAlbum newAlbum = JpaAlbum.builder()
.image(album.getImage())
.jpaUser(jpaUser)
Expand All @@ -123,7 +134,8 @@ public void saveNewData(String email, Long token) {
List<JpaAlbumHashTag> albumHashTagList = albumHashTagRepository.findByJpaAlbum_Id(album.getId());

for (JpaAlbumHashTag a : albumHashTagList) {
JpaHashTag hashTag = hashtagRepository.findById(a.getJpaHashtag().getId()).orElseThrow(() -> new HashTagCustomException(HashTagErrorCode.HASHTAG_NOT_FOUND));
JpaHashTag hashTag = hashtagRepository.findById(a.getJpaHashtag().getId())
.orElseThrow(() -> new HashTagCustomException(HashTagErrorCode.HASHTAG_NOT_FOUND));

JpaHashTag newTag = JpaHashTag.builder()
.hashTag(hashTag.getHashTag())
Expand All @@ -133,4 +145,5 @@ public void saveNewData(String email, Long token) {
hashtagRepository.save(newTag);
}
}

}

0 comments on commit a70b108

Please sign in to comment.