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

hyperledger / identus-cloud-agent / 10928456511

18 Sep 2024 06:45PM CUT coverage: 48.836% (-0.1%) from 48.942%
10928456511

Pull #1366

CryptoKnightIOG
ATL-7775: Default Backend API to Array Of Credential Schema

Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
Pull Request #1366: feat: Default Backend API to Array Of Credential Schema

24 of 32 new or added lines in 6 files covered. (75.0%)

310 existing lines in 58 files now uncovered.

7570 of 15501 relevant lines covered (48.84%)

0.49 hits per line

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

78.95
/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/model/db/CredentialSchema.scala
1
package org.hyperledger.identus.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 org.hyperledger.identus.pollux.core.model.schema.Schema
8
import org.hyperledger.identus.shared.models.WalletId
9

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

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

29
  def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialSchema =
1✔
30
    copy(authored = authored.truncatedTo(unit))
1✔
31

32
}
33

34
object CredentialSchema {
35
  def fromModel(
1✔
36
      m: org.hyperledger.identus.pollux.core.model.schema.CredentialSchema,
37
      walletId: WalletId
38
  ): CredentialSchema =
39
    CredentialSchema(
40
      guid = m.guid,
41
      id = m.id,
42
      name = m.name,
43
      version = m.version,
44
      author = m.author,
45
      authored = m.authored,
46
      tags = m.tags,
47
      description = m.description,
48
      `type` = m.`type`,
49
      schema = JsonValue(m.schema),
50
      walletId = walletId
51
    )
52

53
  def toModel(
1✔
54
      db: CredentialSchema
55
  ): org.hyperledger.identus.pollux.core.model.schema.CredentialSchema = {
56
    org.hyperledger.identus.pollux.core.model.schema.CredentialSchema(
57
      guid = db.guid,
58
      id = db.id,
59
      name = db.name,
60
      version = db.version,
61
      author = db.author,
62
      authored = db.authored,
63
      tags = db.tags,
64
      description = db.description,
65
      `type` = db.`type`,
66
      schema = db.schema.value
67
    )
68
  }
69
}
70

71
object CredentialSchemaSql extends DoobieContext.Postgres(SnakeCase) with PostgresJsonExtensions {
72
  def insert(schema: CredentialSchema) = run {
1✔
73
    quote(
74
      query[CredentialSchema]
75
        .insertValue(lift(schema))
76
    ).returning(cs => cs)
77
  }
78

79
  def findByGUID(guid: UUID) = run {
1✔
80
    quote(query[CredentialSchema].filter(_.guid == lift(guid)).take(1))
81
  }
82

83
  def findByID(id: UUID) = run {
×
84
    quote(query[CredentialSchema].filter(_.id == lift(id)))
85
  }
86

87
  def getAllVersions(id: UUID, author: String) = run {
1✔
88
    quote(
89
      query[CredentialSchema]
90
        .filter(_.id == lift(id))
91
        .filter(_.author == lift(author))
92
        .sortBy(_.version)(ord = Ord.asc)
93
        .map(_.version)
94
    )
95
  }
96

97
  def update(schema: CredentialSchema) = run {
1✔
98
    quote {
99
      query[CredentialSchema]
100
        .filter(_.guid == lift(schema.guid))
101
        .updateValue(lift(schema))
102
        .returning(s => s)
103
    }
104
  }
105

106
  def delete(guid: UUID) = run {
1✔
107
    quote {
108
      query[CredentialSchema]
109
        .filter(_.guid == lift(guid))
110
        .delete
111
        .returning(cs => cs)
112
    }
113
  }
114

115
  def deleteAll = run {
1✔
116
    quote {
117
      query[CredentialSchema].delete
118
    }
119
  }
120

121
  def totalCount = run {
1✔
122
    quote {
123
      query[CredentialSchema].size
124
    }
125
  }
126

127
  def lookupCount(
1✔
128
      idOpt: Option[UUID] = None,
1✔
129
      authorOpt: Option[String] = None,
1✔
130
      nameOpt: Option[String] = None,
1✔
131
      versionOpt: Option[String] = None,
1✔
132
      tagOpt: Option[String] = None
1✔
133
  ) = run {
1✔
134
    val q =
135
      idOpt.fold(quote(query[CredentialSchema]))(id => quote(query[CredentialSchema].filter(cs => cs.id == lift(id))))
1✔
136

137
    q.dynamic
1✔
138
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
139
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
140
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
141
      .filter(cs =>
1✔
142
        tagOpt
143
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
1✔
144
      )
145
      .size
1✔
146
  }
147

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

160
    q.dynamic
1✔
161
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
162
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
163
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
164
      .filter(cs =>
1✔
165
        tagOpt
166
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
1✔
167
      )
168
      .sortBy(cs => cs.id)
169
      .drop(offset)
170
      .take(limit)
171
  }
172
}
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