Skip to content

Commit

Permalink
feat: implement AccountController
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmelati committed Jul 28, 2024
1 parent e5663a2 commit fef4ab9
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 87 deletions.
2 changes: 2 additions & 0 deletions modules/admin-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ java {
}

dependencies {
api(projects.modules.openapi)
api(projects.modules.openidFederationCommon)
api(projects.modules.persistence)
implementation(libs.springboot.actuator)
implementation(libs.springboot.web)
implementation(libs.kotlin.reflect)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sphereon.oid.fed.server.admin.controllers
import org.springframework.web.bind.annotation.*

import com.sphereon.oid.fed.openapi.models.AccountDTO
import com.sphereon.oid.fed.openapi.models.CreateAccountDTO
import com.sphereon.oid.fed.server.admin.services.*

@RestController
@RequestMapping("/account")
class AccountController {
private val accountService = AccountService()

@GetMapping
fun getAccounts(): List<AccountDTO> {
return accountService.findAll()
}

@PostMapping
fun createAccount(@RequestBody account: CreateAccountDTO) {
return accountService.create(account)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sphereon.oid.fed.server.admin.services

import com.sphereon.oid.fed.openapi.models.AccountDTO
import com.sphereon.oid.fed.openapi.models.CreateAccountDTO
import com.sphereon.oid.fed.persistence.Persistence
import com.sphereon.oid.fed.persistence.extensions.toDTO

class AccountService {
private val accountRepository = Persistence.accountRepository

fun create(account: CreateAccountDTO) {
return accountRepository.create(account)
}

fun findAll(): List<AccountDTO> {
return accountRepository.findAll().map { it.toDTO() }
}
}
2 changes: 1 addition & 1 deletion modules/openapi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ openApiGenerate {
inputSpec.set("$projectDir/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml")
library.set("multiplatform")
outputDir.set("$projectDir/build/generated")
configOptions.set(
configOptions.set(
mapOf(
"dateLibrary" to "string"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags:

servers:
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/SphereonInt/OpenIDFederationAPI/1.0.0-d36
url: https://virtserver.swaggerhub.com/SphereonInt/OpenIDFederationAPI/1.0.0-d35

paths:
/status:
Expand Down Expand Up @@ -1075,7 +1075,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/AccountResponse'
$ref: '#/components/schemas/AccountDTO'
'401':
description: Unauthorized
content:
Expand All @@ -1098,14 +1098,14 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAccountRequest'
$ref: '#/components/schemas/CreateAccountDTO'
responses:
'201':
description: Account created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/CreateAccountResponse'
$ref: '#/components/schemas/AccountDTO'
'400':
description: Invalid request
content:
Expand Down Expand Up @@ -1905,6 +1905,7 @@ components:
properties:
revoked_at:
type: string
format: date-time
reason:
type: string

Expand Down Expand Up @@ -1934,6 +1935,7 @@ components:
description: Expiration time after which the statement MUST NOT be accepted for processing.
iat:
type: integer
format: date-time
description: The time the statement was issued.
jwks:
$ref: '#/components/schemas/JWKS'
Expand Down Expand Up @@ -3397,9 +3399,11 @@ components:
properties:
iss:
type: string
format: date-time
description: The Entity's Entity Identifier.
iat:
type: integer
type: string
format: date-time
description: Time when the signed JWT was issued, using the time format defined for the iat claim in RFC7519.
keys:
type: array
Expand All @@ -3419,15 +3423,19 @@ components:
properties:
iss:
type: string
format: date-time
description: Entity Identifier of the issuer of the resolve response.
sub:
type: string
format: date-time
description: Entity Identifier of the subject of the resolve response.
iat:
type: integer
type: string
format: date-time
description: Time when this resolution was issued. This is expressed as Seconds Since the Epoch.
exp:
type: integer
type: string
format: date-time
description: Time when this resolution is no longer valid. This is expressed as Seconds Since the Epoch.
metadata:
$ref: '#/components/schemas/Metadata'
Expand Down Expand Up @@ -3497,40 +3505,15 @@ components:
type: string
description: The updated list of scopes for the user.

CreateAccountRequest:
CreateAccountDTO:
type: object
properties:
name:
type: string
description: The name of the account.
example: Acme Corporation
slug:
type: string
description: A unique, URL-friendly identifier for the account. Must be unique.
example: acme-corp
required:
- name
- slug

CreateAccountResponse:
type: object
properties:
id:
type: string
description: The unique identifier for the newly created account.
example: 12345
username:
type: string
description: The username of the account.
example: acmecorp
createdAt:
type: string
format: date-time
description: The date and time when the account was created.
updatedAt:
type: string
format: date-time
description: The date and time when the account was last updated.
example: acmeco
required:
- username

AddUserToAccountRequest:
type: object
Expand Down Expand Up @@ -3563,7 +3546,7 @@ components:
description: The role of the user within the account.
example: admin

Account:
AccountDTO:
type: object
properties:
id:
Expand All @@ -3574,19 +3557,6 @@ components:
type: string
description: The username of the account.
example: acmecorp
createdAt:
type: string
format: date-time
description: The date and time when the account was created.
updatedAt:
type: string
format: date-time
description: The date and time when the account was last updated.

AccountResponse:
type: array
items:
$ref: '#/components/schemas/Account'

CreateEntityStatementRequest:
properties:
Expand Down Expand Up @@ -3660,7 +3630,7 @@ components:

UserAccount:
allOf:
- $ref: '#/components/schemas/Account'
- $ref: '#/components/schemas/AccountDTO'
type: object
properties:
roles:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import com.sphereon.oid.fed.persistence.Database
package com.sphereon.oid.fed.persistence

import com.sphereon.oid.fed.persistence.repositories.AccountRepository

class Persistence(databaseFactory: DatabaseFactory, config: DatabaseConfig) {
val database: Database
expect object Persistence {
val accountRepository: AccountRepository

init {
val driver = databaseFactory.createDriver(config)
database = Database(driver)
accountRepository = AccountRepository(database)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sphereon.oid.fed.persistence.extensions

import com.sphereon.oid.fed.openapi.models.AccountDTO
import entities.Account as SqlDelightAccount

fun SqlDelightAccount.toDTO(): AccountDTO {
return AccountDTO(
username = this.username
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sphereon.oid.fed.persistence.repositories

import com.sphereon.oid.fed.openapi.models.CreateAccountRequest
import entities.*
import com.sphereon.oid.fed.persistence.Database

Expand All @@ -14,12 +15,12 @@ class AccountRepository(database: Database) {
return accountQueries.findByUsername(username).executeAsOneOrNull()
}

fun create(account: Account) {
accountQueries.create(account.username)
fun create(account: CreateAccountRequest) {
accountQueries.create(username = account.username)
}

fun findAll(): List<Account> {
return accountQueries.findAll().executeAsList()
return accountQueries.findAll().executeAsList().
}

fun delete(id: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sphereon.oid.fed.persistence
import PlatformSqlDriver
import com.sphereon.oid.fed.persistence.repositories.AccountRepository

actual object Persistence {
actual val accountRepository: AccountRepository

init {
val driver = PlatformSqlDriver().createPostgresDriver(System.getenv("DB_URL"), System.getenv("DB_USER"), System.getenv("DB_PASSWORD"))
val database = Database(driver)
accountRepository = AccountRepository(database)
}
}

This file was deleted.

0 comments on commit fef4ab9

Please sign in to comment.