diff --git a/backend/src/main/java/net/onelitefeather/otis/OtisApplication.java b/backend/src/main/java/net/onelitefeather/otis/OtisApplication.java index c2fe300..4d3cd8b 100644 --- a/backend/src/main/java/net/onelitefeather/otis/OtisApplication.java +++ b/backend/src/main/java/net/onelitefeather/otis/OtisApplication.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.info.Contact; import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.License; +import io.swagger.v3.oas.annotations.tags.Tag; @ConfigurationProperties("application.properties") @OpenAPIDefinition( @@ -13,9 +14,12 @@ title = "Otis API", version = "0.0.1", description = "Simple user management system", - license = @License(name = "Close Source"), + license = @License(name = "Apache-2.0"), contact = @Contact(url = "https://onelitefeather.net", name = "Management", email = "admin@onelitefeather.net") - ) + ), + tags = { + @Tag(name = "Player", description = "Player management"), + } ) public class OtisApplication { diff --git a/backend/src/main/java/net/onelitefeather/otis/controller/OtisRequestsController.java b/backend/src/main/java/net/onelitefeather/otis/controller/OtisRequestsController.java index 835b4ef..84c8e28 100644 --- a/backend/src/main/java/net/onelitefeather/otis/controller/OtisRequestsController.java +++ b/backend/src/main/java/net/onelitefeather/otis/controller/OtisRequestsController.java @@ -7,6 +7,10 @@ import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.Post; import io.micronaut.validation.Validated; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.inject.Inject; import jakarta.validation.Valid; import net.onelitefeather.otis.database.entity.OtisPlayer; @@ -26,14 +30,56 @@ public OtisRequestsController(OtisPlayerRepository repository) { this.repository = repository; } + @Operation( + summary = "Add a new Otis player", + description = "This endpoint allows you to add a new Otis player to the database.", + tags = {"Player"} + ) + @ApiResponse( + responseCode = "200", + description = "Player added successfully", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "500", + description = "The player could not be added to the database", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Validated - @Post() + @Post public HttpResponse add(@Valid OtisPlayerDTO playerDTO) { OtisPlayer otisPlayer = OtisPlayer.toEntity(playerDTO); OtisPlayer saved = repository.save(otisPlayer); return HttpResponse.ok(saved.toDto()); } + @Operation( + summary = "Get Otis player by ID", + description = "This endpoint retrieves an Otis player by their UUID.", + tags = {"Player"} + ) + @ApiResponse( + responseCode = "200", + description = "Player was successfully found.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "404", + description = "Player not found", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Validated @Get("/byId/{owner}") public HttpResponse getById(@Valid UUID owner) { @@ -44,6 +90,27 @@ public HttpResponse getById(@Valid UUID owner) { return HttpResponse.ok(entity.toDto()); } + @Operation( + summary = "Get Otis player by name", + description = "This endpoint retrieves an Otis player by their name.", + tags = {"Player"} + ) + @ApiResponse( + responseCode = "200", + description = "Player was successfully found.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "404", + description = "Player not found", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Validated @Get("/byName/{owner}") public HttpResponse getByString(@Valid String owner) { @@ -54,6 +121,27 @@ public HttpResponse getByString(@Valid String owner) { return HttpResponse.ok(entity.toDto()); } + @Operation( + summary = "Update an existing Otis player", + description = "This endpoint allows you to update an existing Otis player in the database.", + tags = {"Player"} + ) + @ApiResponse( + responseCode = "200", + description = "Player updated successfully", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "400", + description = "Bad request, player UUID does not match the owner", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Validated @Post("/update/{owner}") public HttpResponse update(@Valid UUID owner, @Valid OtisPlayerDTO playerDTO) { @@ -65,6 +153,27 @@ public HttpResponse update(@Valid UUID owner, @Valid OtisPlayerDT return HttpResponse.ok(saved.toDto()); } + @Operation( + summary = "Delete an Otis player", + description = "This endpoint allows you to delete an Otis player from the database.", + tags = {"Player"} + ) + @ApiResponse( + responseCode = "200", + description = "Player deleted successfully", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "404", + description = "Player not found", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Validated @Post("/delete/{owner}") public HttpResponse delete(@Valid UUID owner) { @@ -82,7 +191,28 @@ public HttpResponse delete(@Valid UUID owner) { * @param pageable the pageable instance * @return a list of all players */ - @Get("/all") + @Operation( + summary = "Get all Otis players", + description = "This endpoint retrieves all Otis players from the database.", + tags = {"Player"} + ) + @ApiResponse( + responseCode = "200", + description = "Players retrieved successfully", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "404", + description = "No players found", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) + @Get(uris = {"/getAll", "/all"}) public HttpResponse> getAll(Pageable pageable) { Page entities = this.repository.findAll(pageable); if (entities.isEmpty()) { diff --git a/backend/src/main/java/net/onelitefeather/otis/controller/OtisSearchController.java b/backend/src/main/java/net/onelitefeather/otis/controller/OtisSearchController.java index d5f4164..148265f 100644 --- a/backend/src/main/java/net/onelitefeather/otis/controller/OtisSearchController.java +++ b/backend/src/main/java/net/onelitefeather/otis/controller/OtisSearchController.java @@ -3,6 +3,10 @@ import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.validation.constraints.Pattern; @@ -19,11 +23,37 @@ public class OtisSearchController { private final OtisPlayerRepository otisPlayerRepository; + /** + * Constructs a new reference to the OtisSearchController. + * + * @param playerRepository the repository to access player data. + */ @Inject - public OtisSearchController(OtisPlayerRepository otisPlayerRepository) { - this.otisPlayerRepository = otisPlayerRepository; + public OtisSearchController(OtisPlayerRepository playerRepository) { + this.otisPlayerRepository = playerRepository; } + @Operation( + summary = "Search for a player by their ID", + description = "Returns the player information if found, otherwise returns 404 Not Found.", + tags = {"Player", "Search"} + ) + @ApiResponse( + responseCode = "200", + description = "Player found and returned successfully.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "404", + description = "Player not found.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Valid @Get("/byId/{id}") public HttpResponse searchById(@Valid UUID id) { @@ -36,6 +66,27 @@ public HttpResponse searchById(@Valid UUID id) { return HttpResponse.ok(entity.get().toDto()); } + @Operation( + summary = "Search for a player by their name", + description = "Returns the player information if found, otherwise returns 404 Not Found.", + tags = {"Player", "Search"} + ) + @ApiResponse( + responseCode = "200", + description = "Player found and returned successfully.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = OtisPlayerDTO.class) + ) + ) + @ApiResponse( + responseCode = "404", + description = "Player not found.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = String.class) + ) + ) @Valid @Get("/byName/{name}") public HttpResponse searchByName(