From 22b194ea36a55021cc6bc345286bb25708ffed8e Mon Sep 17 00:00:00 2001 From: gabang2 Date: Sun, 2 Jun 2024 15:45:38 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80:=20=EC=B5=9C=EA=B7=BC=20?= =?UTF-8?q?=ED=82=A4=EC=9B=8C=EB=93=9C=20=EA=B2=80=EC=83=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CulturalEventController.java | 10 +++- .../service/CulturalEventService.java | 2 - .../entity/CulturalEventSearchKeyword.java | 42 +++++++++++++++ .../CulturalEventSearchKeywordRepository.java | 16 ++++++ .../CulturalEventSearchKeywordService.java | 53 +++++++++++++++++++ .../backend/domain/member/entity/Member.java | 4 ++ 6 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/main/java/project/backend/domain/keyword/entity/CulturalEventSearchKeyword.java create mode 100644 src/main/java/project/backend/domain/keyword/repository/CulturalEventSearchKeywordRepository.java create mode 100644 src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java diff --git a/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java b/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java index c7bdc78..fec5189 100644 --- a/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java +++ b/src/main/java/project/backend/domain/culturalevent/controller/CulturalEventController.java @@ -15,6 +15,8 @@ import project.backend.domain.culturalevent.service.CulturalEventService; import project.backend.domain.culturalevnetcategory.entity.CategoryTitle; import project.backend.domain.culturalevnetinfo.service.CulturalEventInfoService; +import project.backend.domain.keyword.entity.CulturalEventSearchKeyword; +import project.backend.domain.keyword.service.CulturalEventSearchKeywordService; import project.backend.domain.member.entity.Member; import project.backend.domain.ticketingsite.mapper.TicketingSiteMapper; import project.backend.domain.member.service.MemberJwtService; @@ -33,6 +35,7 @@ public class CulturalEventController { private final CulturalEventInfoService culturalEventInfoService; private final TicketingSiteMapper ticketingSiteMapper; private final MemberJwtService memberJwtService; + private final CulturalEventSearchKeywordService culturalEventSearchKeywordService; @ApiOperation(value = "문화생활 리스트 조회", notes = "`ordering` : ticketOpenDate(오픈 다가온 순) | -point(인기순) | -updatedDate(최근순) | recommend(추천순) | endDate(공연마감순)\n" + @@ -52,7 +55,12 @@ public ResponseEntity getCulturalEventList( // Member Member member = memberJwtService.getMember(); - // Response + // Save Search Keyword + if (keyword != null) { + culturalEventSearchKeywordService.createCulturalEventSearchKeyword(member, keyword); + } + + // Get Cultural Event List culturalEventList = culturalEventService.getCulturalEventList(page, size, categories, ordering, isOpened, latitude, longitude, keyword); List culturalEventResponseDtoList = culturalEventMapper .culturalEventToCulturalEventListDtos(culturalEventList); diff --git a/src/main/java/project/backend/domain/culturalevent/service/CulturalEventService.java b/src/main/java/project/backend/domain/culturalevent/service/CulturalEventService.java index 1dd2ab3..6651009 100644 --- a/src/main/java/project/backend/domain/culturalevent/service/CulturalEventService.java +++ b/src/main/java/project/backend/domain/culturalevent/service/CulturalEventService.java @@ -1,7 +1,6 @@ package project.backend.domain.culturalevent.service; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import project.backend.domain.culturalevent.entity.CulturalEvent; @@ -19,7 +18,6 @@ import java.time.Duration; import java.time.LocalDateTime; -import java.util.Arrays; import java.util.List; import java.util.Optional; diff --git a/src/main/java/project/backend/domain/keyword/entity/CulturalEventSearchKeyword.java b/src/main/java/project/backend/domain/keyword/entity/CulturalEventSearchKeyword.java new file mode 100644 index 0000000..e07a780 --- /dev/null +++ b/src/main/java/project/backend/domain/keyword/entity/CulturalEventSearchKeyword.java @@ -0,0 +1,42 @@ +package project.backend.domain.keyword.entity; + +import lombok.*; +import project.backend.domain.common.entity.BaseEntity; +import project.backend.domain.member.entity.Member; + +import javax.persistence.*; +import java.util.Optional; + + +@Entity +@Getter +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public class CulturalEventSearchKeyword extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public Long id; + + public String keyword; + + public Boolean isDeleted; + + @ManyToOne(fetch = FetchType.LAZY) + public Member member; + + @Builder + public CulturalEventSearchKeyword(String keyword) { + this.keyword = keyword; + this.isDeleted = false; + } + + public void setMember(Member member) { + if (this.member != null) { + if (this.member.getCulturalEventSearchKeywordList().contains(this)) { + this.member.getCulturalEventSearchKeywordList().remove(this); + } + } + this.member = Optional.ofNullable(member).orElse(this.member); + this.member.getCulturalEventSearchKeywordList().add(this); + } +} diff --git a/src/main/java/project/backend/domain/keyword/repository/CulturalEventSearchKeywordRepository.java b/src/main/java/project/backend/domain/keyword/repository/CulturalEventSearchKeywordRepository.java new file mode 100644 index 0000000..84ccad0 --- /dev/null +++ b/src/main/java/project/backend/domain/keyword/repository/CulturalEventSearchKeywordRepository.java @@ -0,0 +1,16 @@ +package project.backend.domain.keyword.repository; + +import io.lettuce.core.dynamic.annotation.Param; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import project.backend.domain.keyword.entity.CulturalEventSearchKeyword; +import project.backend.domain.member.entity.Member; + +import java.util.List; + +public interface CulturalEventSearchKeywordRepository extends JpaRepository { + + List findCulturalEventSearchKeywordsByIsDeletedFalseAndMember(Member member); + @Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM CulturalEventSearchKeyword c WHERE c.isDeleted = false AND c.member = :member AND c.keyword = :keyword") + Boolean existsByIsDeletedFalseAndMemberAndKeyword(@Param("member") Member member, @Param("keyword") String keyword); +} diff --git a/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java b/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java new file mode 100644 index 0000000..d7cac9e --- /dev/null +++ b/src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java @@ -0,0 +1,53 @@ +package project.backend.domain.keyword.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import project.backend.domain.keyword.entity.CulturalEventSearchKeyword; +import project.backend.domain.keyword.repository.CulturalEventSearchKeywordRepository; +import project.backend.domain.member.entity.Member; +import project.backend.domain.quit.entity.Quit; +import project.backend.domain.ticket.entity.Ticket; +import project.backend.global.error.exception.BusinessException; +import project.backend.global.error.exception.ErrorCode; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional +public class CulturalEventSearchKeywordService { + + private final CulturalEventSearchKeywordRepository culturalEventSearchKeywordRepository; + + // 사용자, 키워드 등록 + public void createCulturalEventSearchKeyword(Member member, String keyword) { + if (!culturalEventSearchKeywordRepository.existsByIsDeletedFalseAndMemberAndKeyword(member, keyword)) { + CulturalEventSearchKeyword culturalEventSearchKeyword = CulturalEventSearchKeyword.builder() + .keyword(keyword).build(); + + culturalEventSearchKeyword.setMember(member); + culturalEventSearchKeywordRepository.save(culturalEventSearchKeyword); + } + } + + // 키워드 삭제 + public void deleteCulturalEventSearchKeyword(Long id) { + CulturalEventSearchKeyword culturalEventSearchKeyword = verifiedCulturalEventSearchKeyword(id); + culturalEventSearchKeyword.isDeleted = true; + } + + // 사용자 키워드 목록 조회 + public List getCulturalEventSearchKeywordList(Member member) { + return culturalEventSearchKeywordRepository.findCulturalEventSearchKeywordsByIsDeletedFalseAndMember(member); + } + + + // 인기 키워드 생성(1시간 지난 키워드(is_deleted 중에서) 삭제) + // TODO : 아직 개발하지 않았음. + + // 키워드 검증 + private CulturalEventSearchKeyword verifiedCulturalEventSearchKeyword(Long id) { + return culturalEventSearchKeywordRepository.findById(id).orElseThrow(() -> new BusinessException(ErrorCode.NOTICE_NOT_FOUND)); + } +} diff --git a/src/main/java/project/backend/domain/member/entity/Member.java b/src/main/java/project/backend/domain/member/entity/Member.java index 51d50dc..14294e1 100644 --- a/src/main/java/project/backend/domain/member/entity/Member.java +++ b/src/main/java/project/backend/domain/member/entity/Member.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import lombok.RequiredArgsConstructor; +import project.backend.domain.keyword.entity.CulturalEventSearchKeyword; import project.backend.domain.like.entity.CulturalEventLike; import project.backend.domain.member.dto.MemberSignupDto; import project.backend.domain.memberTicketLike.entity.MemberTicketLike; @@ -69,6 +70,9 @@ public class Member extends BaseEntity { @OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) public List culturalEventVisitList = new ArrayList<>(); + @OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) + public List culturalEventSearchKeywordList = new ArrayList<>(); + @Builder public Member(SocialType socialType, String socialId, String nickname, String profileUrl, String refreshToken) { this.socialType = socialType;