1 package fr.tiogars.inception.domains.domaintemplate.controllers;
2
3 import org.springframework.http.ResponseEntity;
4 import org.springframework.web.bind.annotation.PathVariable;
5 import org.springframework.web.bind.annotation.PutMapping;
6 import org.springframework.web.bind.annotation.RequestBody;
7 import org.springframework.web.bind.annotation.RestController;
8
9 import fr.tiogars.inception.domains.domaintemplate.models.DomainTemplate;
10 import fr.tiogars.inception.domains.domaintemplate.models.UpdateDomainTemplateRequest;
11 import fr.tiogars.inception.domains.domaintemplate.services.DomainTemplateUpdateService;
12 import io.swagger.v3.oas.annotations.Operation;
13 import io.swagger.v3.oas.annotations.Parameter;
14 import io.swagger.v3.oas.annotations.responses.ApiResponse;
15 import io.swagger.v3.oas.annotations.responses.ApiResponses;
16 import io.swagger.v3.oas.annotations.tags.Tag;
17 import jakarta.validation.Valid;
18
19
20
21
22
23
24 @Tag(name = "DomainTemplates", description = "CRUD operations for the DomainTemplate business object.")
25 @RestController
26 public class DomainTemplateUpdateController {
27
28 private final DomainTemplateUpdateService service;
29
30
31
32
33
34
35 public DomainTemplateUpdateController(DomainTemplateUpdateService service) {
36 this.service = service;
37 }
38
39
40
41
42
43
44
45
46
47 @Operation(summary = "Replace a record version", description = "Replaces the payload of an existing version identified by the domain and record key.")
48 @ApiResponses(value = {
49 @ApiResponse(responseCode = "200", description = "The record version was updated."),
50 @ApiResponse(responseCode = "400", description = "The record version or payload is invalid."),
51 @ApiResponse(responseCode = "404", description = "No record exists for the supplied domain, key, and version.")
52 })
53 @PutMapping("/api/v1/domaintemplate/{id}")
54 public ResponseEntity<DomainTemplate> updateDomainTemplate(
55 @Parameter(description = "Persistent template identifier.", required = true, example = "42") @PathVariable Long id,
56 @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Replacement label and description.", required = true) @Valid @RequestBody UpdateDomainTemplateRequest request) {
57 return service.update(id, request)
58 .map(ResponseEntity::ok)
59 .orElseGet(() -> ResponseEntity.notFound().build());
60 }
61 }