Skip to content

Commit df9f045

Browse files
committed
Extract contrroller-level functions into interfaces
- Extract endpoint functions into interfaces - Move endpoint (swagger) documentation into interfaces - Remove unused imports from controller classes
1 parent 781053f commit df9f045

22 files changed

+1200
-884
lines changed
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
package org.phoebus.channelfinder.rest.api;
2+
3+
import static org.phoebus.channelfinder.common.CFResourceDescriptors.CHANNEL_RESOURCE_URI;
4+
import static org.phoebus.channelfinder.common.CFResourceDescriptors.SEARCH_PARAM_DESCRIPTION;
5+
6+
import io.swagger.v3.oas.annotations.Operation;
7+
import io.swagger.v3.oas.annotations.Parameter;
8+
import io.swagger.v3.oas.annotations.media.ArraySchema;
9+
import io.swagger.v3.oas.annotations.media.Content;
10+
import io.swagger.v3.oas.annotations.media.Schema;
11+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
12+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
13+
import java.util.List;
14+
import org.phoebus.channelfinder.entity.Channel;
15+
import org.phoebus.channelfinder.entity.SearchResult;
16+
import org.springframework.util.MultiValueMap;
17+
import org.springframework.web.bind.annotation.DeleteMapping;
18+
import org.springframework.web.bind.annotation.GetMapping;
19+
import org.springframework.web.bind.annotation.PathVariable;
20+
import org.springframework.web.bind.annotation.PostMapping;
21+
import org.springframework.web.bind.annotation.PutMapping;
22+
import org.springframework.web.bind.annotation.RequestBody;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.RequestParam;
25+
import org.springframework.web.server.ResponseStatusException;
26+
27+
@RequestMapping(CHANNEL_RESOURCE_URI)
28+
public interface IChannelManager {
29+
30+
@Operation(
31+
summary = "Query channels",
32+
description =
33+
"Query a collection of Channel instances based on tags, property values, and channel names.",
34+
operationId = "queryChannels",
35+
tags = {"Channel"})
36+
@ApiResponses(
37+
value = {
38+
@ApiResponse(
39+
responseCode = "200",
40+
description = "List of channels",
41+
content =
42+
@Content(array = @ArraySchema(schema = @Schema(implementation = Channel.class)))),
43+
@ApiResponse(
44+
responseCode = "400",
45+
description = "Invalid request",
46+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
47+
@ApiResponse(
48+
responseCode = "500",
49+
description = "Error while trying to find all channels",
50+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
51+
})
52+
@GetMapping
53+
List<Channel> query(
54+
@Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam
55+
MultiValueMap<String, String> allRequestParams);
56+
57+
@Operation(
58+
summary = "Combined query for channels",
59+
description =
60+
"Query for a collection of Channel instances and get a count and the first 10k hits.",
61+
operationId = "combinedQueryChannels",
62+
tags = {"Channel"})
63+
@ApiResponses(
64+
value = {
65+
@ApiResponse(
66+
responseCode = "200",
67+
description = "The number of matches for the query, and the first 10k channels",
68+
content =
69+
@Content(
70+
array = @ArraySchema(schema = @Schema(implementation = SearchResult.class)))),
71+
@ApiResponse(
72+
responseCode = "400",
73+
description = "Invalid request - response size exceeded",
74+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
75+
@ApiResponse(
76+
responseCode = "500",
77+
description = "Error while trying to find all channels",
78+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
79+
})
80+
@GetMapping("/combined")
81+
SearchResult combinedQuery(
82+
@Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam
83+
MultiValueMap<String, String> allRequestParams);
84+
85+
@Operation(
86+
summary = "Count channels matching query",
87+
description = "Get the number of channels matching the given query parameters.",
88+
operationId = "countChannels",
89+
tags = {"Channel"})
90+
@ApiResponses(
91+
value = {
92+
@ApiResponse(
93+
responseCode = "200",
94+
description = "The number of channels matching the query",
95+
content = @Content(schema = @Schema(implementation = Long.class))),
96+
@ApiResponse(
97+
responseCode = "500",
98+
description = "Error while trying to count the result for channel-query",
99+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
100+
})
101+
@GetMapping("/count")
102+
long queryCount(
103+
@Parameter(description = SEARCH_PARAM_DESCRIPTION) @RequestParam
104+
MultiValueMap<String, String> allRequestParams);
105+
106+
@Operation(
107+
summary = "Get channel by name",
108+
description = "Retrieve a Channel instance by its name.",
109+
operationId = "getChannelByName",
110+
tags = {"Channel"})
111+
@ApiResponses(
112+
value = {
113+
@ApiResponse(
114+
responseCode = "200",
115+
description = "Channel with the specified name",
116+
content = @Content(schema = @Schema(implementation = Channel.class))),
117+
@ApiResponse(
118+
responseCode = "404",
119+
description = "Channel not found",
120+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
121+
})
122+
@GetMapping("/{channelName}")
123+
Channel read(@PathVariable("channelName") String channelName);
124+
125+
@Operation(
126+
summary = "Create or replace a channel",
127+
description = "Create or replace a channel instance identified by the payload.",
128+
operationId = "createOrReplaceChannel",
129+
tags = {"Channel"})
130+
@ApiResponses(
131+
value = {
132+
@ApiResponse(
133+
responseCode = "200",
134+
description = "The created/replaced channel",
135+
content = @Content(schema = @Schema(implementation = Channel.class))),
136+
@ApiResponse(
137+
responseCode = "400",
138+
description = "Invalid request",
139+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
140+
@ApiResponse(
141+
responseCode = "401",
142+
description = "Unauthorized",
143+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
144+
@ApiResponse(
145+
responseCode = "404",
146+
description = "Channel, Tag, or property not found",
147+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
148+
@ApiResponse(
149+
responseCode = "500",
150+
description = "Error while trying to create channel",
151+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
152+
})
153+
@PutMapping("/{channelName}")
154+
Channel create(@PathVariable("channelName") String channelName, @RequestBody Channel channel);
155+
156+
@Operation(
157+
summary = "Create or replace multiple channels",
158+
description = "Create or replace multiple channel instances.",
159+
operationId = "createOrReplaceChannels",
160+
tags = {"Channel"})
161+
@ApiResponses(
162+
value = {
163+
@ApiResponse(
164+
responseCode = "200",
165+
description = "The created/replaced channels",
166+
content =
167+
@Content(array = @ArraySchema(schema = @Schema(implementation = Channel.class)))),
168+
@ApiResponse(
169+
responseCode = "400",
170+
description = "Invalid request",
171+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
172+
@ApiResponse(
173+
responseCode = "401",
174+
description = "Unauthorized",
175+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
176+
@ApiResponse(
177+
responseCode = "404",
178+
description = "Tag, or property not found",
179+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
180+
@ApiResponse(
181+
responseCode = "500",
182+
description = "Error while trying to create channels",
183+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
184+
})
185+
@PutMapping
186+
Iterable<Channel> create(@RequestBody Iterable<Channel> channels);
187+
188+
@Operation(
189+
summary = "Update a channel",
190+
description =
191+
"Merge properties and tags of the channel identified by the payload into an existing channel.",
192+
operationId = "updateChannel",
193+
tags = {"Channel"})
194+
@ApiResponses(
195+
value = {
196+
@ApiResponse(
197+
responseCode = "200",
198+
description = "The updated channel",
199+
content = @Content(schema = @Schema(implementation = Channel.class))),
200+
@ApiResponse(
201+
responseCode = "400",
202+
description = "Invalid request",
203+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
204+
@ApiResponse(
205+
responseCode = "401",
206+
description = "Unauthorized",
207+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
208+
@ApiResponse(
209+
responseCode = "404",
210+
description = "Channel, Tag, or property not found",
211+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
212+
@ApiResponse(
213+
responseCode = "500",
214+
description = "Error while trying to update channel",
215+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
216+
})
217+
@PostMapping("/{channelName}")
218+
Channel update(@PathVariable("channelName") String channelName, @RequestBody Channel channel);
219+
220+
@Operation(
221+
summary = "Update multiple channels",
222+
description =
223+
"Merge properties and tags of the channels identified by the payload into existing channels.",
224+
operationId = "updateChannels",
225+
tags = {"Channel"})
226+
@ApiResponses(
227+
value = {
228+
@ApiResponse(
229+
responseCode = "200",
230+
description = "The updated channels",
231+
content = @Content(schema = @Schema(implementation = Channel.class))),
232+
@ApiResponse(
233+
responseCode = "400",
234+
description = "Invalid request",
235+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
236+
@ApiResponse(
237+
responseCode = "401",
238+
description = "Unauthorized",
239+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
240+
@ApiResponse(
241+
responseCode = "404",
242+
description = "Channel not found",
243+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
244+
@ApiResponse(
245+
responseCode = "500",
246+
description = "Error while trying to update channels",
247+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
248+
})
249+
@PostMapping()
250+
Iterable<Channel> update(@RequestBody Iterable<Channel> channels);
251+
252+
@Operation(
253+
summary = "Delete a channel",
254+
description = "Delete a channel instance identified by its name.",
255+
operationId = "deleteChannel",
256+
tags = {"Channel"})
257+
@ApiResponses(
258+
value = {
259+
@ApiResponse(responseCode = "200", description = "Channel deleted"),
260+
@ApiResponse(
261+
responseCode = "401",
262+
description = "Unauthorized",
263+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
264+
@ApiResponse(
265+
responseCode = "404",
266+
description = "Channel not found",
267+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class))),
268+
@ApiResponse(
269+
responseCode = "500",
270+
description = "Error while trying to delete channel",
271+
content = @Content(schema = @Schema(implementation = ResponseStatusException.class)))
272+
})
273+
@DeleteMapping("/{channelName}")
274+
void remove(@PathVariable("channelName") String channelName);
275+
276+
/**
277+
* Checks if 1. the channel name is not null and matches the name in the body 2. the channel owner
278+
* is not null or empty 3. all the listed tags/props exist and prop value is not null or empty
279+
*
280+
* @param channel channel to be validated
281+
*/
282+
void validateChannelRequest(Channel channel);
283+
284+
/**
285+
* Checks if 1. the tag names are not null 2. the tag owners are not null or empty 3. all the
286+
* channels exist
287+
*
288+
* @param channels list of channels to be validated
289+
*/
290+
void validateChannelRequest(Iterable<Channel> channels);
291+
}

0 commit comments

Comments
 (0)