DomainTemplateDeleteController.java
package fr.tiogars.domaintemplate.domains.domaintemplate.controllers;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import fr.tiogars.domaintemplate.domains.domaintemplate.services.DomainTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
* Exposes the endpoint that deletes every version of a domain record.
*
* @since 0.1.0
*/
@Tag(name = "DomainTemplates", description = "CRUD operations for the DomainTemplate business object.")
@RestController
public class DomainTemplateDeleteController {
private final DomainTemplateService service;
/**
* Creates the delete endpoint.
*
* @param service domain record service
*/
public DomainTemplateDeleteController(DomainTemplateService service) {
this.service = service;
}
/**
* Deletes every version of a record.
*
* @param id persistent template identifier
* @return a no-content response when a record was deleted, or a not-found response otherwise
*/
@Operation(
summary = "Delete all versions of a record",
description = "Deletes every stored version identified by the domain and record key."
)
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "All versions of the record were deleted."),
@ApiResponse(responseCode = "404", description = "No record exists for the supplied domain and key.")
})
@DeleteMapping("/api/v1/domaintemplate/{id}")
public ResponseEntity<Void> deleteDomainTemplate(
@Parameter(description = "Persistent template identifier.", required = true, example = "42")
@PathVariable Long id) {
return service.delete(id)
? ResponseEntity.noContent().build()
: ResponseEntity.notFound().build();
}
}