• 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

52.78
/pollux/lib/sql-doobie/src/main/scala/io/iohk/atala/pollux/sql/model/db/CredentialSchema.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.Schema
8
import io.iohk.atala.shared.models.WalletId
9

10
import java.time.OffsetDateTime
11
import java.util.UUID
12

13
case class CredentialSchema(
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
    `type`: String,
23
    schema: JsonValue[Schema],
24
    walletId: WalletId
25
) {
1✔
26
  lazy val uniqueConstraintKey = author + name + version
27
}
28

29
object CredentialSchema {
1✔
30
  def fromModel(
31
      m: io.iohk.atala.pollux.core.model.schema.CredentialSchema,
32
      walletId: WalletId
33
  ): CredentialSchema =
34
    CredentialSchema(
35
      guid = m.guid,
36
      id = m.id,
37
      name = m.name,
38
      version = m.version,
39
      author = m.author,
40
      authored = m.authored,
41
      tags = m.tags,
42
      description = m.description,
43
      `type` = m.`type`,
44
      schema = JsonValue(m.schema),
45
      walletId = walletId
46
    )
47

1✔
48
  def toModel(
49
      db: CredentialSchema
50
  ): io.iohk.atala.pollux.core.model.schema.CredentialSchema = {
51
    io.iohk.atala.pollux.core.model.schema.CredentialSchema(
52
      guid = db.guid,
53
      id = db.id,
54
      name = db.name,
55
      version = db.version,
56
      author = db.author,
57
      authored = db.authored,
58
      tags = db.tags,
59
      description = db.description,
60
      `type` = db.`type`,
61
      schema = db.schema.value
62
    )
63
  }
64
}
65

66
object CredentialSchemaSql extends DoobieContext.Postgres(SnakeCase) with PostgresJsonExtensions {
1✔
67
  def insert(schema: CredentialSchema) = run {
68
    quote(
69
      query[CredentialSchema]
70
        .insertValue(lift(schema))
71
    ).returning(cs => cs)
72
  }
73

1✔
74
  def findByGUID(guid: UUID) = run {
75
    quote(query[CredentialSchema].filter(_.guid == lift(guid)).take(1))
76
  }
77

×
78
  def findByID(id: UUID) = run {
79
    quote(query[CredentialSchema].filter(_.id == lift(id)))
80
  }
81

1✔
82
  def getAllVersions(id: UUID, author: String) = run {
83
    quote(
84
      query[CredentialSchema]
85
        .filter(_.id == lift(id))
86
        .filter(_.author == lift(author))
87
        .sortBy(_.version)(ord = Ord.asc)
88
        .map(_.version)
89
    )
90
  }
91

1✔
92
  def update(schema: CredentialSchema) = run {
93
    quote {
94
      query[CredentialSchema]
95
        .filter(_.guid == lift(schema.guid))
96
        .updateValue(lift(schema))
97
        .returning(s => s)
98
    }
99
  }
100

1✔
101
  def delete(guid: UUID) = run {
102
    quote {
103
      query[CredentialSchema]
104
        .filter(_.guid == lift(guid))
105
        .delete
106
        .returning(cs => cs)
107
    }
108
  }
109

1✔
110
  def deleteAll = run {
111
    quote {
112
      query[CredentialSchema].delete
113
    }
114
  }
115

1✔
116
  def totalCount = run {
117
    quote {
118
      query[CredentialSchema].size
119
    }
120
  }
121

1✔
122
  def lookupCount(
1✔
123
      idOpt: Option[UUID] = None,
1✔
124
      authorOpt: Option[String] = None,
1✔
125
      nameOpt: Option[String] = None,
1✔
126
      versionOpt: Option[String] = None,
1✔
127
      tagOpt: Option[String] = None
×
128
  ) = run {
129
    val q =
×
130
      idOpt.fold(quote(query[CredentialSchema]))(id => quote(query[CredentialSchema].filter(cs => cs.id == lift(id))))
131

×
132
    q.dynamic
133
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
134
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
135
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
×
136
      .filter(cs =>
137
        tagOpt
×
138
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
139
      )
×
140
      .size
141
  }
142

1✔
143
  def lookup(
1✔
144
      idOpt: Option[UUID] = None,
×
145
      authorOpt: Option[String] = None,
×
146
      nameOpt: Option[String] = None,
×
147
      versionOpt: Option[String] = None,
×
148
      tagOpt: Option[String] = None,
×
149
      offset: Int = 0,
×
150
      limit: Int = 1000
1✔
151
  ) = run {
152
    val q =
×
153
      idOpt.fold(quote(query[CredentialSchema]))(id => quote(query[CredentialSchema].filter(cs => cs.id == lift(id))))
154

×
155
    q.dynamic
156
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
157
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
158
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
×
159
      .filter(cs =>
160
        tagOpt
×
161
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
162
      )
163
      .sortBy(cs => cs.id)
164
      .drop(offset)
165
      .take(limit)
166
  }
167
}
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