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

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

13 Sep 2023 04:00PM UTC coverage: 29.221% (+0.04%) from 29.185%
6174938546

push

web-flow
docs: update readme with latest release (#715)

Signed-off-by: Anton Baliasnikov <anton.baliasnikov@iohk.io>

3470 of 11875 relevant lines covered (29.22%)

0.29 hits per line

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

28.85
/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.util.UUID
12

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

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

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

81
object CredentialDefinitionSql extends DoobieContext.Postgres(SnakeCase) with PostgresJsonExtensions {
×
82
  def insert(credentialDefinition: CredentialDefinition) = run {
83
    quote(
84
      query[CredentialDefinition]
85
        .insertValue(lift(credentialDefinition))
86
    ).returning(cs => cs)
87
  }
×
88

×
89
  def findByGUID(guid: UUID) = run {
90
    quote(query[CredentialDefinition].filter(_.guid == lift(guid)).take(1))
91
  }
×
92

×
93
  def findByID(id: UUID) = run {
94
    quote(query[CredentialDefinition].filter(_.id == lift(id)))
95
  }
96

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

×
107
  def update(credentialDefinition: CredentialDefinition) = run {
108
    quote {
109
      query[CredentialDefinition]
110
        .filter(_.guid == lift(credentialDefinition.guid))
111
        .updateValue(lift(credentialDefinition))
×
112
        .returning(s => s)
113
    }
114
  }
115

×
116
  def delete(guid: UUID) = run {
117
    quote {
118
      query[CredentialDefinition]
119
        .filter(_.guid == lift(guid))
120
        .delete
121
        .returning(cs => cs)
122
    }
123
  }
124

1✔
125
  def deleteAll = run {
126
    quote {
127
      query[CredentialDefinition].delete
128
    }
129
  }
130

1✔
131
  def totalCount = run {
132
    quote {
133
      query[CredentialDefinition].size
134
    }
135
  }
×
136

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

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

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

×
174
    q.dynamic
175
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
176
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
177
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
×
178
      .filter(cs =>
179
        tagOpt
×
180
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
181
      )
182
      .sortBy(cs => cs.id)
183
      .drop(offset)
184
      .take(limit)
185
  }
186
}
×
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