DomainTemplateDeleteController.java
package fr.tiogars.inception.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.inception.domains.domaintemplate.services.DomainTemplateDeleteService;
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 archives a domain record.
*
* @since 0.1.0
*/
@Tag(name = "DomainTemplates", description = "CRUD operations for the DomainTemplate business object.")
@RestController
public class DomainTemplateDeleteController {
private final DomainTemplateDeleteService service;
/**
* Creates the delete endpoint.
*
* @param service domain record deletion service
*/
public DomainTemplateDeleteController(DomainTemplateDeleteService service) {
this.service = service;
}
/**
* Archives an active record, preserving its database row and business code.
*
* @param id persistent template identifier
* @return a no-content response when a record was archived, or a not-found response otherwise
*/
@Operation(
summary = "Soft-delete a DomainTemplate",
description = "Archives the row and allows its code to be reused with a new identifier."
)
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "The record was archived."),
@ApiResponse(responseCode = "404", description = "No active record exists for the supplied identifier.")
})
@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();
}
}