-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAllergyControllerAdapter.java
More file actions
62 lines (55 loc) · 2.53 KB
/
AllergyControllerAdapter.java
File metadata and controls
62 lines (55 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.cuoco.adapter.in.controller;
import com.cuoco.adapter.in.controller.model.ParametricResponse;
import com.cuoco.application.port.in.GetAllAllergiesQuery;
import com.cuoco.application.usecase.model.Allergy;
import com.cuoco.shared.GlobalExceptionHandler;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/allergies")
public class AllergyControllerAdapter {
private final GetAllAllergiesQuery getAllAllergiesQuery;
public AllergyControllerAdapter(GetAllAllergiesQuery getAllAllergiesQuery) {
this.getAllAllergiesQuery = getAllAllergiesQuery;
}
@GetMapping
@Tag(name = "Parametric Endpoints", description = "Parametric values of immutable resources")
@Operation(summary = "GET all the allergies")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "Return all the existent allergies",
content = @Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = ParametricResponse.class))
)
),
@ApiResponse(
responseCode = "503",
description = "Service unavailable",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = GlobalExceptionHandler.ApiErrorResponse.class)
)
)
})
public ResponseEntity<List<ParametricResponse>> getAll() {
log.info("Executing GET all allergies");
List<Allergy> allergies = getAllAllergiesQuery.execute();
List<ParametricResponse> response = allergies.stream().map(ParametricResponse::fromDomain).toList();
log.info("All allergies are retrieved successfully");
return ResponseEntity.ok(response);
}
}