Skip to content

Commit

Permalink
Merge pull request #34 from gamgyul-code/feat/29-bookmark-category
Browse files Browse the repository at this point in the history
북마크시 카테고리 선택 기능 구현 완료
  • Loading branch information
gywns0417 authored Nov 21, 2024
2 parents 05273de + 9510ce4 commit 7a617ce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.gamgyul_code.halmang_vision.member.domain.MemberRepository;
import com.gamgyul_code.halmang_vision.member.dto.ApiMember;
import com.gamgyul_code.halmang_vision.spot.domain.Spot;
import com.gamgyul_code.halmang_vision.spot.domain.SpotCategory;
import com.gamgyul_code.halmang_vision.spot.domain.SpotRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -28,13 +29,13 @@ public class BookmarkService {
private final MemberRepository memberRepository;

@Transactional
public void createSpotBookmark(long spotId, ApiMember apiMember) {
public void createSpotBookmark(long spotId, SpotCategory spotCategory, ApiMember apiMember) {
Member member = apiMember.toMember(memberRepository);
Spot spot = findSpotById(spotId);

validateBookmarkExists(member, spot, false);

bookmarkRepository.save(bookmarkGenerator.generate(spot, member));
bookmarkRepository.save(bookmarkGenerator.generate(spot, member, spotCategory));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import com.gamgyul_code.halmang_vision.global.utils.BaseTimeEntity;
import com.gamgyul_code.halmang_vision.member.domain.Member;
import com.gamgyul_code.halmang_vision.spot.domain.Spot;
import com.gamgyul_code.halmang_vision.spot.domain.SpotCategory;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -26,6 +30,10 @@ public class Bookmark extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(value = EnumType.STRING)
@NotNull
SpotCategory spotCategory;

@ManyToOne
@JoinColumn(name = "spot_id")
private Spot spot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import com.gamgyul_code.halmang_vision.member.domain.Member;
import com.gamgyul_code.halmang_vision.spot.domain.Spot;
import com.gamgyul_code.halmang_vision.spot.domain.SpotCategory;
import org.springframework.stereotype.Component;

@Component
public class BookmarkGenerator {

public Bookmark generate(Spot spot, Member member) {
public Bookmark generate(Spot spot, Member member, SpotCategory spotCategory) {
return Bookmark.builder()
.member(member)
.spot(spot)
.spotCategory(spotCategory)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gamgyul_code.halmang_vision.bookmark.application.BookmarkService;
import com.gamgyul_code.halmang_vision.global.utils.AuthPrincipal;
import com.gamgyul_code.halmang_vision.member.dto.ApiMember;
import com.gamgyul_code.halmang_vision.spot.domain.SpotCategory;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -22,9 +23,10 @@ public class BookmarkController {
private final BookmarkService bookmarkService;

@Operation(summary = "관광지 북마크 생성", description = "해당 회원에게 관광지 북마크를 생성한다.")
@PostMapping("/spots/{spotId}")
public void createSpotBookmark(@PathVariable Long spotId, @Parameter(hidden = true) @AuthPrincipal ApiMember apiMember) {
bookmarkService.createSpotBookmark(spotId, apiMember);
@PostMapping("/spots/{spotId}/{spotCategory}")
public void createSpotBookmark(@PathVariable Long spotId, @PathVariable SpotCategory spotCategory,
@Parameter(hidden = true) @AuthPrincipal ApiMember apiMember) {
bookmarkService.createSpotBookmark(spotId, spotCategory, apiMember);
}

@Operation(summary = "관광지 북마크 삭제", description = "해당 회원에게 관광지 북마크를 삭제한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public static class SpotTranslationDetailResponse {
@Schema(description = "북마크 여부", example = "true")
private boolean bookmarked;

@Schema(description = "관광지 카테고리", example = "HISTORY, LOVE")
private List<SpotCategory> spotCategories;

public static SpotTranslationDetailResponse fromEntity(SpotTranslation spotTranslation, boolean isBookmarked) {
return SpotTranslationDetailResponse.builder()
.spotTranslationId(spotTranslation.getId())
Expand All @@ -187,6 +190,7 @@ public static SpotTranslationDetailResponse fromEntity(SpotTranslation spotTrans
.topographyStory(spotTranslation.getTopographyStory())
.caution(spotTranslation.getCaution())
.bookmarked(isBookmarked)
.spotCategories(spotTranslation.getSpot().getSpotCategory())
.build();
}
}
Expand Down Expand Up @@ -215,6 +219,9 @@ public static class SimpleSpotTranslationResponse {
@Schema(description = "북마크 여부", example = "true")
private boolean bookmarked;

@Schema(description = "관광지 카테고리", example = "HISTORY, LOVE")
private List<SpotCategory> spotCategories;

public static SimpleSpotTranslationResponse fromEntity(SpotTranslation spotTranslation, boolean isBookmarked) {
return SimpleSpotTranslationResponse.builder()
.spotTranslationId(spotTranslation.getId())
Expand All @@ -223,6 +230,7 @@ public static SimpleSpotTranslationResponse fromEntity(SpotTranslation spotTrans
.imgUrl(spotTranslation.getSpot().getImgUrl())
.simpleExplanation(spotTranslation.getSimpleExplanation())
.bookmarked(isBookmarked)
.spotCategories(spotTranslation.getSpot().getSpotCategory())
.build();
}
}
Expand Down

0 comments on commit 7a617ce

Please sign in to comment.