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.OptionsException;
27 import info.mikethomas.jfold.options.Options;
28
29 import io.swagger.v3.oas.annotations.Operation;
30 import io.swagger.v3.oas.annotations.media.Content;
31 import io.swagger.v3.oas.annotations.media.Schema;
32 import io.swagger.v3.oas.annotations.responses.ApiResponse;
33 import io.swagger.v3.oas.annotations.tags.Tag;
34
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.MediaType;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.ExceptionHandler;
40 import org.springframework.web.bind.annotation.RequestMapping;
41 import org.springframework.web.bind.annotation.RequestMethod;
42 import org.springframework.web.bind.annotation.ResponseBody;
43 import org.springframework.web.bind.annotation.ResponseStatus;
44 import org.springframework.web.bind.annotation.RestController;
45
46
47
48
49
50
51
52 @RestController("options")
53 @Tag(name = "Options", description = "List or set options with their values.")
54 public class OptionsResource {
55
56 @Autowired
57 private Connection connection;
58
59
60
61
62
63
64
65
66 @Operation(summary = "options", description = "Get Options.", responses = {
67 @ApiResponse(responseCode = "200", description = "OK", content = {
68 @Content(schema = @Schema(implementation = Options.class))
69 })
70 })
71 @RequestMapping(
72 value = "/options",
73 method = RequestMethod.GET,
74 produces = {
75 MediaType.APPLICATION_JSON_VALUE,
76 MediaType.APPLICATION_XML_VALUE,
77 MediaType.TEXT_XML_VALUE
78 })
79 @ResponseBody
80 public ResponseEntity<Options> getSlotOptions() throws OptionsException {
81 return new ResponseEntity<>(connection.options(true, true), HttpStatus.OK);
82 }
83
84
85
86
87
88
89
90 @ExceptionHandler(OptionsException.class)
91 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
92 public ResponseEntity<Exception> handleException(Exception ex) {
93 return new ResponseEntity<>(ex, HttpStatus.INTERNAL_SERVER_ERROR);
94 }
95 }