Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error responses #47

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xcuserdata
!src/**/build/
local.properties
application-local.properties
.idea
.DS_Store
captures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ package com.sphereon.oid.fed.server.admin.controllers

import com.sphereon.oid.fed.openapi.models.AccountDTO
import com.sphereon.oid.fed.openapi.models.CreateAccountDTO
import com.sphereon.oid.fed.persistence.models.Account
import com.sphereon.oid.fed.services.AccountService
import org.springframework.web.bind.annotation.*
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")
Expand All @@ -19,4 +26,9 @@ class AccountController {
fun createAccount(@RequestBody account: CreateAccountDTO): AccountDTO {
return accountService.create(account)
}

@DeleteMapping("/{username}")
fun deleteAccount(@PathVariable username: String): Account {
return accountService.deleteAccount(username)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/authority-hints")
@RequestMapping("/accounts/{username}/authority-hints")
class AuthorityHintController {
private val authorityHintService = AuthorityHintService()

@GetMapping
fun getAuthorityHints(@PathVariable accountUsername: String): Array<AuthorityHint> {
return authorityHintService.findByAccountUsername(accountUsername)
fun getAuthorityHints(@PathVariable username: String): Array<AuthorityHint> {
return authorityHintService.findByAccountUsername(username)
}

@PostMapping
fun createAuthorityHint(
@PathVariable accountUsername: String,
@PathVariable username: String,
@RequestBody body: CreateAuthorityHintDTO
): AuthorityHint {
return authorityHintService.createAuthorityHint(accountUsername, body.identifier)
return authorityHintService.createAuthorityHint(username, body.identifier)
}

@DeleteMapping("/{id}")
fun deleteAuthorityHint(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int
): AuthorityHint {
return authorityHintService.deleteAuthorityHint(accountUsername, id)
return authorityHintService.deleteAuthorityHint(username, id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/crits")
@RequestMapping("/accounts/{username}/crits")
class CritController {
private val critService = CritService()

@PostMapping
fun createCrit(
@PathVariable accountUsername: String,
@PathVariable username: String,
@RequestBody body: CreateCritDTO
): Crit {
return critService.create(accountUsername, body.claim)
return critService.create(username, body.claim)
}

@GetMapping
fun getCrits(
@PathVariable accountUsername: String
@PathVariable username: String
): Array<Crit> {
return critService.findByAccountUsername(accountUsername)
return critService.findByAccountUsername(username)
}

@DeleteMapping("/{id}")
fun deleteCrit(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int
): Crit {
return critService.delete(accountUsername, id)
return critService.delete(username, id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/metadata")
@RequestMapping("/accounts/{username}/metadata")
class EntityConfigurationMetadataController {
private val entityConfigurationMetadataService = EntityConfigurationMetadataService()

@GetMapping
fun get(
@PathVariable accountUsername: String
@PathVariable username: String
): Array<EntityConfigurationMetadataDTO> {
return entityConfigurationMetadataService.findByAccountUsername(accountUsername)
return entityConfigurationMetadataService.findByAccountUsername(username)
}

@PostMapping
fun create(
@PathVariable accountUsername: String,
@PathVariable username: String,
@RequestBody body: CreateMetadataDTO
): EntityConfigurationMetadataDTO {
return entityConfigurationMetadataService.createEntityConfigurationMetadata(
accountUsername,
username,
body.key,
body.metadata
)
}

@DeleteMapping("/{id}")
fun delete(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int
): EntityConfigurationMetadataDTO {
return entityConfigurationMetadataService.deleteEntityConfigurationMetadata(accountUsername, id)
return entityConfigurationMetadataService.deleteEntityConfigurationMetadata(username, id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/entity-statement")
@RequestMapping("/accounts/{username}/entity-statement")
class EntityStatementController {
private val entityConfigurationStatementService = EntityConfigurationStatementService()

@GetMapping
fun getEntityStatement(@PathVariable accountUsername: String): EntityConfigurationStatement {
return entityConfigurationStatementService.findByUsername(accountUsername)
fun getEntityStatement(@PathVariable username: String): EntityConfigurationStatement {
return entityConfigurationStatementService.findByUsername(username)
}

@PostMapping
fun publishEntityStatement(
@PathVariable accountUsername: String,
@PathVariable username: String,
@RequestBody body: PublishEntityStatementDTO?
): String {
return entityConfigurationStatementService.publishByUsername(accountUsername, body?.dryRun ?: false)
return entityConfigurationStatementService.publishByUsername(username, body?.dryRun ?: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/keys")
@RequestMapping("/accounts/{username}/keys")
class KeyController {
private val keyService = KeyService()

@PostMapping
fun create(@PathVariable accountUsername: String): JwkAdminDTO {
val key = keyService.create(accountUsername)
fun create(@PathVariable username: String): JwkAdminDTO {
val key = keyService.create(username)
return key
}

@GetMapping
fun getKeys(@PathVariable accountUsername: String): Array<JwkAdminDTO> {
val keys = keyService.getKeys(accountUsername)
fun getKeys(@PathVariable username: String): Array<JwkAdminDTO> {
val keys = keyService.getKeys(username)
return keys
}

@DeleteMapping("/{keyId}")
fun revokeKey(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable keyId: Int,
@RequestParam reason: String?
): JwkAdminDTO {
return keyService.revokeKey(accountUsername, keyId, reason)
return keyService.revokeKey(username, keyId, reason)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,72 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

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

@GetMapping
fun getSubordinates(@PathVariable accountUsername: String): Array<SubordinateAdminDTO> {
return subordinateService.findSubordinatesByAccount(accountUsername).map { it.toSubordinateAdminDTO() }
fun getSubordinates(@PathVariable username: String): Array<SubordinateAdminDTO> {
return subordinateService.findSubordinatesByAccount(username).map { it.toSubordinateAdminDTO() }
.toTypedArray()
}

@PostMapping
fun createSubordinate(
@PathVariable accountUsername: String,
@PathVariable username: String,
@RequestBody subordinate: CreateSubordinateDTO
): Subordinate {
return subordinateService.createSubordinate(accountUsername, subordinate)
return subordinateService.createSubordinate(username, subordinate)
}

@DeleteMapping("/{id}")
fun deleteSubordinate(
@PathVariable username: String,
@PathVariable id: Int
): Subordinate {
return subordinateService.deleteSubordinate(username, id)
}

@PostMapping("/{id}/jwks")
fun createSubordinateJwk(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int,
@RequestBody jwk: JsonObject
): SubordinateJwkDto {
return subordinateService.createSubordinateJwk(accountUsername, id, jwk)
return subordinateService.createSubordinateJwk(username, id, jwk)
}

@GetMapping("/{id}/jwks")
fun getSubordinateJwks(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int
): Array<SubordinateJwkDto> {
return subordinateService.getSubordinateJwks(accountUsername, id)
return subordinateService.getSubordinateJwks(username, id)
}

@DeleteMapping("/{id}/jwks/{jwkId}")
fun deleteSubordinateJwk(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int,
@PathVariable jwkId: Int
) {
subordinateService.deleteSubordinateJwk(accountUsername, id, jwkId)
subordinateService.deleteSubordinateJwk(username, id, jwkId)
}

@GetMapping("/{id}/statement")
fun getSubordinateStatement(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int
): SubordinateStatement {
return subordinateService.getSubordinateStatement(accountUsername, id)
return subordinateService.getSubordinateStatement(username, id)
}

@PostMapping("/{id}/statement")
fun publishSubordinateStatement(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable id: Int,
@RequestBody dryRun: Boolean?
): String {
return subordinateService.publishSubordinateStatement(accountUsername, id, dryRun)
return subordinateService.publishSubordinateStatement(username, id, dryRun)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/accounts/{accountUsername}/subordinates/{subordinateId}/metadata")
@RequestMapping("/accounts/{username}/subordinates/{subordinateId}/metadata")
class SubordinateMetadataController {
private val subordinateService = SubordinateService()

@GetMapping
fun get(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable subordinateId: Int
): Array<SubordinateMetadataDTO> {
return subordinateService.findSubordinateMetadata(accountUsername, subordinateId)
return subordinateService.findSubordinateMetadata(username, subordinateId)
}

@PostMapping
fun create(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable subordinateId: Int,
@RequestBody body: CreateMetadataDTO
): SubordinateMetadataDTO {
return subordinateService.createMetadata(
accountUsername,
username,
subordinateId,
body.key,
body.metadata
Expand All @@ -40,10 +40,10 @@ class SubordinateMetadataController {

@DeleteMapping("/{id}")
fun delete(
@PathVariable accountUsername: String,
@PathVariable username: String,
@PathVariable subordinateId: Int,
@PathVariable id: Int
): SubordinateMetadataDTO {
return subordinateService.deleteSubordinateMetadata(accountUsername, subordinateId, id)
return subordinateService.deleteSubordinateMetadata(username, subordinateId, id)
}
}
Loading
Loading