Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ public ResponseEntity<?> getAllBookmarks(@AuthenticationPrincipal CustomOAuth2Us
);
}

@DeleteMapping("/{bookmarkId}")
@DeleteMapping("/{storeId}")
@Operation(summary = "북마크 삭제", description = "특정 주점에 대한 북마크 삭제")
@ApiResponse(responseCode = "200", description = "북마크 삭제")
public ResponseEntity<?> deleteBookmark(@PathVariable Long bookmarkId,
public ResponseEntity<?> deleteBookmark(@PathVariable Long storeId,
@AuthenticationPrincipal CustomOAuth2User customOAuth2User) {
String response = bookmarkService.deleteBookmark(storeId, customOAuth2User);
return ResponseEntity
.ok()
.body(
ApiUtils.success(
bookmarkService.deleteBookmark(bookmarkId, customOAuth2User)
response
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.nowait.domaincorerdb.user.exception.UserNotFoundException;
import com.nowait.domaincorerdb.user.repository.UserRepository;
import com.nowait.domainuserrdb.bookmark.entity.Bookmark;
import com.nowait.domainuserrdb.bookmark.exception.BookmarkNotFoundException;
import com.nowait.domainuserrdb.bookmark.repository.BookmarkRepository;
import com.nowait.domainuserrdb.oauth.dto.CustomOAuth2User;

Expand Down Expand Up @@ -88,7 +89,7 @@ public String deleteBookmark(Long storeId, CustomOAuth2User customOAuth2User) {
.orElseThrow(StoreNotFoundException::new);

Bookmark bookmark = bookmarkRepository.findByUserAndStoreAndDeletedFalse(user, store)
.orElseThrow(() -> new EntityNotFoundException(storeId + " 활성화된 bookmark가 없습니다."));
.orElseThrow(BookmarkNotFoundException::new);

if (!Objects.equals(bookmark.getUser().getId(), customOAuth2User.getUserId())) {
throw new IllegalArgumentException("you can only delete your own bookmark");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.nowait.domaincorerdb.store.exception.StoreWaitingDisabledException;
import com.nowait.domaincorerdb.token.exception.BusinessException;
import com.nowait.domaincorerdb.user.exception.UserNotFoundException;
import com.nowait.domainuserrdb.bookmark.exception.BookmarkNotFoundException;
import com.nowait.domainuserrdb.bookmark.exception.BookmarkOwnerMismatchException;
import com.nowait.domainuserrdb.bookmark.exception.DuplicateBookmarkException;

Expand Down Expand Up @@ -146,6 +147,15 @@ public ErrorResponse bookmarkOwnerMismatchException(BookmarkOwnerMismatchExcepti
return new ErrorResponse(e.getMessage(), NOT_OWN_BOOKMARK.getCode());
}

@ResponseStatus(BAD_REQUEST)
@ExceptionHandler(BookmarkNotFoundException.class)
public ErrorResponse handleBookmarkNotFoundException(
BookmarkNotFoundException e, WebRequest request) {
alarm(e, request);
log.error("handleBookmarkNotFoundException", e);
return new ErrorResponse(e.getMessage(), BOOKMARK_NOT_FOUND.getCode());
}

@ResponseStatus(NOT_FOUND)
@ExceptionHandler(UserNotFoundException.class)
public ErrorResponse userNotFoundException(UserNotFoundException e, WebRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum ErrorMessage {
// bookmark
DUPLICATE_BOOKMARK("이미 북마크한 주점입니다.", "bookmark001"),
NOT_OWN_BOOKMARK("해당 주점은 다른 사용자가 북마크한 주점입니다.", "bookmark002"),
BOOKMARK_NOT_FOUND("이미 북마크 삭제된 주점입니다.", "bookmark002"),

// menu
MENU_PARAMETER_EMPTY("메뉴 생성 시 파라미터 정보가 없습니다.", "menu001"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.nowait.domainuserrdb.bookmark.exception;

import com.nowait.common.exception.ErrorMessage;

public class BookmarkNotFoundException extends RuntimeException {
public BookmarkNotFoundException() {
super(ErrorMessage.BOOKMARK_NOT_FOUND.getMessage());
}
}