Feature/ozon-parser-v0.1: правка апишки
This commit is contained in:
parent
171cc650f1
commit
fd71513bbf
@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import ru.pricepulse.parsingservice.enumeration.Category;
|
||||
import ru.pricepulse.parsingservice.enumeration.Marketplace;
|
||||
import ru.pricepulse.parsingservice.persistence.entity.ProductEntity;
|
||||
|
||||
@Repository
|
||||
@ -23,5 +24,5 @@ public interface ProductRepository extends JpaRepository<ProductEntity, Long> {
|
||||
|
||||
Optional<ProductEntity> findByUrl(String url);
|
||||
|
||||
Page<ProductEntity> findAllByCategory(Category category, Pageable pageable);
|
||||
Page<ProductEntity> findAllByMarketplaceAndCategory(Marketplace marketplace, Category category, Pageable pageable);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.pricepulse.parsingservice.enumeration.Category;
|
||||
import ru.pricepulse.parsingservice.enumeration.Marketplace;
|
||||
import ru.pricepulse.parsingservice.ozon_parser.service.dto.ParsedData;
|
||||
import ru.pricepulse.parsingservice.persistence.entity.PriceHistoryEntity;
|
||||
import ru.pricepulse.parsingservice.persistence.entity.PriceHistoryId;
|
||||
@ -59,16 +60,19 @@ public class ProductService {
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public PriceHistoryDto findPriceHistoryByRange(String productUrl, ZonedDateTime from, ZonedDateTime to) {
|
||||
public PriceHistoryDto findPriceHistoryByRange(String productUrl,
|
||||
ZonedDateTime from,
|
||||
ZonedDateTime to) {
|
||||
var priceHistory = productPriceRepository
|
||||
.findAllById_ProductUrlAndIdDateAfterAndId_DateBeforeOrderById_DateAsc(productUrl, from, to);
|
||||
return priceHistoryMapper.toPriceHistoryDto(priceHistory);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public ProductsPageDto findAllProductsByPage(Category category,
|
||||
public ProductsPageDto findAllProductsByPage(Marketplace marketplace,
|
||||
Category category,
|
||||
Pageable pageable) {
|
||||
var page = productRepository.findAllByCategory(category, pageable);
|
||||
var page = productRepository.findAllByMarketplaceAndCategory(marketplace, category, pageable);
|
||||
return new ProductsPageDto(
|
||||
page.getNumberOfElements(),
|
||||
page.getTotalPages(),
|
||||
|
@ -5,19 +5,23 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.pricepulse.parsingservice.ozon_parser.enumeration.OzonCategory;
|
||||
import ru.pricepulse.parsingservice.enumeration.Category;
|
||||
import ru.pricepulse.parsingservice.enumeration.Marketplace;
|
||||
import ru.pricepulse.parsingservice.ozon_parser.service.OzonService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/ozon")
|
||||
@RequestMapping("/api/v1/categories")
|
||||
@RequiredArgsConstructor
|
||||
public class OzonRestApi {
|
||||
public class CategoryApi {
|
||||
|
||||
private final OzonService ozonService;
|
||||
|
||||
@GetMapping("/categories")
|
||||
public ResponseEntity<OzonCategory[]> getOzon() {
|
||||
return ResponseEntity.ok(ozonService.getCategories());
|
||||
@GetMapping
|
||||
public ResponseEntity<?> getCategories(Marketplace marketplace) {
|
||||
if (Marketplace.OZON.equals(marketplace)) {
|
||||
return ResponseEntity.ok(ozonService.getCategories());
|
||||
}
|
||||
return ResponseEntity.ok(Category.values());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ru.pricepulse.parsingservice.web.rest;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.pricepulse.parsingservice.enumeration.Marketplace;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/marketplaces")
|
||||
@RequiredArgsConstructor
|
||||
public class MarketplaceApi {
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Marketplace[]> getMarketplace() {
|
||||
return ResponseEntity.ok(Marketplace.values());
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.pricepulse.parsingservice.enumeration.Category;
|
||||
import ru.pricepulse.parsingservice.enumeration.Marketplace;
|
||||
import ru.pricepulse.parsingservice.service.ProductService;
|
||||
import ru.pricepulse.parsingservice.service.dto.PriceHistoryDto;
|
||||
import ru.pricepulse.parsingservice.service.dto.ProductDto;
|
||||
@ -21,7 +22,7 @@ import ru.pricepulse.parsingservice.service.dto.ProductsPageDto;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/products")
|
||||
@RequiredArgsConstructor
|
||||
public class MainRestApi {
|
||||
public class ProductApi {
|
||||
|
||||
private final ProductService productService;
|
||||
|
||||
@ -42,9 +43,10 @@ public class MainRestApi {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<ProductsPageDto> getAllProductsByCategoryAndPage(Category category,
|
||||
public ResponseEntity<ProductsPageDto> getAllProductsByCategoryAndPage(Marketplace marketplace,
|
||||
Category category,
|
||||
Pageable pageable) {
|
||||
return ResponseEntity.ok(productService.findAllProductsByPage(category, pageable));
|
||||
return ResponseEntity.ok(productService.findAllProductsByPage(marketplace, category, pageable));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user