Skip to content

Commit

Permalink
[#52] feat: 북마크 상태 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihye committed Jun 7, 2024
1 parent 2343416 commit add9cc9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,4 +82,11 @@ public ApiResponse<List<PlaceBookmarkDto>> getBookmarkPlaceNames(
return ApiResponse.success(Success.GET_BOOKMARK_PLACE_NAMES_SUCCESS, placeService.getBookmarkPlaceNames(principalDetails.getMember()));
}

@PatchMapping("/bookmark/{placeId}")
public ApiResponse<List<PlaceBookmarkDto>> getBookmarkPlaceNames(
@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable Long placeId){
placeService.bookmark(principalDetails.getMember(), placeId);
return ApiResponse.success(Success.CHANGE_BOOKMARK_SUCCESS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ public List<PlaceBookmarkDto> 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<PlaceRes> getPlaceRes(List<Place> list){
List<PlaceRes> placeList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public interface PlaceBookmarkRepository extends JpaRepository<PlaceBookmark, Lo

List<PlaceBookmark> findAllByMemberOrderByPlaceNameAsc(Member member);

PlaceBookmark findPlaceBookmarkByPlaceAndMember(Place place, Member member);


}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "스케줄러에서 예약된 작업을 제거했습니다."),
Expand Down

0 comments on commit add9cc9

Please sign in to comment.