Skip to content

Commit

Permalink
추가: 최근 키워드 검색
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosiee committed Jun 2, 2024
1 parent 628a5cd commit 22b194e
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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" +
Expand All @@ -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<CulturalEvent> culturalEventList = culturalEventService.getCulturalEventList(page, size, categories, ordering, isOpened, latitude, longitude, keyword);
List<CulturalEventListDto> culturalEventResponseDtoList = culturalEventMapper
.culturalEventToCulturalEventListDtos(culturalEventList);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +18,6 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<CulturalEventSearchKeyword, Long> {

List<CulturalEventSearchKeyword> 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);
}
Original file line number Diff line number Diff line change
@@ -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<CulturalEventSearchKeyword> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,6 +70,9 @@ public class Member extends BaseEntity {
@OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public List<CulturalEventVisit> culturalEventVisitList = new ArrayList<>();

@OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
public List<CulturalEventSearchKeyword> culturalEventSearchKeywordList = new ArrayList<>();

@Builder
public Member(SocialType socialType, String socialId, String nickname, String profileUrl, String refreshToken) {
this.socialType = socialType;
Expand Down

0 comments on commit 22b194e

Please sign in to comment.