Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
임시로 랜덤한 페이징을 반환하는 api 구현
  • Loading branch information
yooonwodyd committed Nov 3, 2024
1 parent ece63e6 commit 814bb5f
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 @@ -78,4 +79,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 @@ -10,6 +10,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 @@ -23,6 +24,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) {
//TODO ArtistInfo 코드 병합시 수정 예정
Product product = productSaveRequest.toEntity(null);
Expand Down

0 comments on commit 814bb5f

Please sign in to comment.