Skip to content

Commit 62f7456

Browse files
committed
simple controller for quick testing
1 parent 8213868 commit 62f7456

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.kulkeez.controller;
2+
3+
import java.util.Map;
4+
import java.util.Set;
5+
6+
import org.springframework.util.Assert;
7+
import org.springframework.util.StringUtils;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
import lombok.extern.slf4j.Slf4j;
13+
14+
@RestController
15+
@Slf4j
16+
/**
17+
* Check for Availability for Gaming consoles (switch, xbox, ps4)
18+
*
19+
* http://localhost:8080/availability/switch
20+
* http://localhost:8080/availability/ps4
21+
* http://localhost:8080/availability/xbox
22+
*
23+
* @author kulkarvi
24+
*
25+
*/
26+
public class AvailabilityController {
27+
28+
29+
@GetMapping("/availability/{console}")
30+
public Map<String, Object> getAvailability(@PathVariable String console) {
31+
log.info("/availability REST endpoint invoked...");
32+
return Map.of("console", console,
33+
"available", checkAvailability(console));
34+
}
35+
36+
37+
/**
38+
* Check Availability of a Gaming console
39+
*
40+
* @param console
41+
* @return
42+
*/
43+
private boolean checkAvailability(String console) {
44+
Assert.state(validate(console), () -> "the console specified, " + console + ", is not valid.");
45+
return switch (console) {
46+
case "ps5" -> throw new RuntimeException("Service exception");
47+
case "xbox" -> true;
48+
default -> false;
49+
};
50+
}
51+
52+
private boolean validate(String console) {
53+
return StringUtils.hasText(console) &&
54+
Set.of("ps5", "ps4", "switch", "xbox").contains(console);
55+
}
56+
}

0 commit comments

Comments
 (0)