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 { ...@@ -20,9 +20,11 @@ public class PromotionsController {
PromotionService promotionService; PromotionService promotionService;
@GetMapping() @GetMapping()
public ResponseEntity<Flux<PromotionDto>> getAllPromotions(@RequestParam(required = false) String itemSku){ public ResponseEntity<Flux<PromotionDto>> getAllPromotions(@RequestParam(required = false) String sku){
//TODO: test once we have real data if (sku != null){
return ResponseEntity.ok(promotionService.findAll()); return ResponseEntity.ok(promotionService.findPromotionsByProductSku(sku));
}
else return ResponseEntity.ok(promotionService.findAll());
} }
@GetMapping("/{id}") @GetMapping("/{id}")
......
...@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document; ...@@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
@Getter @Getter
@Setter @Setter
@Document @Document(collection="promotions")
public class Promotion { public class Promotion {
@Id @Id
private String id; private String id;
......
...@@ -4,7 +4,9 @@ package com.nisum.ascend.promotions.repository; ...@@ -4,7 +4,9 @@ package com.nisum.ascend.promotions.repository;
import com.nisum.ascend.promotions.model.Promotion; import com.nisum.ascend.promotions.model.Promotion;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository; import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
@Repository @Repository
public interface PromotionRepository extends ReactiveMongoRepository<Promotion, String> { public interface PromotionRepository extends ReactiveMongoRepository<Promotion, String> {
Flux<Promotion> findByProductSku(String sku);
} }
...@@ -15,4 +15,8 @@ public class PromotionService { ...@@ -15,4 +15,8 @@ public class PromotionService {
public Flux<PromotionDto> findAll(){ public Flux<PromotionDto> findAll(){
return promotionRepository.findAll().map(PromotionDto::generateDtoFromPromotion); 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