-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/project/backend/domain/keyword/entity/CulturalEventSearchKeyword.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../java/project/backend/domain/keyword/repository/CulturalEventSearchKeywordRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/project/backend/domain/keyword/service/CulturalEventSearchKeywordService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters