11package com .programmersdiary ;
22
3+ import io .swagger .v3 .oas .annotations .Operation ;
4+ import io .swagger .v3 .oas .annotations .media .Content ;
5+ import io .swagger .v3 .oas .annotations .media .ExampleObject ;
6+ import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
7+ import io .swagger .v3 .oas .annotations .tags .Tag ;
38import org .springframework .web .bind .annotation .GetMapping ;
49import org .springframework .web .bind .annotation .PostMapping ;
510import org .springframework .web .bind .annotation .RequestBody ;
813import java .util .Map ;
914
1015@ RestController
16+ @ Tag (name = "Azul Game" , description = "An API for Azul board game" )
1117public class GameController {
1218 private final Game game ;
1319
@@ -16,16 +22,34 @@ public GameController(Game game) {
1622 }
1723
1824 @ GetMapping ("/show" )
25+ @ Operation (summary = "Get game state as a plain-text" , description = "Returns the current game state as a plain-text" )
26+ @ ApiResponse (responseCode = "200" , description = "Current game state" )
1927 public String show () {
2028 return game .toString ();
2129 }
2230
2331 @ GetMapping ("/showJson" )
32+ @ Operation (summary = "Get game state as JSON" , description = "Returns the current game state as a JSON object" )
33+ @ ApiResponse (responseCode = "200" , description = "Current game state in JSON format" )
2434 public Map <String , Object > showJson () {
2535 return game .jsonObject ();
2636 }
2737
2838 @ PostMapping ("/takeFromFactory" )
39+ @ Operation (summary = "Take tiles from factory" ,
40+ description = "Take tiles of a specific color from a factory display, drop some on the floor (if you want) and put them on a pattern line" )
41+ @ ApiResponse (responseCode = "200" , description = "Updated game state after taking tiles" )
42+ @ io .swagger .v3 .oas .annotations .parameters .RequestBody (
43+ content = @ Content (
44+ examples = {
45+ @ ExampleObject (
46+ name = "Take RED tiles" ,
47+ description = "The example is not guaranteed to work due to randomness of game. Please check the board state first!" ,
48+ value = "{\" factoryIndex\" : 0, \" tileToTake\" : \" RED\" , \" tilesToPutOnFloor\" : 0, \" patternLineIndex\" : 1}"
49+ )
50+ }
51+ )
52+ )
2953 public Map <String , Object > takeTilesFromFactory (@ RequestBody FactoryTakingRequest factoryTakingRequest ) {
3054 game .executeFactoryOfferPhaseWithFactory (
3155 factoryTakingRequest .factoryIndex (), factoryTakingRequest .tileToTake (),
@@ -35,6 +59,20 @@ public Map<String, Object> takeTilesFromFactory(@RequestBody FactoryTakingReques
3559 }
3660
3761 @ PostMapping ("/takeFromCenter" )
62+ @ Operation (summary = "Take tiles from center" ,
63+ description = "Take tiles of a specific color from the center area, drop some on the floor (if you want) and put them on a pattern line" )
64+ @ ApiResponse (responseCode = "200" , description = "Updated game state after taking tiles" )
65+ @ io .swagger .v3 .oas .annotations .parameters .RequestBody (
66+ content = @ Content (
67+ examples = {
68+ @ ExampleObject (
69+ name = "Take BLUE tiles" ,
70+ description = "The example is not guaranteed to work due to randomness of game. Please check the board state first!" ,
71+ value = "{\" tileToTake\" : \" BLUE\" , \" tilesToPutOnFloor\" : 1, \" patternLineIndex\" : 2}"
72+ )
73+ }
74+ )
75+ )
3876 public Map <String , Object > takeTilesFromCenter (@ RequestBody CenterTakingRequest centerTakingRequest ) {
3977 game .executeFactoryOfferPhaseWithCenter (
4078 centerTakingRequest .tileToTake (), centerTakingRequest .tilesToPutOnFloor (),
0 commit comments