@@ -7,17 +7,15 @@ import id.walt.db.repositories.AccountCredentialsRepository
7
7
import id.walt.db.repositories.CredentialsRepository
8
8
import id.walt.db.repositories.DbAccountCredentials
9
9
import id.walt.db.repositories.DbCredential
10
- import id.walt.service.dids.DidUpdateDataObject
11
10
import org.jetbrains.exposed.sql.innerJoin
12
11
import org.jetbrains.exposed.sql.select
13
12
import org.jetbrains.exposed.sql.selectAll
14
- import java.net.URLEncoder
15
13
import java.util.*
16
14
17
15
// TODO: replace DbCredential with a dto
18
16
object CredentialsService {
19
- fun get (account : UUID , credentialId : String ): DbCredential ? =
20
- list(account).singleOrNull { it.credentialId == credentialId }
17
+ fun get (account : UUID , id : String ): DbCredential ? =
18
+ list(account).singleOrNull { it.id == UUID .fromString(id) }
21
19
22
20
fun list (account : UUID ): List <DbCredential > = join(account).let {
23
21
AccountCredentialsRepository .query(it) {
@@ -29,43 +27,49 @@ object CredentialsService {
29
27
}
30
28
}
31
29
32
- fun add (account : UUID , credential : DbCredential ): UUID =
33
- getOrInsert(credential.credentialId, credential.document).let { cid ->
34
- join(account, credential.credentialId).let {
35
- AccountCredentialsRepository .query(it) {
36
- it[AccountCredentials .id]
37
- }
38
- }.takeIf { it.isNotEmpty() }?.single()?.value ? : let {
39
- AccountCredentialsRepository .insert(DbAccountCredentials (
30
+ fun add (account : UUID , credential : DbCredential ): UUID = CredentialsRepository .insert(
31
+ DbCredential (
32
+ credentialId = credential.credentialId,
33
+ document = credential.document,
34
+ )
35
+ ).let { cid ->
36
+ join(account, cid).let {
37
+ AccountCredentialsRepository .query(it) {
38
+ it[AccountCredentials .id]
39
+ }
40
+ }.takeIf { it.isNotEmpty() }?.single()?.value ? : let {
41
+ AccountCredentialsRepository .insert(
42
+ DbAccountCredentials (
40
43
account = account,
41
44
credential = cid,
42
- ))
43
- }
45
+ )
46
+ )
44
47
}
48
+ }
45
49
46
- fun delete (account : UUID , credentialId : String ): Boolean = join(account, credentialId ).let {
50
+ fun delete (account : UUID , id : String ): Boolean = join(account, UUID .fromString(id) ).let {
47
51
AccountCredentialsRepository .query(it) {
48
52
it[AccountCredentials .id]
49
53
}.singleOrNull()?.value
50
54
}?.let {
51
55
AccountCredentialsRepository .delete(it)
52
56
}?.let { it > 0 } ? : false
53
57
54
- fun update (account : UUID , did : DidUpdateDataObject ): Boolean {
58
+ fun update (account : UUID , credential : DbCredential ): Boolean {
55
59
TODO ()
56
60
}
57
61
58
- private fun join (account : UUID , credentialId : String ? = null) = Accounts .innerJoin(AccountCredentials ,
62
+ private fun join (account : UUID , id : UUID ? = null) = Accounts .innerJoin(AccountCredentials ,
59
63
onColumn = { Accounts .id },
60
64
otherColumn = { AccountCredentials .account },
61
65
additionalConstraint = {
62
66
Accounts .id eq account
63
67
}).innerJoin(Credentials ,
64
68
onColumn = { Credentials .id },
65
69
otherColumn = { AccountCredentials .credential },
66
- additionalConstraint = credentialId ?.let {
70
+ additionalConstraint = id ?.let {
67
71
{
68
- Credentials .credentialId eq credentialId
72
+ Credentials .id eq id
69
73
}
70
74
}).selectAll()
71
75
0 commit comments