Commit 2d930609 authored by Julius Wu's avatar Julius Wu

delete route

parent 302aa8ae
......@@ -54,10 +54,11 @@ public class PromotionsController {
@DeleteMapping("/{promoId}")
public Mono<ResponseEntity<PromotionDto>> deletePromotionById(@PathVariable String promoId){
public Mono<ResponseEntity<Void>> deletePromotionById(@PathVariable("promoId") String promoId){
return promotionService.deletePromotion(promoId)
.map(res -> ResponseEntity.ok().<PromotionDto>build())
.map(res -> ResponseEntity.ok().<Void>build())
.defaultIfEmpty(ResponseEntity.notFound().build());
}
}
......@@ -4,7 +4,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends Exception{
HttpStatus status;
......
......@@ -37,12 +37,12 @@ public class PromotionService {
});
}
public Mono<PromotionDto> deletePromotion(String promoId){
public Mono<Promotion> deletePromotion(String promoId){
return promotionRepository.findByPromotionId(promoId)
.flatMap(promo -> promotionRepository.delete(promo)
.then(Mono.just(promo)))
.map(PromotionDto::generateDtoFromPromotion)
.switchIfEmpty(Mono.error(new ResourceNotFoundException(HttpStatus.NOT_FOUND, "Product Not Found")));
.switchIfEmpty(Mono.error(new ResourceNotFoundException(HttpStatus.NOT_FOUND, "Promo Not Found")));
}
}
......@@ -114,6 +114,12 @@ class PromotionsControllerTest {
}
@Test
void deletePromotion(){
String promoId = "asd123";
webTestClient.delete()
.uri("/api/promos".concat("/{promoId}"),promoId)
.accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.exchange()
.expectStatus().isOk()
.expectBody(Void.class);
}
}
\ 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