Commit 08e090cd authored by Sumaiyya Burney's avatar Sumaiyya Burney

Merge branch 'AFP-63' into 'dev'

Afp 63

See merge request !10
parents 4b7f1cf5 48d05f8a
......@@ -57,8 +57,11 @@ public class PromotionsController {
@DeleteMapping("/{promoId}")
public Mono<ResponseEntity<PromotionDto>> deletePromotionById(@PathVariable String promoId){
//TODO: delete promotion
return null;
public Mono<ResponseEntity<Void>> deletePromotionById(@PathVariable("promoId") String promoId){
return promotionService.deletePromotion(promoId)
.map(res -> ResponseEntity.ok().<Void>build())
.defaultIfEmpty(ResponseEntity.notFound().build());
}
}
package com.nisum.ascend.promotions.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends Exception{
HttpStatus status;
public ResourceNotFoundException(HttpStatus status, String message) {
super(message);
this.status = status;
}
}
package com.nisum.ascend.promotions.service;
import com.nisum.ascend.promotions.dto.PromotionDto;
import com.nisum.ascend.promotions.exception.ResourceNotFoundException;
import com.nisum.ascend.promotions.model.Promotion;
import com.nisum.ascend.promotions.repository.PromotionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import java.util.List;
......@@ -45,4 +47,12 @@ public class PromotionService {
});
}
public Mono<Promotion> deletePromotion(String promoId){
return promotionRepository.findByPromotionId(promoId)
.flatMap(promo -> promotionRepository.delete(promo)
.then(Mono.just(promo)))
.switchIfEmpty(Mono.error(new ResourceNotFoundException(HttpStatus.NOT_FOUND, "Promo Not Found")));
}
}
......@@ -128,6 +128,35 @@ class PromotionsControllerTest {
.jsonPath("$.minimumQuantity").isEqualTo(1);
}
@Test
void deletePromotion(){
Promotion promo = new Promotion("deleteTest", "AFP-1", 0.33f, 3);
webTestClient.get()
.uri("/api/promos".concat("/{promoId}"), promo.getPromotionId())
.exchange()
.expectStatus().isNotFound();
webTestClient.post()
.uri("/api/promos")
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.body(Mono.just(promo),Promotion.class)
.exchange()
.expectStatus().isOk()
.expectBody(Promotion.class);
webTestClient.delete()
.uri("/api/promos".concat("/{promoId}"),promo.getPromotionId())
.accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.exchange()
.expectStatus().isOk()
.expectBody(Void.class);
webTestClient.get()
.uri("/api/promos".concat("/{promoId}"), promo.getPromotionId())
.exchange()
.expectStatus().isNotFound();
}
@Test
public void bulkSearchTest(){
......
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