Commit b02db479 authored by John Lam's avatar John Lam

Merge branch 'AFP-64' into 'dev'

Gets all promotions + tested

See merge request !1
parents 929f95a1 cf3f015f
......@@ -20,9 +20,11 @@ public class PromotionsController {
PromotionService promotionService;
@GetMapping()
public Flux<ResponseEntity<PromotionDto>> getAllPromotions(@RequestParam(required = false) String itemSku){
//TODO: get all promos OR promos by item SKU
return null;
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}")
......
......@@ -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);
}
package com.nisum.ascend.promotions.service;
import com.nisum.ascend.promotions.dto.PromotionDto;
import com.nisum.ascend.promotions.repository.PromotionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
@Service
public class PromotionService {
@Autowired
PromotionRepository promotionRepository;
public Flux<PromotionDto> findAll(){
return promotionRepository.findAll().map(PromotionDto::generateDtoFromPromotion);
}
public Flux<PromotionDto> findPromotionsByProductSku(String sku){
return promotionRepository.findByProductSku(sku).map(PromotionDto::generateDtoFromPromotion);
}
}
spring.config.import=classpath:secret.properties
spring.data.mongodb.uri=mongodb+srv://admin:${db.password}@inventory-promotions.d4nfz.mongodb\
.net/${spring.data.mongodb.database}?retryWrites=true&w=majority
spring.data.mongodb.database=test
\ No newline at end of file
package com.nisum.ascend.promotions.controller;
import com.nisum.ascend.promotions.dto.PromotionDto;
import com.nisum.ascend.promotions.model.Promotion;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext
@AutoConfigureWebTestClient
@ActiveProfiles("test")
@Slf4j
class PromotionsControllerTest {
@Autowired
private WebTestClient webTestClient;
@BeforeEach
void setUp() {
}
@Test
void getAllPromotions() {
webTestClient.get().uri("http://localhost:8081/api/promos").exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON_VALUE)
.expectBodyList(PromotionDto.class)
.hasSize(2)
.consumeWith(promo ->{
List<PromotionDto> promos = promo.getResponseBody();
assert promos != null;
promos.forEach(p ->{
assertNotNull(p.getPromotionId());
assertNotNull(p.getProductSku());
System.out.println(p.getPromotionId());
});
});
}
}
\ No newline at end of file
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