1 package info.mikethomas.fahservices.service;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import info.mikethomas.jfold.Connection;
26 import info.mikethomas.jfold.exceptions.SlotInfoException;
27 import info.mikethomas.jfold.slot.Slot;
28
29 import io.swagger.v3.oas.annotations.Operation;
30 import io.swagger.v3.oas.annotations.Parameter;
31 import io.swagger.v3.oas.annotations.media.ArraySchema;
32 import io.swagger.v3.oas.annotations.media.Content;
33 import io.swagger.v3.oas.annotations.media.Schema;
34 import io.swagger.v3.oas.annotations.responses.ApiResponse;
35 import io.swagger.v3.oas.annotations.tags.Tag;
36
37 import java.util.List;
38
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.MediaType;
42 import org.springframework.http.ResponseEntity;
43 import org.springframework.web.bind.annotation.ExceptionHandler;
44 import org.springframework.web.bind.annotation.PathVariable;
45 import org.springframework.web.bind.annotation.RequestMapping;
46 import org.springframework.web.bind.annotation.RequestMethod;
47 import org.springframework.web.bind.annotation.ResponseBody;
48 import org.springframework.web.bind.annotation.ResponseStatus;
49 import org.springframework.web.bind.annotation.RestController;
50
51
52
53
54
55
56
57 @RestController("slot-info")
58 @Tag(name = "Slot Info", description = "Get slot information.")
59 public class SlotInfoResource {
60
61 @Autowired
62 private Connection connection;
63
64
65
66
67
68
69
70
71 @Operation(summary = "slot-info", description = "Get List of slot information.", responses = {
72 @ApiResponse(responseCode = "200", description = "OK", content = {
73 @Content(array = @ArraySchema(schema = @Schema(implementation = Slot.class)))
74 })
75 })
76 @RequestMapping(
77 value = "/slot-info",
78 method = RequestMethod.GET,
79 produces = {
80 MediaType.APPLICATION_JSON_VALUE,
81 MediaType.APPLICATION_XML_VALUE,
82 MediaType.TEXT_XML_VALUE
83 })
84 @ResponseBody
85 public ResponseEntity<List<Slot>> getSlotInfo() throws SlotInfoException {
86 return new ResponseEntity<>(getSlotInfoList(), HttpStatus.OK);
87 }
88
89
90
91
92
93
94
95
96
97 @Operation(summary = "slot-info {slot}", description = "Get slot information at specified index.", responses = {
98 @ApiResponse(responseCode = "200", description = "OK", content = {
99 @Content(schema = @Schema(implementation = Slot.class))
100 })
101 })
102 @RequestMapping(
103 value = "/slot-info/{slot}",
104 method = RequestMethod.GET,
105 produces = {
106 MediaType.APPLICATION_JSON_VALUE,
107 MediaType.APPLICATION_XML_VALUE,
108 MediaType.TEXT_XML_VALUE
109 })
110 @ResponseBody
111 public ResponseEntity<Slot> getSlotInfo(
112 @Parameter(description = "slot number", required = true)
113 @PathVariable("slot") final int slot) throws SlotInfoException {
114 return new ResponseEntity<>(getSlotInfoList().get(slot), HttpStatus.OK);
115 }
116
117
118
119
120
121
122
123 @ExceptionHandler(SlotInfoException.class)
124 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
125 public ResponseEntity<Exception> handleException(Exception ex) {
126 return new ResponseEntity<>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
127 }
128
129
130
131
132
133
134
135 private List<Slot> getSlotInfoList() throws SlotInfoException {
136 return connection.slotInfo();
137 }
138 }