From 6dc61740857e3ba51b5826aa2d7a50330d423181 Mon Sep 17 00:00:00 2001 From: luigi-borriello00 Date: Fri, 10 May 2024 14:12:34 +0200 Subject: [PATCH] docs(friendships-service): add enpoints api specs --- .../services/friendships/Application.kt | 25 ++++++++++- .../interfaces/web/api/FriendshipHttpApi.kt | 42 +++++++++++++++++++ .../src/main/resources/application.yml | 3 ++ .../piperkt/services/servers/Application.kt | 12 ------ 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/friendships-service/src/main/kotlin/piperkt/services/friendships/Application.kt b/friendships-service/src/main/kotlin/piperkt/services/friendships/Application.kt index 1da6ef5a..2887b0e5 100644 --- a/friendships-service/src/main/kotlin/piperkt/services/friendships/Application.kt +++ b/friendships-service/src/main/kotlin/piperkt/services/friendships/Application.kt @@ -1,7 +1,28 @@ package piperkt.services.friendships import io.micronaut.runtime.Micronaut.run +import io.swagger.v3.oas.annotations.OpenAPIDefinition +import io.swagger.v3.oas.annotations.info.Contact +import io.swagger.v3.oas.annotations.info.Info -fun main(vararg args: String) { - run(*args) +@OpenAPIDefinition( + info = + Info( + title = "Piper-kt Friendships API", + version = "1.0", + description = "Piper-kt Friendships Service API", + contact = + Contact( + url = "https://piper-kt.com", + name = "Zucchero Sintattico", + email = "zuccherosintattico@gmail.com" + ) + ) +) +object Application { + + @JvmStatic + fun main(args: Array) { + run(Application.javaClass) + } } diff --git a/friendships-service/src/main/kotlin/piperkt/services/friendships/interfaces/web/api/FriendshipHttpApi.kt b/friendships-service/src/main/kotlin/piperkt/services/friendships/interfaces/web/api/FriendshipHttpApi.kt index 91bf5823..1e564169 100644 --- a/friendships-service/src/main/kotlin/piperkt/services/friendships/interfaces/web/api/FriendshipHttpApi.kt +++ b/friendships-service/src/main/kotlin/piperkt/services/friendships/interfaces/web/api/FriendshipHttpApi.kt @@ -5,31 +5,67 @@ import io.micronaut.http.annotation.PathVariable import io.micronaut.http.annotation.QueryValue import io.micronaut.security.annotation.Secured import io.micronaut.security.rules.SecurityRule +import io.swagger.v3.oas.annotations.responses.ApiResponse +import io.swagger.v3.oas.annotations.responses.ApiResponses import java.security.Principal import piperkt.services.friendships.interfaces.web.api.interactions.FriendshipApi @Secured(SecurityRule.IS_AUTHENTICATED) interface FriendshipHttpApi { + @ApiResponses( + ApiResponse(responseCode = "200", description = "Friendship request sent successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ApiResponse(responseCode = "403", description = "Forbidden"), + ) fun sendFriendshipRequest( @Body request: FriendshipApi.SendFriendshipRequest.Request, principal: Principal ): FriendshipApi.SendFriendshipRequest.Response + @ApiResponses( + ApiResponse(responseCode = "200", description = "Friendship request accepted successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ApiResponse(responseCode = "404", description = "Friendship request not found"), + ) fun acceptFriendshipRequest( @Body request: FriendshipApi.AcceptFriendshipRequest.Request, principal: Principal ): FriendshipApi.AcceptFriendshipRequest.Response + @ApiResponses( + ApiResponse(responseCode = "200", description = "Friendship request declined successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ApiResponse(responseCode = "404", description = "Friendship request not found"), + ) fun declineFriendshipRequest( @Body request: FriendshipApi.DeclineFriendshipRequest.Request, principal: Principal ): FriendshipApi.DeclineFriendshipRequest.Response + @ApiResponses( + ApiResponse(responseCode = "200", description = "Friendship requests found successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ) fun getFriendshipRequests(principal: Principal): FriendshipApi.GetFriendshipRequests.Response + @ApiResponses( + ApiResponse(responseCode = "200", description = "Friendships found successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ) fun getFriendships(principal: Principal): FriendshipApi.GetFriendships.Response + @ApiResponses( + ApiResponse(responseCode = "200", description = "Friendship messages found successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ApiResponse(responseCode = "404", description = "Friendship not found"), + ) fun getFriendshipMessages( @PathVariable friendUsername: String, @QueryValue from: Int, @@ -37,6 +73,12 @@ interface FriendshipHttpApi { principal: Principal ): FriendshipApi.GetFriendshipMessages.Response + @ApiResponses( + ApiResponse(responseCode = "200", description = "Message sent successfully"), + ApiResponse(responseCode = "400", description = "Bad request"), + ApiResponse(responseCode = "401", description = "Unauthorized"), + ApiResponse(responseCode = "404", description = "Friendship not found"), + ) fun sendMessage( @PathVariable friendUsername: String, @Body request: FriendshipApi.SendMessage.Request, diff --git a/friendships-service/src/main/resources/application.yml b/friendships-service/src/main/resources/application.yml index a34c67ce..909f0c0a 100644 --- a/friendships-service/src/main/resources/application.yml +++ b/friendships-service/src/main/resources/application.yml @@ -4,3 +4,6 @@ application: mongodb: package-names: - piperkt.services.friendships.infrastructure.persistence +micronaut: + openapi: + filename: "openapi-friendships" diff --git a/servers-service/src/main/kotlin/piperkt/services/servers/Application.kt b/servers-service/src/main/kotlin/piperkt/services/servers/Application.kt index 45b31bcc..8db19c4b 100644 --- a/servers-service/src/main/kotlin/piperkt/services/servers/Application.kt +++ b/servers-service/src/main/kotlin/piperkt/services/servers/Application.kt @@ -26,15 +26,3 @@ object Application { Micronaut.run(Application.javaClass) } } -// LEVEL -> WHATS -> DEPENDENCIES -// -------------------------------- -// DOMAIN -> Language: -// - Entities -// - Value Objects -// - Repositories -// - Factories -// APPLICATION -> Domain -// - Services -// INTERFACES -> -// - Controller (Indepedent of the framework) -// INFRASTRUCTURE