77import io .micronaut .http .annotation .Get ;
88import io .micronaut .http .annotation .Post ;
99import io .micronaut .validation .Validated ;
10+ import io .swagger .v3 .oas .annotations .Operation ;
11+ import io .swagger .v3 .oas .annotations .media .Content ;
12+ import io .swagger .v3 .oas .annotations .media .Schema ;
13+ import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
1014import jakarta .inject .Inject ;
1115import jakarta .validation .Valid ;
1216import net .onelitefeather .otis .database .entity .OtisPlayer ;
@@ -26,14 +30,56 @@ public OtisRequestsController(OtisPlayerRepository repository) {
2630 this .repository = repository ;
2731 }
2832
33+ @ Operation (
34+ summary = "Add a new Otis player" ,
35+ description = "This endpoint allows you to add a new Otis player to the database." ,
36+ tags = {"Player" }
37+ )
38+ @ ApiResponse (
39+ responseCode = "200" ,
40+ description = "Player added successfully" ,
41+ content = @ Content (
42+ mediaType = "application/json" ,
43+ schema = @ Schema (implementation = OtisPlayerDTO .class )
44+ )
45+ )
46+ @ ApiResponse (
47+ responseCode = "500" ,
48+ description = "The player could not be added to the database" ,
49+ content = @ Content (
50+ mediaType = "application/json" ,
51+ schema = @ Schema (implementation = String .class )
52+ )
53+ )
2954 @ Validated
30- @ Post ()
55+ @ Post
3156 public HttpResponse <OtisPlayerDTO > add (@ Valid OtisPlayerDTO playerDTO ) {
3257 OtisPlayer otisPlayer = OtisPlayer .toEntity (playerDTO );
3358 OtisPlayer saved = repository .save (otisPlayer );
3459 return HttpResponse .ok (saved .toDto ());
3560 }
3661
62+ @ Operation (
63+ summary = "Get Otis player by ID" ,
64+ description = "This endpoint retrieves an Otis player by their UUID." ,
65+ tags = {"Player" }
66+ )
67+ @ ApiResponse (
68+ responseCode = "200" ,
69+ description = "Player was successfully found." ,
70+ content = @ Content (
71+ mediaType = "application/json" ,
72+ schema = @ Schema (implementation = OtisPlayerDTO .class )
73+ )
74+ )
75+ @ ApiResponse (
76+ responseCode = "404" ,
77+ description = "Player not found" ,
78+ content = @ Content (
79+ mediaType = "application/json" ,
80+ schema = @ Schema (implementation = String .class )
81+ )
82+ )
3783 @ Validated
3884 @ Get ("/byId/{owner}" )
3985 public HttpResponse <OtisPlayerDTO > getById (@ Valid UUID owner ) {
@@ -44,6 +90,27 @@ public HttpResponse<OtisPlayerDTO> getById(@Valid UUID owner) {
4490 return HttpResponse .ok (entity .toDto ());
4591 }
4692
93+ @ Operation (
94+ summary = "Get Otis player by name" ,
95+ description = "This endpoint retrieves an Otis player by their name." ,
96+ tags = {"Player" }
97+ )
98+ @ ApiResponse (
99+ responseCode = "200" ,
100+ description = "Player was successfully found." ,
101+ content = @ Content (
102+ mediaType = "application/json" ,
103+ schema = @ Schema (implementation = OtisPlayerDTO .class )
104+ )
105+ )
106+ @ ApiResponse (
107+ responseCode = "404" ,
108+ description = "Player not found" ,
109+ content = @ Content (
110+ mediaType = "application/json" ,
111+ schema = @ Schema (implementation = String .class )
112+ )
113+ )
47114 @ Validated
48115 @ Get ("/byName/{owner}" )
49116 public HttpResponse <OtisPlayerDTO > getByString (@ Valid String owner ) {
@@ -54,6 +121,27 @@ public HttpResponse<OtisPlayerDTO> getByString(@Valid String owner) {
54121 return HttpResponse .ok (entity .toDto ());
55122 }
56123
124+ @ Operation (
125+ summary = "Update an existing Otis player" ,
126+ description = "This endpoint allows you to update an existing Otis player in the database." ,
127+ tags = {"Player" }
128+ )
129+ @ ApiResponse (
130+ responseCode = "200" ,
131+ description = "Player updated successfully" ,
132+ content = @ Content (
133+ mediaType = "application/json" ,
134+ schema = @ Schema (implementation = OtisPlayerDTO .class )
135+ )
136+ )
137+ @ ApiResponse (
138+ responseCode = "400" ,
139+ description = "Bad request, player UUID does not match the owner" ,
140+ content = @ Content (
141+ mediaType = "application/json" ,
142+ schema = @ Schema (implementation = String .class )
143+ )
144+ )
57145 @ Validated
58146 @ Post ("/update/{owner}" )
59147 public HttpResponse <OtisPlayerDTO > update (@ Valid UUID owner , @ Valid OtisPlayerDTO playerDTO ) {
@@ -65,6 +153,27 @@ public HttpResponse<OtisPlayerDTO> update(@Valid UUID owner, @Valid OtisPlayerDT
65153 return HttpResponse .ok (saved .toDto ());
66154 }
67155
156+ @ Operation (
157+ summary = "Delete an Otis player" ,
158+ description = "This endpoint allows you to delete an Otis player from the database." ,
159+ tags = {"Player" }
160+ )
161+ @ ApiResponse (
162+ responseCode = "200" ,
163+ description = "Player deleted successfully" ,
164+ content = @ Content (
165+ mediaType = "application/json" ,
166+ schema = @ Schema (implementation = OtisPlayerDTO .class )
167+ )
168+ )
169+ @ ApiResponse (
170+ responseCode = "404" ,
171+ description = "Player not found" ,
172+ content = @ Content (
173+ mediaType = "application/json" ,
174+ schema = @ Schema (implementation = String .class )
175+ )
176+ )
68177 @ Validated
69178 @ Post ("/delete/{owner}" )
70179 public HttpResponse <OtisPlayerDTO > delete (@ Valid UUID owner ) {
@@ -82,7 +191,28 @@ public HttpResponse<OtisPlayerDTO> delete(@Valid UUID owner) {
82191 * @param pageable the pageable instance
83192 * @return a list of all players
84193 */
85- @ Get ("/all" )
194+ @ Operation (
195+ summary = "Get all Otis players" ,
196+ description = "This endpoint retrieves all Otis players from the database." ,
197+ tags = {"Player" }
198+ )
199+ @ ApiResponse (
200+ responseCode = "200" ,
201+ description = "Players retrieved successfully" ,
202+ content = @ Content (
203+ mediaType = "application/json" ,
204+ schema = @ Schema (implementation = OtisPlayerDTO .class )
205+ )
206+ )
207+ @ ApiResponse (
208+ responseCode = "404" ,
209+ description = "No players found" ,
210+ content = @ Content (
211+ mediaType = "application/json" ,
212+ schema = @ Schema (implementation = String .class )
213+ )
214+ )
215+ @ Get (uris = {"/getAll" , "/all" })
86216 public HttpResponse <Iterable <OtisPlayerDTO >> getAll (Pageable pageable ) {
87217 Page <OtisPlayer > entities = this .repository .findAll (pageable );
88218 if (entities .isEmpty ()) {
0 commit comments