@@ -24,7 +24,7 @@ type Repository struct {
24
24
DB postgres.Database
25
25
}
26
26
27
- func (repo * Repository ) Update (ctx context.Context , client clients.Client ) (clients.Client , error ) {
27
+ func (repo * Repository ) Update (ctx context.Context , client clients.Client ) (clients.Client , errors. Error ) {
28
28
var query []string
29
29
var upq string
30
30
if client .Name != "" {
@@ -45,47 +45,48 @@ func (repo *Repository) Update(ctx context.Context, client clients.Client) (clie
45
45
return repo .update (ctx , client , q )
46
46
}
47
47
48
- func (repo * Repository ) UpdateTags (ctx context.Context , client clients.Client ) (clients.Client , error ) {
48
+ func (repo * Repository ) UpdateTags (ctx context.Context , client clients.Client ) (clients.Client , errors. Error ) {
49
49
q := `UPDATE clients SET tags = :tags, updated_at = :updated_at, updated_by = :updated_by
50
50
WHERE id = :id AND status = :status
51
51
RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
52
52
client .Status = clients .EnabledStatus
53
53
return repo .update (ctx , client , q )
54
54
}
55
55
56
- func (repo * Repository ) UpdateIdentity (ctx context.Context , client clients.Client ) (clients.Client , error ) {
56
+ func (repo * Repository ) UpdateIdentity (ctx context.Context , client clients.Client ) (clients.Client , errors. Error ) {
57
57
q := `UPDATE clients SET identity = :identity, updated_at = :updated_at, updated_by = :updated_by
58
58
WHERE id = :id AND status = :status
59
59
RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
60
60
client .Status = clients .EnabledStatus
61
61
return repo .update (ctx , client , q )
62
62
}
63
63
64
- func (repo * Repository ) UpdateSecret (ctx context.Context , client clients.Client ) (clients.Client , error ) {
64
+ func (repo * Repository ) UpdateSecret (ctx context.Context , client clients.Client ) (clients.Client , errors. Error ) {
65
65
q := `UPDATE clients SET secret = :secret, updated_at = :updated_at, updated_by = :updated_by
66
66
WHERE id = :id AND status = :status
67
67
RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
68
68
client .Status = clients .EnabledStatus
69
69
return repo .update (ctx , client , q )
70
70
}
71
71
72
- func (repo * Repository ) UpdateRole (ctx context.Context , client clients.Client ) (clients.Client , error ) {
72
+ func (repo * Repository ) UpdateRole (ctx context.Context , client clients.Client ) (clients.Client , errors. Error ) {
73
73
q := `UPDATE clients SET role = :role, updated_at = :updated_at, updated_by = :updated_by
74
74
WHERE id = :id AND status = :status
75
75
RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, role, created_at, updated_at, updated_by`
76
76
client .Status = clients .EnabledStatus
77
- return repo .update (ctx , client , q )
77
+ cl , err := repo .update (ctx , client , q )
78
+ return cl , errors .Cast (err )
78
79
}
79
80
80
- func (repo * Repository ) ChangeStatus (ctx context.Context , client clients.Client ) (clients.Client , error ) {
81
+ func (repo * Repository ) ChangeStatus (ctx context.Context , client clients.Client ) (clients.Client , errors. Error ) {
81
82
q := `UPDATE clients SET status = :status, updated_at = :updated_at, updated_by = :updated_by
82
83
WHERE id = :id
83
84
RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
84
85
85
86
return repo .update (ctx , client , q )
86
87
}
87
88
88
- func (repo * Repository ) RetrieveByID (ctx context.Context , id string ) (clients.Client , error ) {
89
+ func (repo * Repository ) RetrieveByID (ctx context.Context , id string ) (clients.Client , errors. Error ) {
89
90
q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status
90
91
FROM clients WHERE id = :id`
91
92
@@ -105,13 +106,14 @@ func (repo *Repository) RetrieveByID(ctx context.Context, id string) (clients.Cl
105
106
return clients.Client {}, errors .Wrap (repoerr .ErrViewEntity , err )
106
107
}
107
108
108
- return ToClient (dbc )
109
+ cl , err := ToClient (dbc )
110
+ return cl , errors .Cast (err )
109
111
}
110
112
111
113
return clients.Client {}, repoerr .ErrNotFound
112
114
}
113
115
114
- func (repo * Repository ) RetrieveByIdentity (ctx context.Context , identity string ) (clients.Client , error ) {
116
+ func (repo * Repository ) RetrieveByIdentity (ctx context.Context , identity string ) (clients.Client , errors. Error ) {
115
117
q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status
116
118
FROM clients WHERE identity = :identity AND status = :status`
117
119
@@ -122,7 +124,7 @@ func (repo *Repository) RetrieveByIdentity(ctx context.Context, identity string)
122
124
123
125
row , err := repo .DB .NamedQueryContext (ctx , q , dbc )
124
126
if err != nil {
125
- return clients.Client {}, postgres .HandleError (repoerr .ErrViewEntity , err )
127
+ return clients.Client {}, errors . Cast ( postgres .HandleError (repoerr .ErrViewEntity , err ) )
126
128
}
127
129
defer row .Close ()
128
130
@@ -138,7 +140,7 @@ func (repo *Repository) RetrieveByIdentity(ctx context.Context, identity string)
138
140
return clients.Client {}, repoerr .ErrNotFound
139
141
}
140
142
141
- func (repo * Repository ) RetrieveAll (ctx context.Context , pm clients.Page ) (clients.ClientsPage , error ) {
143
+ func (repo * Repository ) RetrieveAll (ctx context.Context , pm clients.Page ) (clients.ClientsPage , errors. Error ) {
142
144
query , err := PageQuery (pm )
143
145
if err != nil {
144
146
return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
@@ -151,9 +153,9 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
151
153
if err != nil {
152
154
return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
153
155
}
154
- rows , err := repo .DB .NamedQueryContext (ctx , q , dbPage )
155
- if err != nil {
156
- return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
156
+ rows , Err := repo .DB .NamedQueryContext (ctx , q , dbPage )
157
+ if Err != nil {
158
+ return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , Err )
157
159
}
158
160
defer rows .Close ()
159
161
@@ -173,9 +175,9 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
173
175
}
174
176
cq := fmt .Sprintf (`SELECT COUNT(*) FROM clients c %s;` , query )
175
177
176
- total , err := postgres .Total (ctx , repo .DB , cq , dbPage )
177
- if err != nil {
178
- return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
178
+ total , Err := postgres .Total (ctx , repo .DB , cq , dbPage )
179
+ if Err != nil {
180
+ return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , Err )
179
181
}
180
182
181
183
page := clients.ClientsPage {
@@ -190,7 +192,7 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
190
192
return page , nil
191
193
}
192
194
193
- func (repo * Repository ) RetrieveAllBasicInfo (ctx context.Context , pm clients.Page ) (clients.ClientsPage , error ) {
195
+ func (repo * Repository ) RetrieveAllBasicInfo (ctx context.Context , pm clients.Page ) (clients.ClientsPage , errors. Error ) {
194
196
sq , tq := constructSearchQuery (pm )
195
197
196
198
q := fmt .Sprintf (`SELECT c.id, c.name, c.created_at, c.updated_at FROM clients c %s LIMIT :limit OFFSET :offset;` , sq )
@@ -200,9 +202,9 @@ func (repo *Repository) RetrieveAllBasicInfo(ctx context.Context, pm clients.Pag
200
202
return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
201
203
}
202
204
203
- rows , err := repo .DB .NamedQueryContext (ctx , q , dbPage )
204
- if err != nil {
205
- return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
205
+ rows , Err := repo .DB .NamedQueryContext (ctx , q , dbPage )
206
+ if Err != nil {
207
+ return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , Err )
206
208
}
207
209
defer rows .Close ()
208
210
@@ -222,9 +224,9 @@ func (repo *Repository) RetrieveAllBasicInfo(ctx context.Context, pm clients.Pag
222
224
}
223
225
224
226
cq := fmt .Sprintf (`SELECT COUNT(*) FROM clients c %s;` , tq )
225
- total , err := postgres .Total (ctx , repo .DB , cq , dbPage )
226
- if err != nil {
227
- return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
227
+ total , Err := postgres .Total (ctx , repo .DB , cq , dbPage )
228
+ if Err != nil {
229
+ return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , Err )
228
230
}
229
231
230
232
page := clients.ClientsPage {
@@ -239,7 +241,7 @@ func (repo *Repository) RetrieveAllBasicInfo(ctx context.Context, pm clients.Pag
239
241
return page , nil
240
242
}
241
243
242
- func (repo * Repository ) RetrieveAllByIDs (ctx context.Context , pm clients.Page ) (clients.ClientsPage , error ) {
244
+ func (repo * Repository ) RetrieveAllByIDs (ctx context.Context , pm clients.Page ) (clients.ClientsPage , errors. Error ) {
243
245
if (len (pm .IDs ) == 0 ) && (pm .Domain == "" ) {
244
246
return clients.ClientsPage {
245
247
Page : clients.Page {Total : pm .Total , Offset : pm .Offset , Limit : pm .Limit },
@@ -257,9 +259,9 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (
257
259
if err != nil {
258
260
return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
259
261
}
260
- rows , err := repo .DB .NamedQueryContext (ctx , q , dbPage )
261
- if err != nil {
262
- return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
262
+ rows , Err := repo .DB .NamedQueryContext (ctx , q , dbPage )
263
+ if Err != nil {
264
+ return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , Err )
263
265
}
264
266
defer rows .Close ()
265
267
@@ -279,9 +281,9 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (
279
281
}
280
282
cq := fmt .Sprintf (`SELECT COUNT(*) FROM clients c %s;` , query )
281
283
282
- total , err := postgres .Total (ctx , repo .DB , cq , dbPage )
283
- if err != nil {
284
- return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
284
+ total , Err := postgres .Total (ctx , repo .DB , cq , dbPage )
285
+ if Err != nil {
286
+ return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , Err )
285
287
}
286
288
287
289
page := clients.ClientsPage {
@@ -296,15 +298,15 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (
296
298
return page , nil
297
299
}
298
300
299
- func (repo * Repository ) update (ctx context.Context , client clients.Client , query string ) (clients.Client , error ) {
301
+ func (repo * Repository ) update (ctx context.Context , client clients.Client , query string ) (clients.Client , errors. Error ) {
300
302
dbc , err := ToDBClient (client )
301
303
if err != nil {
302
304
return clients.Client {}, errors .Wrap (repoerr .ErrUpdateEntity , err )
303
305
}
304
306
305
- row , err := repo .DB .NamedQueryContext (ctx , query , dbc )
306
- if err != nil {
307
- return clients.Client {}, postgres .HandleError (repoerr .ErrUpdateEntity , err )
307
+ row , Err := repo .DB .NamedQueryContext (ctx , query , dbc )
308
+ if Err != nil {
309
+ return clients.Client {}, errors . Cast ( postgres .HandleError (repoerr .ErrUpdateEntity , Err ) )
308
310
}
309
311
defer row .Close ()
310
312
@@ -336,7 +338,7 @@ type DBClient struct {
336
338
Role * clients.Role `db:"role,omitempty"`
337
339
}
338
340
339
- func ToDBClient (c clients.Client ) (DBClient , error ) {
341
+ func ToDBClient (c clients.Client ) (DBClient , errors. Error ) {
340
342
data := []byte ("{}" )
341
343
if len (c .Metadata ) > 0 {
342
344
b , err := json .Marshal (c .Metadata )
@@ -346,8 +348,8 @@ func ToDBClient(c clients.Client) (DBClient, error) {
346
348
data = b
347
349
}
348
350
var tags pgtype.TextArray
349
- if err := tags .Set (c .Tags ); err != nil {
350
- return DBClient {}, err
351
+ if Err := tags .Set (c .Tags ); Err != nil {
352
+ return DBClient {}, errors . Cast ( Err )
351
353
}
352
354
var updatedBy * string
353
355
if c .UpdatedBy != "" {
@@ -374,7 +376,7 @@ func ToDBClient(c clients.Client) (DBClient, error) {
374
376
}, nil
375
377
}
376
378
377
- func ToClient (c DBClient ) (clients.Client , error ) {
379
+ func ToClient (c DBClient ) (clients.Client , errors. Error ) {
378
380
var metadata clients.Metadata
379
381
if c .Metadata != nil {
380
382
if err := json .Unmarshal ([]byte (c .Metadata ), & metadata ); err != nil {
@@ -415,7 +417,7 @@ func ToClient(c DBClient) (clients.Client, error) {
415
417
return cli , nil
416
418
}
417
419
418
- func ToDBClientsPage (pm clients.Page ) (dbClientsPage , error ) {
420
+ func ToDBClientsPage (pm clients.Page ) (dbClientsPage , errors. Error ) {
419
421
_ , data , err := postgres .CreateMetadataQuery ("" , pm .Metadata )
420
422
if err != nil {
421
423
return dbClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
@@ -448,7 +450,7 @@ type dbClientsPage struct {
448
450
Role clients.Role `db:"role"`
449
451
}
450
452
451
- func PageQuery (pm clients.Page ) (string , error ) {
453
+ func PageQuery (pm clients.Page ) (string , errors. Error ) {
452
454
mq , _ , err := postgres .CreateMetadataQuery ("" , pm .Metadata )
453
455
if err != nil {
454
456
return "" , errors .Wrap (errors .ErrMalformedEntity , err )
0 commit comments