-
Notifications
You must be signed in to change notification settings - Fork 4
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
26 changed files
with
648 additions
and
31 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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/helpmeCookies/global/entity/BaseTimeEntity.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,21 @@ | ||
package com.helpmeCookies.global.entity; | ||
|
||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Getter | ||
public abstract class BaseTimeEntity { | ||
|
||
@CreatedDate | ||
private LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime modifiedDate; | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/helpmeCookies/product/controller/docs/ProductApiDocs.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,21 @@ | ||
package com.helpmeCookies.product.controller.docs; | ||
|
||
import com.helpmeCookies.product.dto.ProductPage.Paging; | ||
import com.helpmeCookies.product.util.ProductSort; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "상품 관련 기능", description = "상품 관련 API") | ||
public interface ProductApiDocs { | ||
|
||
@Operation(summary = "상품 검색") | ||
ResponseEntity<Paging> getProductsByPage( | ||
String query, | ||
@Parameter(description = "default value 20") int size, | ||
int page, | ||
ProductSort productSort | ||
); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/helpmeCookies/product/dto/ProductPage.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,46 @@ | ||
package com.helpmeCookies.product.dto; | ||
|
||
import com.helpmeCookies.product.repository.dto.ProductSearch; | ||
import java.util.List; | ||
import org.springframework.data.domain.Page; | ||
|
||
public class ProductPage { | ||
|
||
public record Info( | ||
Long id, | ||
String name, | ||
String artist, | ||
Long price, | ||
String thumbnailUrl | ||
) { | ||
public static Info from(ProductSearch productSearch) { | ||
return new Info( | ||
productSearch.getId(), | ||
productSearch.getName(), | ||
productSearch.getArtist(), | ||
productSearch.getPrice(), | ||
productSearch.getThumbnailUrl() | ||
); | ||
} | ||
|
||
public static List<Info> of(List<ProductSearch> content) { | ||
return content.stream() | ||
.map(Info::from) | ||
.toList(); | ||
} | ||
} | ||
|
||
public record Paging ( | ||
boolean hasNext, | ||
List<Info> products | ||
) { | ||
|
||
public static Paging from(Page<ProductSearch> productPage) { | ||
return new Paging( | ||
productPage.hasNext(), | ||
Info.of(productPage.getContent()) | ||
); | ||
} | ||
} | ||
|
||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/helpmeCookies/product/repository/ProductRepository.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 |
---|---|---|
@@ -1,9 +1,23 @@ | ||
package com.helpmeCookies.product.repository; | ||
|
||
import com.helpmeCookies.product.entity.Product; | ||
import com.helpmeCookies.product.repository.dto.ProductSearch; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProductRepository extends JpaRepository<Product, Long> { | ||
|
||
@Query(value = "SELECT p.id, p.name, p.thumbnail_url, a.nickname AS artist, p.price " + | ||
"FROM product p JOIN artist_info a ON p.artist_info_id = a.id " + | ||
"WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)", | ||
countQuery = "SELECT COUNT(*) " + | ||
"FROM product p JOIN artist_info a ON p.artist_info_id = a.id " + | ||
"WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)", | ||
nativeQuery = true) // Index 사용 | ||
Page<ProductSearch> findByNameWithIdx(@Param("query") String query, Pageable pageable); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/helpmeCookies/product/repository/dto/ProductSearch.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,10 @@ | ||
package com.helpmeCookies.product.repository.dto; | ||
|
||
|
||
public interface ProductSearch { | ||
Long getId(); | ||
String getName(); | ||
String getThumbnailUrl(); | ||
String getArtist(); | ||
Long getPrice(); | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/helpmeCookies/product/service/dto/ProductPage.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,44 @@ | ||
package com.helpmeCookies.product.service.dto; | ||
|
||
import com.helpmeCookies.product.repository.dto.ProductSearch; | ||
import java.util.List; | ||
import org.springframework.data.domain.Page; | ||
|
||
public class ProductPage { | ||
|
||
public record Info( | ||
Long id, | ||
String name, | ||
String artist, | ||
Long price | ||
) { | ||
public static Info from(ProductSearch productSearch) { | ||
return new Info( | ||
productSearch.getId(), | ||
productSearch.getName(), | ||
productSearch.getArtist(), | ||
productSearch.getPrice() | ||
); | ||
} | ||
|
||
public static List<Info> of(List<ProductSearch> content) { | ||
return content.stream() | ||
.map(Info::from) | ||
.toList(); | ||
} | ||
} | ||
|
||
public record Paging ( | ||
boolean hasNext, | ||
List<Info> products | ||
) { | ||
|
||
public static Paging from(Page<ProductSearch> productPage) { | ||
return new Paging( | ||
productPage.hasNext(), | ||
Info.of(productPage.getContent()) | ||
); | ||
} | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/helpmeCookies/product/util/ProductSort.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,5 @@ | ||
package com.helpmeCookies.product.util; | ||
|
||
public enum ProductSort { | ||
RELEVANCE, LATEST | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/helpmeCookies/product/util/SortUtil.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,14 @@ | ||
package com.helpmeCookies.product.util; | ||
|
||
import org.springframework.data.domain.Sort; | ||
|
||
public class SortUtil { | ||
|
||
public static Sort convertProductSort(ProductSort productSort) { | ||
return switch (productSort) { | ||
case LATEST -> Sort.by(Sort.Order.desc("created_date")); | ||
default -> Sort.unsorted(); | ||
}; | ||
} | ||
|
||
} |
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
Oops, something went wrong.