Commit 680db9db authored by Sumaiyya Burney's avatar Sumaiyya Burney

Adds query param to find promo by prod SKU

parent a363227b
......@@ -20,9 +20,11 @@ public class PromotionsController {
PromotionService promotionService;
@GetMapping()
public ResponseEntity<Flux<PromotionDto>> getAllPromotions(@RequestParam(required = false) String itemSku){
//TODO: test once we have real data
return ResponseEntity.ok(promotionService.findAll());
public ResponseEntity<Flux<PromotionDto>> getAllPromotions(@RequestParam(required = false) String sku){
if (sku != null){
return ResponseEntity.ok(promotionService.findPromotionsByProductSku(sku));
}
else return ResponseEntity.ok(promotionService.findAll());
}
@GetMapping("/{id}")
......
......@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@Document
@Document(collection="promotions")
public class Promotion {
@Id
private String id;
......
......@@ -4,7 +4,9 @@ package com.nisum.ascend.promotions.repository;
import com.nisum.ascend.promotions.model.Promotion;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
@Repository
public interface PromotionRepository extends ReactiveMongoRepository<Promotion, String> {
Flux<Promotion> findByProductSku(String sku);
}
......@@ -15,4 +15,8 @@ public class PromotionService {
public Flux<PromotionDto> findAll(){
return promotionRepository.findAll().map(PromotionDto::generateDtoFromPromotion);
}
public Flux<PromotionDto> findPromotionsByProductSku(String sku){
return promotionRepository.findByProductSku(sku).map(PromotionDto::generateDtoFromPromotion);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment