@@ -24,7 +24,7 @@ type Repository struct {
2424 DB postgres.Database
2525}
2626
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 ) {
2828 var query []string
2929 var upq string
3030 if client .Name != "" {
@@ -45,47 +45,48 @@ func (repo *Repository) Update(ctx context.Context, client clients.Client) (clie
4545 return repo .update (ctx , client , q )
4646}
4747
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 ) {
4949 q := `UPDATE clients SET tags = :tags, updated_at = :updated_at, updated_by = :updated_by
5050 WHERE id = :id AND status = :status
5151 RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
5252 client .Status = clients .EnabledStatus
5353 return repo .update (ctx , client , q )
5454}
5555
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 ) {
5757 q := `UPDATE clients SET identity = :identity, updated_at = :updated_at, updated_by = :updated_by
5858 WHERE id = :id AND status = :status
5959 RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
6060 client .Status = clients .EnabledStatus
6161 return repo .update (ctx , client , q )
6262}
6363
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 ) {
6565 q := `UPDATE clients SET secret = :secret, updated_at = :updated_at, updated_by = :updated_by
6666 WHERE id = :id AND status = :status
6767 RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
6868 client .Status = clients .EnabledStatus
6969 return repo .update (ctx , client , q )
7070}
7171
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 ) {
7373 q := `UPDATE clients SET role = :role, updated_at = :updated_at, updated_by = :updated_by
7474 WHERE id = :id AND status = :status
7575 RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, role, created_at, updated_at, updated_by`
7676 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 )
7879}
7980
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 ) {
8182 q := `UPDATE clients SET status = :status, updated_at = :updated_at, updated_by = :updated_by
8283 WHERE id = :id
8384 RETURNING id, name, tags, identity, metadata, COALESCE(domain_id, '') AS domain_id, status, created_at, updated_at, updated_by`
8485
8586 return repo .update (ctx , client , q )
8687}
8788
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 ) {
8990 q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status
9091 FROM clients WHERE id = :id`
9192
@@ -105,13 +106,14 @@ func (repo *Repository) RetrieveByID(ctx context.Context, id string) (clients.Cl
105106 return clients.Client {}, errors .Wrap (repoerr .ErrViewEntity , err )
106107 }
107108
108- return ToClient (dbc )
109+ cl , err := ToClient (dbc )
110+ return cl , errors .Cast (err )
109111 }
110112
111113 return clients.Client {}, repoerr .ErrNotFound
112114}
113115
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 ) {
115117 q := `SELECT id, name, tags, COALESCE(domain_id, '') AS domain_id, identity, secret, metadata, created_at, updated_at, updated_by, status
116118 FROM clients WHERE identity = :identity AND status = :status`
117119
@@ -122,7 +124,7 @@ func (repo *Repository) RetrieveByIdentity(ctx context.Context, identity string)
122124
123125 row , err := repo .DB .NamedQueryContext (ctx , q , dbc )
124126 if err != nil {
125- return clients.Client {}, postgres .HandleError (repoerr .ErrViewEntity , err )
127+ return clients.Client {}, errors . Cast ( postgres .HandleError (repoerr .ErrViewEntity , err ) )
126128 }
127129 defer row .Close ()
128130
@@ -138,7 +140,7 @@ func (repo *Repository) RetrieveByIdentity(ctx context.Context, identity string)
138140 return clients.Client {}, repoerr .ErrNotFound
139141}
140142
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 ) {
142144 query , err := PageQuery (pm )
143145 if err != nil {
144146 return clients.ClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
@@ -151,9 +153,9 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
151153 if err != nil {
152154 return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
153155 }
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 )
157159 }
158160 defer rows .Close ()
159161
@@ -173,9 +175,9 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
173175 }
174176 cq := fmt .Sprintf (`SELECT COUNT(*) FROM clients c %s;` , query )
175177
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 )
179181 }
180182
181183 page := clients.ClientsPage {
@@ -190,7 +192,7 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
190192 return page , nil
191193}
192194
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 ) {
194196 sq , tq := constructSearchQuery (pm )
195197
196198 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
200202 return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
201203 }
202204
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 )
206208 }
207209 defer rows .Close ()
208210
@@ -222,9 +224,9 @@ func (repo *Repository) RetrieveAllBasicInfo(ctx context.Context, pm clients.Pag
222224 }
223225
224226 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 )
228230 }
229231
230232 page := clients.ClientsPage {
@@ -239,7 +241,7 @@ func (repo *Repository) RetrieveAllBasicInfo(ctx context.Context, pm clients.Pag
239241 return page , nil
240242}
241243
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 ) {
243245 if (len (pm .IDs ) == 0 ) && (pm .Domain == "" ) {
244246 return clients.ClientsPage {
245247 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) (
257259 if err != nil {
258260 return clients.ClientsPage {}, errors .Wrap (repoerr .ErrFailedToRetrieveAllGroups , err )
259261 }
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 )
263265 }
264266 defer rows .Close ()
265267
@@ -279,9 +281,9 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (
279281 }
280282 cq := fmt .Sprintf (`SELECT COUNT(*) FROM clients c %s;` , query )
281283
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 )
285287 }
286288
287289 page := clients.ClientsPage {
@@ -296,15 +298,15 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (
296298 return page , nil
297299}
298300
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 ) {
300302 dbc , err := ToDBClient (client )
301303 if err != nil {
302304 return clients.Client {}, errors .Wrap (repoerr .ErrUpdateEntity , err )
303305 }
304306
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 ) )
308310 }
309311 defer row .Close ()
310312
@@ -336,7 +338,7 @@ type DBClient struct {
336338 Role * clients.Role `db:"role,omitempty"`
337339}
338340
339- func ToDBClient (c clients.Client ) (DBClient , error ) {
341+ func ToDBClient (c clients.Client ) (DBClient , errors. Error ) {
340342 data := []byte ("{}" )
341343 if len (c .Metadata ) > 0 {
342344 b , err := json .Marshal (c .Metadata )
@@ -346,8 +348,8 @@ func ToDBClient(c clients.Client) (DBClient, error) {
346348 data = b
347349 }
348350 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 )
351353 }
352354 var updatedBy * string
353355 if c .UpdatedBy != "" {
@@ -374,7 +376,7 @@ func ToDBClient(c clients.Client) (DBClient, error) {
374376 }, nil
375377}
376378
377- func ToClient (c DBClient ) (clients.Client , error ) {
379+ func ToClient (c DBClient ) (clients.Client , errors. Error ) {
378380 var metadata clients.Metadata
379381 if c .Metadata != nil {
380382 if err := json .Unmarshal ([]byte (c .Metadata ), & metadata ); err != nil {
@@ -415,7 +417,7 @@ func ToClient(c DBClient) (clients.Client, error) {
415417 return cli , nil
416418}
417419
418- func ToDBClientsPage (pm clients.Page ) (dbClientsPage , error ) {
420+ func ToDBClientsPage (pm clients.Page ) (dbClientsPage , errors. Error ) {
419421 _ , data , err := postgres .CreateMetadataQuery ("" , pm .Metadata )
420422 if err != nil {
421423 return dbClientsPage {}, errors .Wrap (repoerr .ErrViewEntity , err )
@@ -448,7 +450,7 @@ type dbClientsPage struct {
448450 Role clients.Role `db:"role"`
449451}
450452
451- func PageQuery (pm clients.Page ) (string , error ) {
453+ func PageQuery (pm clients.Page ) (string , errors. Error ) {
452454 mq , _ , err := postgres .CreateMetadataQuery ("" , pm .Metadata )
453455 if err != nil {
454456 return "" , errors .Wrap (errors .ErrMalformedEntity , err )
0 commit comments