diff --git a/src/main/java/Journey/Together/domain/place/controller/PlaceController.java b/src/main/java/Journey/Together/domain/place/controller/PlaceController.java index ae83914..c439975 100644 --- a/src/main/java/Journey/Together/domain/place/controller/PlaceController.java +++ b/src/main/java/Journey/Together/domain/place/controller/PlaceController.java @@ -9,6 +9,7 @@ import Journey.Together.global.security.PrincipalDetails; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.hibernate.annotations.Fetch; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -81,4 +82,11 @@ public ApiResponse> getBookmarkPlaceNames( return ApiResponse.success(Success.GET_BOOKMARK_PLACE_NAMES_SUCCESS, placeService.getBookmarkPlaceNames(principalDetails.getMember())); } + @PatchMapping("/bookmark/{placeId}") + public ApiResponse> getBookmarkPlaceNames( + @AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable Long placeId){ + placeService.bookmark(principalDetails.getMember(), placeId); + return ApiResponse.success(Success.CHANGE_BOOKMARK_SUCCESS); + } + } diff --git a/src/main/java/Journey/Together/domain/place/service/PlaceService.java b/src/main/java/Journey/Together/domain/place/service/PlaceService.java index 14c44e1..e585324 100644 --- a/src/main/java/Journey/Together/domain/place/service/PlaceService.java +++ b/src/main/java/Journey/Together/domain/place/service/PlaceService.java @@ -178,6 +178,25 @@ public List getBookmarkPlaceNames(Member member){ return placeBookmarkList.stream().map(PlaceBookmarkDto::of).toList(); } + + @Transactional + // 북마크 상태변경 + public void bookmark(Member member, Long placeId){ + Place place = getPlace(placeId); + + PlaceBookmark placeBookmark = placeBookmarkRepository.findPlaceBookmarkByPlaceAndMember(place, member);// 북마크 설정 + if (placeBookmark == null) { + PlaceBookmark newPlaceBookmark = PlaceBookmark.builder() + .place(place) + .member(member) + .build(); + placeBookmarkRepository.save(newPlaceBookmark); + } else { + // 북마크 해체 + placeBookmarkRepository.delete(placeBookmark); + } + } + private List getPlaceRes(List list){ List placeList = new ArrayList<>(); diff --git a/src/main/java/Journey/Together/domain/placeBookbark/entity/PlaceBookmark.java b/src/main/java/Journey/Together/domain/placeBookbark/entity/PlaceBookmark.java index b9ef303..294b20e 100644 --- a/src/main/java/Journey/Together/domain/placeBookbark/entity/PlaceBookmark.java +++ b/src/main/java/Journey/Together/domain/placeBookbark/entity/PlaceBookmark.java @@ -25,4 +25,10 @@ public class PlaceBookmark extends BaseTimeEntity { @JoinColumn(name = "place_id") Place place; + @Builder + public PlaceBookmark(Member member, Place place){ + this.member=member; + this.place=place; + } + } diff --git a/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java b/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java index 5813839..a7dd11f 100644 --- a/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java +++ b/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java @@ -17,5 +17,7 @@ public interface PlaceBookmarkRepository extends JpaRepository findAllByMemberOrderByPlaceNameAsc(Member member); + PlaceBookmark findPlaceBookmarkByPlaceAndMember(Place place, Member member); + } diff --git a/src/main/java/Journey/Together/global/exception/Success.java b/src/main/java/Journey/Together/global/exception/Success.java index 46b461d..4f3fd85 100644 --- a/src/main/java/Journey/Together/global/exception/Success.java +++ b/src/main/java/Journey/Together/global/exception/Success.java @@ -55,7 +55,7 @@ public enum Success { UPDATE_CATEGORY_TITLE_SUCCESS(HttpStatus.OK, "카테고리 수정 완료"), UPDATE_TIMER_DATETIME_SUCCESS(HttpStatus.OK, "타이머 시간/날짜 수정 완료"), UPDATE_TIMER_COMMENT_SUCCESS(HttpStatus.OK, "타이머 코멘트 수정 완료"), - CHANGE_TIMER_ALARM_SUCCESS(HttpStatus.OK, "타이머 알람여부 수정 완료"), + CHANGE_BOOKMARK_SUCCESS(HttpStatus.OK, "북마크 상태 수정 완료"), PUSH_ALARM_PERIODIC_SUCCESS(HttpStatus.OK, "푸시알림 활성에 성공했습니다."), PUSH_ALARM_SUCCESS(HttpStatus.OK, "푸시알림 전송에 성공했습니다."), CLEAR_SCHEDULED_TASKS_SUCCESS(HttpStatus.OK, "스케줄러에서 예약된 작업을 제거했습니다."),