• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8539884318

03 Apr 2024 01:50PM UTC coverage: 31.674% (+0.2%) from 31.453%
8539884318

Pull #958

patlo-iog
chore: pr cleanup

Signed-off-by: Pat Losoponkul <pat.losoponkul@iohk.io>
Pull Request #958: fix: add shared-crypto module and apollo wrapper for other key types

74 of 161 new or added lines in 9 files covered. (45.96%)

433 existing lines in 86 files now uncovered.

4525 of 14286 relevant lines covered (31.67%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.5
/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialDefinition.scala
1
package io.iohk.atala.pollux.sql.model.db
2

3
import io.getquill.*
4
import io.getquill.context.json.PostgresJsonExtensions
5
import io.getquill.doobie.DoobieContext
6
import io.getquill.idiom.*
7
import io.iohk.atala.pollux.core.model.schema.{CorrectnessProof, Definition}
8
import io.iohk.atala.shared.models.WalletId
9

10
import java.time.OffsetDateTime
11
import java.time.temporal.ChronoUnit
12
import java.util.UUID
13

14
case class CredentialDefinition(
15
    guid: UUID,
16
    id: UUID,
17
    name: String,
18
    version: String,
19
    author: String,
20
    authored: OffsetDateTime,
21
    tags: Seq[String],
22
    description: String,
23
    schemaId: String,
24
    definitionJsonSchemaId: String,
25
    definition: JsonValue[Definition],
26
    keyCorrectnessProofJsonSchemaId: String,
27
    keyCorrectnessProof: JsonValue[CorrectnessProof],
28
    signatureType: String,
29
    supportRevocation: Boolean,
30
    walletId: WalletId
31
) {
1✔
32
  lazy val uniqueConstraintKey = author + name + version
33

1✔
34
  def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialDefinition =
1✔
35
    copy(authored = authored.truncatedTo(unit))
36
}
37

38
object CredentialDefinition {
1✔
39
  def fromModel(
40
      m: io.iohk.atala.pollux.core.model.schema.CredentialDefinition,
41
      walletId: WalletId
42
  ): CredentialDefinition =
43
    CredentialDefinition(
44
      guid = m.guid,
45
      id = m.id,
46
      name = m.name,
47
      version = m.version,
48
      author = m.author,
49
      authored = m.authored,
×
50
      tags = Seq(m.tag),
51
      description = m.description,
52
      definitionJsonSchemaId = m.definitionJsonSchemaId,
53
      definition = JsonValue(m.definition),
54
      keyCorrectnessProofJsonSchemaId = m.keyCorrectnessProofJsonSchemaId,
55
      keyCorrectnessProof = JsonValue(m.keyCorrectnessProof),
56
      schemaId = m.schemaId,
57
      signatureType = m.signatureType,
58
      supportRevocation = m.supportRevocation,
59
      walletId = walletId
60
    )
61

1✔
62
  def toModel(
63
      db: CredentialDefinition
64
  ): io.iohk.atala.pollux.core.model.schema.CredentialDefinition = {
65
    io.iohk.atala.pollux.core.model.schema.CredentialDefinition(
66
      guid = db.guid,
67
      id = db.id,
68
      name = db.name,
69
      version = db.version,
70
      author = db.author,
71
      authored = db.authored,
×
72
      tag = db.tags.headOption.getOrElse(""),
73
      description = db.description,
74
      definitionJsonSchemaId = db.definitionJsonSchemaId,
75
      definition = db.definition.value,
76
      keyCorrectnessProofJsonSchemaId = db.keyCorrectnessProofJsonSchemaId,
77
      keyCorrectnessProof = db.keyCorrectnessProof.value,
78
      schemaId = db.schemaId,
79
      signatureType = db.signatureType,
80
      supportRevocation = db.supportRevocation
81
    )
82
  }
83
}
84

85
object CredentialDefinitionSql extends DoobieContext.Postgres(SnakeCase) with PostgresJsonExtensions {
1✔
86
  def insert(credentialDefinition: CredentialDefinition) = run {
87
    quote(
88
      query[CredentialDefinition]
89
        .insertValue(lift(credentialDefinition))
90
    ).returning(cs => cs)
91
  }
92

1✔
93
  def findByGUID(guid: UUID) = run {
94
    quote(query[CredentialDefinition].filter(_.guid == lift(guid)).take(1))
95
  }
96

×
97
  def findByID(id: UUID) = run {
98
    quote(query[CredentialDefinition].filter(_.id == lift(id)))
99
  }
100

×
101
  def getAllVersions(id: UUID, author: String) = run {
102
    quote(
103
      query[CredentialDefinition]
104
        .filter(_.id == lift(id))
105
        .filter(_.author == lift(author))
106
        .sortBy(_.version)(ord = Ord.asc)
107
        .map(_.version)
108
    )
109
  }
110

1✔
111
  def update(credentialDefinition: CredentialDefinition) = run {
112
    quote {
113
      query[CredentialDefinition]
114
        .filter(_.guid == lift(credentialDefinition.guid))
115
        .updateValue(lift(credentialDefinition))
116
        .returning(s => s)
117
    }
118
  }
119

1✔
120
  def delete(guid: UUID) = run {
121
    quote {
122
      query[CredentialDefinition]
123
        .filter(_.guid == lift(guid))
124
        .delete
125
        .returning(cs => cs)
126
    }
127
  }
UNCOV
128

×
129
  def deleteAll = run {
130
    quote {
131
      query[CredentialDefinition].delete
132
    }
133
  }
134

1✔
135
  def totalCount = run {
136
    quote {
137
      query[CredentialDefinition].size
138
    }
139
  }
140

1✔
141
  def lookupCount(
1✔
142
      idOpt: Option[UUID] = None,
1✔
143
      authorOpt: Option[String] = None,
1✔
144
      nameOpt: Option[String] = None,
1✔
145
      versionOpt: Option[String] = None,
1✔
146
      tagOpt: Option[String] = None
1✔
147
  ) = run {
148
    val q =
×
149
      idOpt.fold(quote(query[CredentialDefinition]))(id =>
150
        quote(query[CredentialDefinition].filter(cs => cs.id == lift(id)))
151
      )
152

×
153
    q.dynamic
154
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
155
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
156
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
×
157
      .filter(cs =>
158
        tagOpt
×
159
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
160
      )
×
161
      .size
162
  }
163

1✔
164
  def lookup(
1✔
165
      idOpt: Option[UUID] = None,
×
166
      authorOpt: Option[String] = None,
×
167
      nameOpt: Option[String] = None,
×
168
      versionOpt: Option[String] = None,
×
169
      tagOpt: Option[String] = None,
×
170
      offset: Int = 0,
×
171
      limit: Int = 1000
×
172
  ) = run {
173
    val q =
×
174
      idOpt.fold(quote(query[CredentialDefinition]))(id =>
175
        quote(query[CredentialDefinition].filter(cs => cs.id == lift(id)))
176
      )
177

×
178
    q.dynamic
179
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
180
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
181
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
×
182
      .filter(cs =>
183
        tagOpt
×
184
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
185
      )
186
      .sortBy(cs => cs.id)
187
      .drop(offset)
188
      .take(limit)
189
  }
190
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc