-
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 Trust Mark Definitions
- Loading branch information
Showing
22 changed files
with
583 additions
and
101 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...ain/kotlin/com/sphereon/oid/fed/server/admin/controllers/TrustMarkDefinitionController.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,60 @@ | ||
package com.sphereon.oid.fed.server.admin.controllers | ||
|
||
import com.sphereon.oid.fed.openapi.models.CreateTrustMarkDefinitionDTO | ||
import com.sphereon.oid.fed.openapi.models.TrustMarkDefinitionDTO | ||
import com.sphereon.oid.fed.openapi.models.UpdateTrustMarkDefinitionDTO | ||
import com.sphereon.oid.fed.services.AccountService | ||
import com.sphereon.oid.fed.services.TrustMarkService | ||
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.PutMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/accounts/{username}/trust-mark-definitions") | ||
class TrustMarkDefinitionController { | ||
private val accountService = AccountService() | ||
private val trustMarkService = TrustMarkService() | ||
|
||
@GetMapping | ||
fun getTrustMarkDefinitions(@PathVariable username: String): List<TrustMarkDefinitionDTO> { | ||
return trustMarkService.findAllByAccount(accountService.usernameToAccountId(username)) | ||
} | ||
|
||
@PostMapping | ||
fun createTrustMarkDefinition( | ||
@PathVariable username: String, | ||
@RequestBody createDto: CreateTrustMarkDefinitionDTO | ||
): TrustMarkDefinitionDTO { | ||
return trustMarkService.createTrustMarkDefinition(accountService.usernameToAccountId(username), createDto) | ||
} | ||
|
||
@GetMapping("/{id}") | ||
fun getTrustMarkDefinitionById( | ||
@PathVariable username: String, | ||
@PathVariable id: Int | ||
): TrustMarkDefinitionDTO { | ||
return trustMarkService.findById(accountService.usernameToAccountId(username), id) | ||
} | ||
|
||
@PutMapping("/{id}") | ||
fun updateTrustMarkDefinition( | ||
@PathVariable username: String, | ||
@PathVariable id: Int, | ||
@RequestBody updateDto: UpdateTrustMarkDefinitionDTO | ||
): TrustMarkDefinitionDTO { | ||
return trustMarkService.updateTrustMarkDefinition(accountService.usernameToAccountId(username), id, updateDto) | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
fun deleteTrustMarkDefinition( | ||
@PathVariable username: String, | ||
@PathVariable id: Int | ||
): TrustMarkDefinitionDTO { | ||
return trustMarkService.deleteTrustMarkDefinition(accountService.usernameToAccountId(username), 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
1 change: 1 addition & 0 deletions
1
modules/persistence/src/commonMain/sqldelight/com/sphereon/oid/fed/persistence/models/1.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
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
20 changes: 19 additions & 1 deletion
20
modules/persistence/src/commonMain/sqldelight/com/sphereon/oid/fed/persistence/models/11.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 +1,19 @@ | ||
ALTER TABLE Account ADD COLUMN identifier VARCHAR(255) NULL; | ||
CREATE TABLE TrustMarkDefinition ( | ||
id SERIAL PRIMARY KEY, | ||
account_id INT NOT NULL, | ||
identifier TEXT NOT NULL, | ||
name TEXT NOT NULL, | ||
description TEXT, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
deleted_at TIMESTAMP, | ||
CONSTRAINT FK_AccountTrustMarkDefinition FOREIGN KEY (account_id) REFERENCES Account (id) ON DELETE CASCADE | ||
); | ||
|
||
CREATE UNIQUE INDEX unique_account_identifier_active | ||
ON TrustMarkDefinition (account_id, identifier) | ||
WHERE deleted_at IS NULL; | ||
|
||
CREATE INDEX idx_trustmarkdefinitions_account_id ON TrustMarkDefinition (account_id); | ||
|
||
CREATE INDEX idx_trustmarkdefinitions_deleted_at ON TrustMarkDefinition (deleted_at); |
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
24 changes: 14 additions & 10 deletions
24
.../persistence/src/commonMain/sqldelight/com/sphereon/oid/fed/persistence/models/Account.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
findAll: | ||
SELECT * FROM Account WHERE deleted_at IS NULL; | ||
SELECT * | ||
FROM Account | ||
WHERE deleted_at IS NULL; | ||
|
||
create: | ||
INSERT INTO Account (username, identifier) VALUES (?, ?) RETURNING *; | ||
INSERT INTO Account (username, identifier) | ||
VALUES (?, ?) | ||
RETURNING *; | ||
|
||
delete: | ||
UPDATE Account SET deleted_at = CURRENT_TIMESTAMP WHERE id = ? RETURNING *; | ||
UPDATE Account | ||
SET deleted_at = CURRENT_TIMESTAMP | ||
WHERE id = ? | ||
RETURNING *; | ||
|
||
findByUsername: | ||
SELECT * FROM Account WHERE username = ? AND deleted_at IS NULL; | ||
|
||
findById: | ||
SELECT * FROM Account WHERE id = ? AND deleted_at IS NULL; | ||
|
||
update: | ||
UPDATE Account SET username = ? WHERE id = ? AND deleted_at IS NULL RETURNING *; | ||
SELECT * | ||
FROM Account | ||
WHERE username = ? | ||
AND deleted_at IS NULL; |
Oops, something went wrong.