DomainTemplateSeedController.java
package fr.tiogars.domaintemplate.domains.domaintemplate.controllers;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import fr.tiogars.domaintemplate.domains.domaintemplate.entities.DomainTemplate;
import fr.tiogars.domaintemplate.domains.domaintemplate.models.CreateDomainTemplateRequest;
import fr.tiogars.domaintemplate.domains.domaintemplate.services.DomainTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
/**
* Exposes the endpoint that seeds a collection of domain records.
*
* @since 0.1.0
*/
@Tag(name = "DomainTemplates", description = "CRUD operations for the DomainTemplate business object.")
@RestController
public class DomainTemplateSeedController {
private final DomainTemplateService service;
/**
* Creates the seed endpoint.
*
* @param service domain record service
*/
public DomainTemplateSeedController(DomainTemplateService service) {
this.service = service;
}
/**
* Creates or replaces the supplied records.
*
* @param records validated records to seed
* @return stored records in input order
*/
@Operation(
summary = "Seed domain records",
description = "Creates or replaces every supplied record version in a single request.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "The supplied records were stored."),
@ApiResponse(responseCode = "400", description = "One or more supplied records are invalid.")
})
@PostMapping("/api/v1/domaintemplate/seed")
@ResponseStatus(HttpStatus.CREATED)
public List<DomainTemplate> seedDomainTemplate(
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "Validated domain record versions to create or replace.",
required = true)
@RequestBody
List<@Valid CreateDomainTemplateRequest> records) {
return service.seed(records);
}
}