Skip to content

Commit

Permalink
feat: implement federation list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmelati committed Aug 14, 2024
1 parent 15a4446 commit 5cd7366
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sphereon.oid.fed.server.admin.controllers

import com.sphereon.oid.fed.persistence.models.Subordinate
import com.sphereon.oid.fed.services.SubordinateService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/subordinates")
class SubordinateController {
private val subordinateService = SubordinateService()

@GetMapping
fun getSubordinates(@PathVariable accountUsername: String): List<Subordinate> {
return subordinateService.findSubordinatesByAccount(accountUsername)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sphereon.oid.fed.server.federation.controllers

import com.sphereon.oid.fed.services.SubordinateService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
Expand All @@ -8,6 +9,8 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping()
class FederationController {
private val subordinateService = SubordinateService()

@GetMapping("/.well-known/openid-federation")
fun getRootEntityConfigurationStatement(): String {
throw NotImplementedError()
Expand All @@ -19,8 +22,13 @@ class FederationController {
}

@GetMapping("/list")
fun getSubordinatesList(): List<String> {
throw NotImplementedError()
fun getRootSubordinatesList(): List<String> {
return subordinateService.findSubordinatesByAccountAsList("root")
}

@GetMapping("/{username}/list")
fun getSubordinatesList(@PathVariable username: String): List<String> {
return subordinateService.findSubordinatesByAccountAsList(username)
}

@GetMapping("/fetch")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.sphereon.oid.fed.services

import com.sphereon.oid.fed.persistence.Persistence
import com.sphereon.oid.fed.persistence.models.Subordinate

class SubordinateService {
private val accountRepository = Persistence.accountRepository
private val subordinateRepository = Persistence.subordinateRepository

fun findSubordinatesByAccount(accountUsername: String): List<Subordinate> {
val account = accountRepository.findByUsername(accountUsername)
?: throw IllegalArgumentException(Constants.ACCOUNT_NOT_FOUND)

return subordinateRepository.findByAccountId(account.id)
}

fun findSubordinatesByAccountAsList(accountUsername: String): List<String> {
val subordinates = findSubordinatesByAccount(accountUsername)
return subordinates.map { it.subordinate_identifier }
}
}

0 comments on commit 5cd7366

Please sign in to comment.