@@ -15,7 +15,7 @@ import (
1515)
1616
1717// AddUser to save user information in database
18- func (p * provider ) AddUser (user models.User ) (models.User , error ) {
18+ func (p * provider ) AddUser (ctx context. Context , user models.User ) (models.User , error ) {
1919 if user .ID == "" {
2020 user .ID = uuid .New ().String ()
2121 }
@@ -30,8 +30,8 @@ func (p *provider) AddUser(user models.User) (models.User, error) {
3030
3131 user .CreatedAt = time .Now ().Unix ()
3232 user .UpdatedAt = time .Now ().Unix ()
33- userCollection , _ := p .db .Collection (nil , models .Collections .User )
34- meta , err := userCollection .CreateDocument (arangoDriver .WithOverwrite (nil ), user )
33+ userCollection , _ := p .db .Collection (ctx , models .Collections .User )
34+ meta , err := userCollection .CreateDocument (arangoDriver .WithOverwrite (ctx ), user )
3535 if err != nil {
3636 return user , err
3737 }
@@ -42,10 +42,10 @@ func (p *provider) AddUser(user models.User) (models.User, error) {
4242}
4343
4444// UpdateUser to update user information in database
45- func (p * provider ) UpdateUser (user models.User ) (models.User , error ) {
45+ func (p * provider ) UpdateUser (ctx context. Context , user models.User ) (models.User , error ) {
4646 user .UpdatedAt = time .Now ().Unix ()
47- collection , _ := p .db .Collection (nil , models .Collections .User )
48- meta , err := collection .UpdateDocument (nil , user .Key , user )
47+ collection , _ := p .db .Collection (ctx , models .Collections .User )
48+ meta , err := collection .UpdateDocument (ctx , user .Key , user )
4949 if err != nil {
5050 return user , err
5151 }
@@ -56,9 +56,9 @@ func (p *provider) UpdateUser(user models.User) (models.User, error) {
5656}
5757
5858// DeleteUser to delete user information from database
59- func (p * provider ) DeleteUser (user models.User ) error {
60- collection , _ := p .db .Collection (nil , models .Collections .User )
61- _ , err := collection .RemoveDocument (nil , user .Key )
59+ func (p * provider ) DeleteUser (ctx context. Context , user models.User ) error {
60+ collection , _ := p .db .Collection (ctx , models .Collections .User )
61+ _ , err := collection .RemoveDocument (ctx , user .Key )
6262 if err != nil {
6363 return err
6464 }
@@ -67,13 +67,13 @@ func (p *provider) DeleteUser(user models.User) error {
6767}
6868
6969// ListUsers to get list of users from database
70- func (p * provider ) ListUsers (pagination model.Pagination ) (* model.Users , error ) {
70+ func (p * provider ) ListUsers (ctx context. Context , pagination model.Pagination ) (* model.Users , error ) {
7171 var users []* model.User
72- ctx := driver .WithQueryFullCount (context . Background () )
72+ sctx := driver .WithQueryFullCount (ctx )
7373
7474 query := fmt .Sprintf ("FOR d in %s SORT d.created_at DESC LIMIT %d, %d RETURN d" , models .Collections .User , pagination .Offset , pagination .Limit )
7575
76- cursor , err := p .db .Query (ctx , query , nil )
76+ cursor , err := p .db .Query (sctx , query , nil )
7777 if err != nil {
7878 return nil , err
7979 }
@@ -84,7 +84,7 @@ func (p *provider) ListUsers(pagination model.Pagination) (*model.Users, error)
8484
8585 for {
8686 var user models.User
87- meta , err := cursor .ReadDocument (nil , & user )
87+ meta , err := cursor .ReadDocument (ctx , & user )
8888
8989 if arangoDriver .IsNoMoreDocuments (err ) {
9090 break
@@ -104,15 +104,15 @@ func (p *provider) ListUsers(pagination model.Pagination) (*model.Users, error)
104104}
105105
106106// GetUserByEmail to get user information from database using email address
107- func (p * provider ) GetUserByEmail (email string ) (models.User , error ) {
107+ func (p * provider ) GetUserByEmail (ctx context. Context , email string ) (models.User , error ) {
108108 var user models.User
109109
110110 query := fmt .Sprintf ("FOR d in %s FILTER d.email == @email RETURN d" , models .Collections .User )
111111 bindVars := map [string ]interface {}{
112112 "email" : email ,
113113 }
114114
115- cursor , err := p .db .Query (nil , query , bindVars )
115+ cursor , err := p .db .Query (ctx , query , bindVars )
116116 if err != nil {
117117 return user , err
118118 }
@@ -125,7 +125,7 @@ func (p *provider) GetUserByEmail(email string) (models.User, error) {
125125 }
126126 break
127127 }
128- _ , err := cursor .ReadDocument (nil , & user )
128+ _ , err := cursor .ReadDocument (ctx , & user )
129129 if err != nil {
130130 return user , err
131131 }
@@ -135,15 +135,15 @@ func (p *provider) GetUserByEmail(email string) (models.User, error) {
135135}
136136
137137// GetUserByID to get user information from database using user ID
138- func (p * provider ) GetUserByID (id string ) (models.User , error ) {
138+ func (p * provider ) GetUserByID (ctx context. Context , id string ) (models.User , error ) {
139139 var user models.User
140140
141141 query := fmt .Sprintf ("FOR d in %s FILTER d._id == @id LIMIT 1 RETURN d" , models .Collections .User )
142142 bindVars := map [string ]interface {}{
143143 "id" : id ,
144144 }
145145
146- cursor , err := p .db .Query (nil , query , bindVars )
146+ cursor , err := p .db .Query (ctx , query , bindVars )
147147 if err != nil {
148148 return user , err
149149 }
@@ -156,7 +156,7 @@ func (p *provider) GetUserByID(id string) (models.User, error) {
156156 }
157157 break
158158 }
159- _ , err := cursor .ReadDocument (nil , & user )
159+ _ , err := cursor .ReadDocument (ctx , & user )
160160 if err != nil {
161161 return user , err
162162 }
0 commit comments