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

delete route

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