store update
This commit is contained in:
parent
68919c1615
commit
acafa181ba
@ -1,6 +1,7 @@
|
||||
package com.ktds.hi.store.biz.usecase.out;
|
||||
|
||||
import com.ktds.hi.store.domain.Store;
|
||||
import com.ktds.hi.store.infra.gateway.entity.TagEntity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -14,6 +15,15 @@ import java.util.Optional;
|
||||
*/
|
||||
public interface StoreRepositoryPort {
|
||||
|
||||
/**
|
||||
* 매장의 태그 목록 조회
|
||||
*/
|
||||
List<TagEntity> findTagsByStoreId(Long storeId);
|
||||
|
||||
/**
|
||||
* 여러 매장의 태그 목록 조회
|
||||
*/
|
||||
List<TagEntity> findTagsByStoreIds(List<Long> storeIds);
|
||||
/**
|
||||
* 태그로 매장 검색 (OR 조건)
|
||||
*/
|
||||
|
||||
@ -5,12 +5,15 @@ import com.ktds.hi.store.domain.StoreStatus;
|
||||
import com.ktds.hi.store.biz.usecase.out.StoreRepositoryPort;
|
||||
import com.ktds.hi.store.biz.usecase.out.StoreSearchCriteria;
|
||||
import com.ktds.hi.store.infra.gateway.entity.StoreEntity;
|
||||
import com.ktds.hi.store.infra.gateway.entity.TagEntity;
|
||||
import com.ktds.hi.store.infra.gateway.repository.StoreJpaRepository;
|
||||
import com.ktds.hi.store.infra.gateway.repository.TagJpaRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ktds.hi.store.infra.gateway.entity.TagEntity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -29,7 +32,36 @@ import java.util.stream.Collectors;
|
||||
public class StoreRepositoryAdapter implements StoreRepositoryPort {
|
||||
|
||||
private final StoreJpaRepository storeJpaRepository;
|
||||
private final TagJpaRepository tagJpaRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public List<TagEntity> findTagsByStoreId(Long storeId) {
|
||||
return tagJpaRepository.findByStoreId(storeId)
|
||||
.stream()
|
||||
.map(this::tagToDomain)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TagEntity> findTagsByStoreIds(List<Long> storeIds) {
|
||||
return tagJpaRepository.findByStoreIds(storeIds)
|
||||
.stream()
|
||||
.map(this::tagToDomain)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private TagEntity tagToDomain(TagEntity entity) {
|
||||
return TagEntity.builder()
|
||||
.id(entity.getId())
|
||||
.tagName(entity.getTagName())
|
||||
.tagCategory(entity.getTagCategory())
|
||||
.tagColor(entity.getTagColor())
|
||||
.sortOrder(entity.getSortOrder())
|
||||
.isActive(entity.getIsActive())
|
||||
.clickCount(entity.getClickCount())
|
||||
.build();
|
||||
}
|
||||
@Override
|
||||
public List<Store> findStoresByOwnerId(Long ownerId) {
|
||||
return storeJpaRepository.findByOwnerId(ownerId)
|
||||
|
||||
@ -8,7 +8,8 @@ import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@ -76,6 +77,14 @@ public class StoreEntity {
|
||||
@Column(name = "image_url", length = 500)
|
||||
private String imageUrl;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "store_tags",
|
||||
joinColumns = @JoinColumn(name = "store_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "tag_id")
|
||||
)
|
||||
private Set<TagEntity> tags = new HashSet<>();
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@ -3,6 +3,11 @@ package com.ktds.hi.store.infra.gateway.entity;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import com.ktds.hi.store.domain.TagCategory;
|
||||
import com.ktds.hi.store.infra.gateway.entity.StoreEntity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 태그 엔티티 클래스
|
||||
* 매장 태그 정보를 저장
|
||||
@ -22,6 +27,9 @@ public class TagEntity {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToMany(mappedBy = "tags")
|
||||
private Set<StoreEntity> stores = new HashSet<>();
|
||||
|
||||
@Column(name = "tag_name", nullable = false, length = 50)
|
||||
private String tagName; // 매운맛, 깨끗한, 유제품 등
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package com.ktds.hi.store.infra.gateway.repository;
|
||||
|
||||
import com.ktds.hi.store.domain.TagCategory;
|
||||
import com.ktds.hi.store.infra.gateway.entity.TagEntity;
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@ -25,6 +26,16 @@ public interface TagJpaRepository extends JpaRepository<TagEntity, Long> {
|
||||
*/
|
||||
List<TagEntity> findByIsActiveTrueOrderByTagName();
|
||||
|
||||
@Query("SELECT t FROM TagEntity t JOIN t.stores s WHERE s.id = :storeId AND t.isActive = true")
|
||||
List<TagEntity> findByStoreId(@Param("storeId") Long storeId);
|
||||
|
||||
@Query("SELECT t FROM TagEntity t JOIN t.stores s WHERE s.id IN :storeIds AND t.isActive = true")
|
||||
List<TagEntity> findByStoreIds(@Param("storeIds") List<Long> storeIds);
|
||||
|
||||
@Query("SELECT t.tagName, COUNT(s) as storeCount FROM TagEntity t " +
|
||||
"JOIN t.stores s WHERE t.isActive = true " +
|
||||
"GROUP BY t.tagName ORDER BY storeCount DESC")
|
||||
List<Object[]> findTopTagsByStoreCount(@Param("limit") int limit);
|
||||
/**
|
||||
* 태그명으로 조회
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user