DomainTemplateReadController.java

package fr.tiogars.domaintemplate.domains.domaintemplate.controllers;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import fr.tiogars.domaintemplate.domains.domaintemplate.entities.DomainTemplate;
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 lookup of one DomainTemplate by identifier. */
@Tag(name = "DomainTemplates", description = "CRUD operations for the DomainTemplate business object.")
@RestController
public class DomainTemplateReadController {

    private final DomainTemplateService service;

    public DomainTemplateReadController(DomainTemplateService service) {
        this.service = service;
    }

    @Operation(summary = "Get a DomainTemplate")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "The template was returned."),
            @ApiResponse(responseCode = "404", description = "No template exists for the supplied identifier.")
    })
    @GetMapping("/api/v1/domaintemplate/{id}")
    public ResponseEntity<DomainTemplate> readDomainTemplate(
            @Parameter(description = "Persistent template identifier.", required = true, example = "42")
            @PathVariable Long id) {
        return service.findById(id)
                .map(ResponseEntity::ok)
                .orElseGet(() -> ResponseEntity.notFound().build());
    }
}