Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

점포 북마크 기능 개선 #68

Merged
merged 1 commit into from
Sep 25, 2024
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 @@ -2,15 +2,14 @@

import com.dongyang.dongpo.apiresponse.ApiResponse;
import com.dongyang.dongpo.domain.member.Member;
import com.dongyang.dongpo.dto.bookmark.BookmarkDto;
import com.dongyang.dongpo.service.bookmark.BookmarkService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/bookmark")
Expand All @@ -21,15 +20,15 @@ public class BookmarkController {

@PostMapping("")
@Operation(summary = "북마크 추가")
public ResponseEntity<ApiResponse<String>> addBookmark(@RequestBody Long storeId,
@AuthenticationPrincipal Member member) throws Exception {
bookmarkService.addBookmark(member, storeId);
public ResponseEntity<ApiResponse<String>> addBookmark(@RequestBody Map<String, Long> request,
@AuthenticationPrincipal Member member) {
bookmarkService.addBookmark(member, request.get("storeId"));
return ResponseEntity.ok(new ApiResponse<>("success"));
}

@DeleteMapping("/{id}")
public ResponseEntity<ApiResponse<String>> deleteBookmark(@PathVariable Long id,
@AuthenticationPrincipal Member member) throws Exception {
@AuthenticationPrincipal Member member) {
bookmarkService.deleteBookmark(id, member);
return ResponseEntity.ok(new ApiResponse<>("success"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Table(name = "store_bookmark")
@Table(name = "store_bookmark", uniqueConstraints = {
@UniqueConstraint(columnNames = {"member_id", "store_id"})
})
public class StoreBookmark {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/dongyang/dongpo/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ErrorCode {

STORE_REGISTRATION_NOT_VALID(400, "위치 정보가 오차를 벗어났습니다."),
ARGUMENT_NOT_SATISFIED(400, "요청이 잘못되었습니다."),
BOOKMARK_ALREADY_EXISTS(400, "해당 점포의 북마크가 이미 존재합니다."),
;

private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.dongyang.dongpo.repository.store.StoreRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -35,7 +36,11 @@ public void addBookmark(Member member, Long storeId) {
.member(member)
.build();

bookmarkRepository.save(bookmark);
try {
bookmarkRepository.save(bookmark);
} catch (DataIntegrityViolationException ignore) {
throw new CustomException(ErrorCode.BOOKMARK_ALREADY_EXISTS);
}

log.info("Member Id : {} is Add Bookmark Store Id : {}", member.getId(), storeId);
}
Expand Down