View Javadoc
1   package fr.tiogars.chat.domains.task.controllers;
2   
3   import java.util.List;
4   
5   import org.springframework.http.HttpStatus;
6   import org.springframework.web.bind.annotation.PostMapping;
7   import org.springframework.web.bind.annotation.RequestBody;
8   import org.springframework.web.bind.annotation.ResponseStatus;
9   import org.springframework.web.bind.annotation.RestController;
10  
11  import fr.tiogars.chat.domains.task.models.CreateTaskRequest;
12  import fr.tiogars.chat.domains.task.models.Task;
13  import fr.tiogars.chat.domains.task.services.TaskSeedService;
14  import io.swagger.v3.oas.annotations.Operation;
15  import io.swagger.v3.oas.annotations.responses.ApiResponse;
16  import io.swagger.v3.oas.annotations.responses.ApiResponses;
17  import io.swagger.v3.oas.annotations.tags.Tag;
18  import jakarta.validation.Valid;
19  
20  /**
21   * Exposes the endpoint that seeds a collection of domain records.
22   *
23   * @since 0.1.0
24   */
25  @Tag(name = "Tasks", description = "CRUD operations for the Task business object.")
26  @RestController
27  public class TaskSeedController {
28  
29          private final TaskSeedService service;
30  
31          /**
32           * Creates the seed endpoint.
33           *
34           * @param service domain record seed service
35           */
36          public TaskSeedController(TaskSeedService service) {
37                  this.service = service;
38          }
39  
40          /**
41           * Creates or replaces the supplied records.
42           *
43           * @param records validated records to seed
44           * @return stored records in input order
45           */
46          @Operation(summary = "Seed domain records", description = "Creates or replaces every supplied record version in a single request.")
47          @ApiResponses(value = {
48                          @ApiResponse(responseCode = "201", description = "The supplied records were stored."),
49                          @ApiResponse(responseCode = "400", description = "One or more supplied records are invalid.")
50          })
51          @PostMapping("/api/v1/task/seed")
52          @ResponseStatus(HttpStatus.CREATED)
53          public List<Task> seedTask(
54                          @io.swagger.v3.oas.annotations.parameters.RequestBody(
55                                  description = "Tasks to create or replace by immutable code.", required = true)
56                          @RequestBody List<@Valid CreateTaskRequest> records) {
57                  return service.seed(records);
58          }
59  }