From 6676ebac0dc135de33047b3bd3b35530633dd97a Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Mon, 12 Aug 2024 17:01:10 +0530 Subject: [PATCH] feat: Added accounts endpoint --- .../oid/fed/server/admin/Application.kt | 2 ++ .../common/httpclient/OidFederationClient.kt | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/admin-server/src/main/kotlin/com/sphereon/oid/fed/server/admin/Application.kt b/modules/admin-server/src/main/kotlin/com/sphereon/oid/fed/server/admin/Application.kt index 654f00f7..56dfdade 100644 --- a/modules/admin-server/src/main/kotlin/com/sphereon/oid/fed/server/admin/Application.kt +++ b/modules/admin-server/src/main/kotlin/com/sphereon/oid/fed/server/admin/Application.kt @@ -2,8 +2,10 @@ package com.sphereon.oid.fed.server.admin import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.context.annotation.ComponentScan @SpringBootApplication +@ComponentScan(basePackages = ["com.sphereon.oid.fed.services"]) class Application fun main(args: Array) { diff --git a/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/httpclient/OidFederationClient.kt b/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/httpclient/OidFederationClient.kt index 64f29f6c..e849f67d 100644 --- a/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/httpclient/OidFederationClient.kt +++ b/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/httpclient/OidFederationClient.kt @@ -12,6 +12,7 @@ import io.ktor.client.plugins.logging.* import io.ktor.client.request.* import io.ktor.client.request.forms.* import io.ktor.http.* +import io.ktor.http.HttpMethod.Companion.Delete import io.ktor.http.HttpMethod.Companion.Get import io.ktor.http.HttpMethod.Companion.Post import io.ktor.serialization.kotlinx.json.* @@ -65,4 +66,29 @@ class OidFederationClient( }.body() } } + + suspend fun fetchAccount(url: String, httpMethod: HttpMethod = Get, parameters: Parameters = Parameters.Empty): String { + return when (httpMethod) { + Get -> getAccount(url) + Post -> postAccount(url, parameters) + Delete -> deleteAccount(url) + else -> throw IllegalArgumentException("Unsupported HTTP method: $httpMethod") + } + } + + private suspend fun getAccount(url: String): String { + return client.use { it.get(url).body() } + } + + private suspend fun postAccount(url: String, parameters: Parameters): String { + return client.use { + it.post(url) { + setBody(FormDataContent(parameters)) + }.body() + } + } + + private suspend fun deleteAccount(url: String): String { + return client.use { it.delete(url).body() } + } }