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

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

30 Jan 2024 06:12PM UTC coverage: 30.205% (-0.3%) from 30.492%
7715589173

Pull #792

web-flow
feat: Refactor Anoncred Duplicate Code (#868)

Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
Pull Request #792: feat: ZKP verification

178 of 628 new or added lines in 27 files covered. (28.34%)

544 existing lines in 123 files now uncovered.

4097 of 13564 relevant lines covered (30.2%)

0.3 hits per line

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

32.69
/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
UNCOV
31
) {
×
32
  lazy val uniqueConstraintKey = author + name + version
33

1✔
34
  def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialDefinition =
1✔
UNCOV
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,
UNCOV
45
      id = m.id,
×
46
      name = m.name,
47
      version = m.version,
48
      author = m.author,
49
      authored = m.authored,
1✔
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,
UNCOV
75
      definition = db.definition.value,
×
76
      keyCorrectnessProofJsonSchemaId = db.keyCorrectnessProofJsonSchemaId,
77
      keyCorrectnessProof = db.keyCorrectnessProof.value,
UNCOV
78
      schemaId = db.schemaId,
×
79
      signatureType = db.signatureType,
80
      supportRevocation = db.supportRevocation
81
    )
UNCOV
82
  }
×
83
}
UNCOV
84

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

×
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))
UNCOV
105
        .filter(_.author == lift(author))
×
106
        .sortBy(_.version)(ord = Ord.asc)
107
        .map(_.version)
UNCOV
108
    )
×
109
  }
UNCOV
110

×
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
  }
UNCOV
119

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

1✔
129
  def deleteAll = run {
130
    quote {
131
      query[CredentialDefinition].delete
UNCOV
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
×
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)))
UNCOV
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 {
1✔
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
}
1✔
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