View Javadoc
1   package fr.tiogars.inception.domains.domaintemplate.controllers;
2   
3   import org.springframework.http.ResponseEntity;
4   import org.springframework.web.bind.annotation.DeleteMapping;
5   import org.springframework.web.bind.annotation.PathVariable;
6   import org.springframework.web.bind.annotation.RestController;
7   
8   import fr.tiogars.inception.domains.domaintemplate.services.DomainTemplateDeleteService;
9   import io.swagger.v3.oas.annotations.Operation;
10  import io.swagger.v3.oas.annotations.Parameter;
11  import io.swagger.v3.oas.annotations.responses.ApiResponse;
12  import io.swagger.v3.oas.annotations.responses.ApiResponses;
13  import io.swagger.v3.oas.annotations.tags.Tag;
14  
15  /**
16   * Exposes the endpoint that archives a domain record.
17   *
18   * @since 0.1.0
19   */
20  @Tag(name = "DomainTemplates", description = "CRUD operations for the DomainTemplate business object.")
21  @RestController
22  public class DomainTemplateDeleteController {
23  
24      private final DomainTemplateDeleteService service;
25  
26      /**
27       * Creates the delete endpoint.
28       *
29       * @param service domain record deletion service
30       */
31      public DomainTemplateDeleteController(DomainTemplateDeleteService service) {
32          this.service = service;
33      }
34  
35      /**
36       * Archives an active record, preserving its database row and business code.
37       *
38       * @param id persistent template identifier
39       * @return a no-content response when a record was archived, or a not-found response otherwise
40       */
41          @Operation(
42              summary = "Soft-delete a DomainTemplate",
43              description = "Archives the row and allows its code to be reused with a new identifier."
44          )
45          @ApiResponses(value = {
46              @ApiResponse(responseCode = "204", description = "The record was archived."),
47              @ApiResponse(responseCode = "404", description = "No active record exists for the supplied identifier.")
48          })
49          @DeleteMapping("/api/v1/domaintemplate/{id}")
50          public ResponseEntity<Void> deleteDomainTemplate(
51              @Parameter(description = "Persistent template identifier.", required = true, example = "42")
52              @PathVariable Long id) {
53          return service.delete(id)
54                  ? ResponseEntity.noContent().build()
55                  : ResponseEntity.notFound().build();
56      }
57  }