-
Notifications
You must be signed in to change notification settings - Fork 4
/
ServiceApplication.java
47 lines (39 loc) · 1.46 KB
/
ServiceApplication.java
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
package server;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.Set;
@Slf4j
@SpringBootApplication
public class ServiceApplication {
public static void main(String[] args) {
log.info("starting server");
SpringApplication.run(ServiceApplication.class, args);
}
}
@RestController
class AvailabilityController {
private boolean validate(String console) {
return StringUtils.hasText(console) &&
Set.of("ps5", "ps4", "switch", "xbox").contains(console);
}
@GetMapping("/availability/{console}")
Map<String, Object> getAvailability(@PathVariable String console) {
return Map.of("console", console,
"available", checkAvailability(console));
}
private boolean checkAvailability(String console) {
Assert.state(validate(console), () -> "the console specified, " + console + ", is not valid.");
return switch (console) {
case "ps5" -> throw new RuntimeException("Service exception");
case "xbox" -> true;
default -> false;
};
}
}