Skip to content

Commit

Permalink
feat: Added accounts endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Aug 12, 2024
1 parent 428401c commit 6676eba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -65,4 +66,29 @@ class OidFederationClient(
}.body<EntityStatement>()
}
}

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() }
}
}

0 comments on commit 6676eba

Please sign in to comment.