Skip to content

Commit

Permalink
Merge pull request #80 from yooonwodyd/weekly
Browse files Browse the repository at this point in the history
[yooonwodyd-> weekly] 상품 임시 피드 추가 #79
  • Loading branch information
yooonwodyd authored Nov 3, 2024
2 parents 0005206 + 814bb5f commit 3b565d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.helpmeCookies.product.util.ProductSort;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -82,4 +83,12 @@ public ResponseEntity<ProductPage.Paging> getProductsByPage(

return ResponseEntity.ok(productService.getProductsByPage(query, pageable));
}

@GetMapping("/feed")
public ResponseEntity<ProductPage.Paging> getProductsWithRandomPaging(
@RequestParam(name = "size", required = false, defaultValue = "20") int size
) {
Pageable pageable = PageRequest.of(0, size);
return ResponseEntity.ok(productService.getProductsWithRandomPaging(pageable));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public interface ProductRepository extends JpaRepository<Product, Long> {
"WHERE MATCH(p.name) AGAINST (:query IN BOOLEAN MODE)",
nativeQuery = true) // Index 사용
Page<ProductSearch> findByNameWithIdx(@Param("query") String query, Pageable pageable);


@Query("SELECT p FROM Product p ORDER BY FUNCTION('RAND')")
Page<ProductSearch> findAllRandom(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;

@Service
@RequiredArgsConstructor
Expand All @@ -26,6 +27,13 @@ public ProductPage.Paging getProductsByPage(String query, Pageable pageable) {
return ProductPage.Paging.from(productPage);
}

@Transactional
@GetMapping
public ProductPage.Paging getProductsWithRandomPaging(Pageable pageable) {
var productPage = productRepository.findAllRandom(pageable);
return ProductPage.Paging.from(productPage);
}

public Product save(ProductRequest productSaveRequest) {
ArtistInfo artistInfo = artistInfoRepository.findById(productSaveRequest.artistInfoId())
.orElseThrow(() -> new IllegalArgumentException("유효하지 않은 작가 정보입니다."));
Expand Down

0 comments on commit 3b565d1

Please sign in to comment.