Skip to content

Commit

Permalink
refactor : 북마크 추가시 이미 추가된 상태이면 예외 발생하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
JunHwan Kim committed Feb 14, 2024
1 parent 0ed204c commit 17cf30a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import java.util.List;

import static dnd.project.global.common.Result.NOT_FOUND_LECTURE;
import static dnd.project.global.common.Result.NOT_FOUND_USER;
import static dnd.project.global.common.Result.*;

@Service
@RequiredArgsConstructor
Expand All @@ -32,12 +31,16 @@ public Void addBookmark(Long lectureId, Long userId) {
Users user = getUser(userId);
Lecture lecture = getLecture(lectureId);

if (bookmarkRepository.findByLectureAndUser(lecture, user).isPresent()) {
throw new CustomException(ALREADY_CREATED_BOOKMARK);
}

bookmarkRepository.save(
Bookmark.builder()
.user(user)
.lecture(lecture)
.build()
);
.build());

return null;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dnd/project/global/common/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public enum Result {
NOT_FOUND_REVIEW(-3001, "존재하지 않는 리뷰"),
NOT_MATCHED_USER(-3002, "후기를 작성한 사람이 아닙니다."),
NOT_MY_REVIEW_LIKE(-3003, "내가 작성한 후기에는 좋아요를 남길 수 없습니다."),
NOT_CREATED_REVIEW(-3004, "아직 후기를 한번도 작성하지 않았습니다.");
NOT_CREATED_REVIEW(-3004, "아직 후기를 한번도 작성하지 않았습니다."),

ALREADY_CREATED_BOOKMARK(-4000, "이미 강의를 찜했습니다.");

private final int code;
private final String message;
Expand Down

0 comments on commit 17cf30a

Please sign in to comment.