-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
.../src/main/kotlin/com/sphereon/oid/fed/server/admin/controllers/AuthorityHintController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.sphereon.oid.fed.server.admin.controllers | ||
|
||
import com.sphereon.oid.fed.openapi.models.CreateAuthorityHintDTO | ||
import com.sphereon.oid.fed.persistence.models.AuthorityHint | ||
import com.sphereon.oid.fed.services.AuthorityHintService | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/accounts/{accountUsername}/authority-hints") | ||
class AuthorityHintController { | ||
private val authorityHintService = AuthorityHintService() | ||
|
||
@GetMapping | ||
fun getAuthorityHints(@PathVariable accountUsername: String): Array<AuthorityHint> { | ||
return authorityHintService.findByAccountUsername(accountUsername) | ||
} | ||
|
||
@PostMapping | ||
fun createAuthorityHint( | ||
@PathVariable accountUsername: String, | ||
@RequestBody body: CreateAuthorityHintDTO | ||
): AuthorityHint { | ||
return authorityHintService.createAuthorityHint(accountUsername, body.identifier) | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
fun deleteAuthorityHint( | ||
@PathVariable accountUsername: String, | ||
@PathVariable id: Int | ||
): AuthorityHint { | ||
return authorityHintService.deleteAuthorityHint(accountUsername, id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
modules/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/AuthorityHintService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.sphereon.oid.fed.services | ||
|
||
import com.sphereon.oid.fed.persistence.Persistence | ||
import com.sphereon.oid.fed.persistence.models.AuthorityHint | ||
|
||
class AuthorityHintService { | ||
|
||
fun createAuthorityHint(accountUsername: String, identifier: String): AuthorityHint { | ||
val account = Persistence.accountQueries.findByUsername(accountUsername).executeAsOneOrNull() | ||
?: throw IllegalArgumentException(Constants.ACCOUNT_NOT_FOUND) | ||
|
||
Persistence.authorityHintQueries.findByAccountIdAndIdentifier(account.id, identifier).executeAsOneOrNull() | ||
?: throw IllegalArgumentException(Constants.AUTHORITY_HINT_ALREADY_EXISTS) | ||
|
||
return Persistence.authorityHintQueries.create(account.id, identifier) | ||
.executeAsOneOrNull() | ||
?: throw IllegalStateException(Constants.FAILED_TO_CREATE_AUTHORITY_HINT) | ||
} | ||
|
||
fun deleteAuthorityHint(accountUsername: String, id: Int): AuthorityHint { | ||
val account = Persistence.accountQueries.findByUsername(accountUsername).executeAsOneOrNull() | ||
?: throw IllegalArgumentException(Constants.ACCOUNT_NOT_FOUND) | ||
|
||
Persistence.authorityHintQueries.findByAccountIdAndId(account.id, id).executeAsOneOrNull() | ||
?: throw IllegalArgumentException(Constants.AUTHORITY_HINT_NOT_FOUND) | ||
|
||
return Persistence.authorityHintQueries.delete(id).executeAsOneOrNull() | ||
?: throw IllegalStateException(Constants.FAILED_TO_DELETE_AUTHORITY_HINT) | ||
} | ||
|
||
fun findByAccountId(accountId: Int): Array<AuthorityHint> { | ||
return Persistence.authorityHintQueries.findByAccountId(accountId).executeAsList().toTypedArray() | ||
} | ||
|
||
fun findByAccountUsername(accountUsername: String): Array<AuthorityHint> { | ||
val account = Persistence.accountQueries.findByUsername(accountUsername).executeAsOneOrNull() | ||
?: throw IllegalArgumentException(Constants.ACCOUNT_NOT_FOUND) | ||
|
||
return findByAccountId(account.id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters