1 package fr.tiogars.domaintemplate.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.domaintemplate.domains.domaintemplate.entities.DomainTemplate;
10 import fr.tiogars.domaintemplate.domains.domaintemplate.models.UpdateDomainTemplateRequest;
11 import fr.tiogars.domaintemplate.domains.domaintemplate.services.DomainTemplateService;
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 DomainTemplateService service;
29
30
31
32
33
34
35 public DomainTemplateUpdateController(DomainTemplateService service) {
36 this.service = service;
37 }
38
39
40
41
42
43
44
45
46
47 @Operation(
48 summary = "Replace a record version",
49 description = "Replaces the payload of an existing version identified by the domain and record key.")
50 @ApiResponses(value = {
51 @ApiResponse(responseCode = "200", description = "The record version was updated."),
52 @ApiResponse(responseCode = "400", description = "The record version or payload is invalid."),
53 @ApiResponse(
54 responseCode = "404",
55 description = "No record exists for the supplied domain, key, and version.")
56 })
57 @PutMapping("/api/v1/domaintemplate/{id}")
58 public ResponseEntity<DomainTemplate> updateDomainTemplate(
59 @Parameter(
60 description = "Persistent template identifier.",
61 required = true,
62 example = "42")
63 @PathVariable
64 Long id,
65 @io.swagger.v3.oas.annotations.parameters.RequestBody(
66 description = "Replacement label and description.",
67 required = true)
68 @Valid
69 @RequestBody
70 UpdateDomainTemplateRequest request) {
71 return service.update(id, request)
72 .map(ResponseEntity::ok)
73 .orElseGet(() -> ResponseEntity.notFound().build());
74 }
75 }