-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcommands.txt
117 lines (80 loc) · 2.65 KB
/
commands.txt
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.example.demo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ScoreRepository extends CrudRepository<Score, Long> {
}
@Component
public class Score {
@Id
Long id;
int wins, losses, ties;
public Score() {
super();
}
package com.example.demo;
import java.util.Scanner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ConsoleAppApplication implements CommandLineRunner {
//@Autowired
//Score score;
@Autowired
ScoreRepository scoreRepo;
public static void main(String[] args) {
SpringApplication.run(ConsoleAppApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
Scanner scanner = new Scanner(System.in);
Score score = scoreRepo.findById(Long.valueOf(1)).get();
String result = "";
String gesture = "";
do {
gesture = scanner.next();
if (gesture.equalsIgnoreCase("rock")) {
score.wins++;
result = "tie";
}
if (gesture.equalsIgnoreCase("paper")) {
score.ties++;
result = "win";
}
if (gesture.equalsIgnoreCase("scissors")) {
score.losses++;
result = "loss";
}
System.out.println("You chose rock. The result is a: " + result);
System.out.println("The score is: " + score);
} while (!gesture.equalsIgnoreCase("q"));
scanner.close();
}
}
@Operation(summary = "Non-idempotent update the score by a single unit.")
@Parameter(description = "New value for the number of wins.")
@ApiResponse(responseCode = "200", description = "Wins updated, score returned.",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Score.class)) })
@OpenAPIDefinition(info = @Info(title = "Score API - Definition", version = "1.2", description = "Operations to Help Settle Scores"))
@Id
@NotNull(message = "Id cannot be null")
private Integer id;
@NotBlank
@PositiveOrZero
@Size(min = 0, max = 20)
int wins, losses, ties;
@GetMapping("/search")
public Page<Score> searchForScores(@ParameterObject Pageable pageable) {
return null;
}
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
public ResponseEntity<String> handleTeapotError(RuntimeException exception) {
return new ResponseEntity<>(exception.getMessage(), HttpStatus.I_AM_A_TEAPOT);
}
}