-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement subordinate relationship create
- Loading branch information
Showing
10 changed files
with
208 additions
and
28 deletions.
There are no files selected for viewing
21 changes: 15 additions & 6 deletions
21
...er/src/main/kotlin/com/sphereon/oid/fed/server/admin/controllers/SubordinateController.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 |
---|---|---|
@@ -1,19 +1,28 @@ | ||
package com.sphereon.oid.fed.server.admin.controllers | ||
|
||
import com.sphereon.oid.fed.openapi.models.CreateSubordinateDTO | ||
import com.sphereon.oid.fed.openapi.models.SubordinateAdminDTO | ||
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 | ||
import com.sphereon.oid.fed.services.extensions.toSubordinateAdminDTO | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@RequestMapping("/accounts/{accountUsername}/subordinates") | ||
class SubordinateController { | ||
private val subordinateService = SubordinateService() | ||
|
||
@GetMapping | ||
fun getSubordinates(@PathVariable accountUsername: String): List<Subordinate> { | ||
return subordinateService.findSubordinatesByAccount(accountUsername) | ||
fun getSubordinates(@PathVariable accountUsername: String): Array<SubordinateAdminDTO> { | ||
return subordinateService.findSubordinatesByAccount(accountUsername).map { it.toSubordinateAdminDTO() } | ||
.toTypedArray() | ||
} | ||
|
||
@PostMapping | ||
fun createSubordinate( | ||
@PathVariable accountUsername: String, | ||
@RequestBody subordinate: CreateSubordinateDTO | ||
): Subordinate { | ||
return subordinateService.createSubordinate(accountUsername, subordinate) | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
.../commonMain/kotlin/com/sphereon/oid/fed/common/builder/FederationEntityMetadataBuilder.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,16 @@ | ||
package com.sphereon.oid.fed.common.builder | ||
|
||
import com.sphereon.oid.fed.openapi.models.FederationEntityMetadata | ||
|
||
class FederationEntityMetadataBuilder { | ||
private var identifier: String? = null | ||
|
||
fun identifier(identifier: String) = apply { this.identifier = identifier } | ||
|
||
fun build(): FederationEntityMetadata { | ||
return FederationEntityMetadata( | ||
federationListEndpoint = "${identifier}/list", | ||
federationFetchEndpoint = "${identifier}/fetch" | ||
) | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
modules/persistence/src/commonMain/sqldelight/com/sphereon/oid/fed/persistence/models/3.sqm
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
CREATE TABLE subordinate ( | ||
id SERIAL PRIMARY KEY, | ||
account_id INT NOT NULL, | ||
subordinate_identifier TEXT NOT NULL, | ||
identifier TEXT NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
deleted_at TIMESTAMP, | ||
CONSTRAINT FK_ParentSubordinate FOREIGN KEY (account_id) REFERENCES account (id), | ||
UNIQUE (account_id, subordinate_identifier) | ||
UNIQUE (account_id, identifier) | ||
); | ||
|
||
CREATE INDEX subordinate_account_id_index ON subordinate (account_id); | ||
CREATE INDEX subordinate_account_id_subordinate_identifier_index ON subordinate (account_id, subordinate_identifier); | ||
CREATE INDEX subordinate_account_id_subordinate_identifier_index ON subordinate (account_id, identifier); |
2 changes: 1 addition & 1 deletion
2
...sistence/src/commonMain/sqldelight/com/sphereon/oid/fed/persistence/models/Subordinate.sq
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
37 changes: 22 additions & 15 deletions
37
...es/services/src/commonMain/kotlin/com/sphereon/oid/fed/services/EntityStatementService.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
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
13 changes: 13 additions & 0 deletions
13
...es/src/commonMain/kotlin/com/sphereon/oid/fed/services/extensions/SubordinateExtension.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,13 @@ | ||
package com.sphereon.oid.fed.services.extensions | ||
|
||
import com.sphereon.oid.fed.openapi.models.SubordinateAdminDTO | ||
import com.sphereon.oid.fed.persistence.models.Subordinate | ||
|
||
fun Subordinate.toSubordinateAdminDTO(): SubordinateAdminDTO { | ||
return SubordinateAdminDTO( | ||
id = this.id, | ||
accountId = this.account_id, | ||
identifier = this.identifier, | ||
createdAt = this.created_at.toString(), | ||
) | ||
} |