@@ -3,15 +3,14 @@ package user
33import (
44 "context"
55 "fmt"
6- "github.com/softwareplace/wireguard-api/pkg/domain/db"
76 "github.com/softwareplace/wireguard-api/pkg/models"
87 "github.com/softwareplace/wireguard-api/pkg/utils/date"
98 "go.mongodb.org/mongo-driver/bson"
109 "log"
1110)
1211
13- func (impl * usersRepositoryImpl ) Save (user models.User ) error {
14- collection := db . GetDB (). Collection ( "users" )
12+ func (r * usersRepositoryImpl ) Save (user models.User ) error {
13+ collection := r . collection ( )
1514
1615 nowToString := date .NowToString ()
1716 user .CreatedAt = nowToString
@@ -21,8 +20,8 @@ func (impl *usersRepositoryImpl) Save(user models.User) error {
2120 return err
2221}
2322
24- func (impl * usersRepositoryImpl ) Update (user models.User ) error {
25- collection := db . GetDB (). Collection ( "users" )
23+ func (r * usersRepositoryImpl ) Update (user models.User ) error {
24+ collection := r . collection ( )
2625 user .UpdatedAt = date .NowToString ()
2726
2827 filter := bson.M {"_id" : user .Id }
@@ -31,8 +30,8 @@ func (impl *usersRepositoryImpl) Update(user models.User) error {
3130 return err
3231}
3332
34- func (impl * usersRepositoryImpl ) FindUserBySalt (salt string ) (* models.User , error ) {
35- collection := db . GetDB (). Collection ( "users" )
33+ func (r * usersRepositoryImpl ) FindUserBySalt (salt string ) (* models.User , error ) {
34+ collection := r . collection ( )
3635 var currentUser models.User
3736
3837 err := collection .FindOne (context .Background (), map [string ]interface {}{
@@ -46,8 +45,8 @@ func (impl *usersRepositoryImpl) FindUserBySalt(salt string) (*models.User, erro
4645 return & currentUser , nil
4746}
4847
49- func (impl * usersRepositoryImpl ) FindUserByEmail (email string ) (* models.User , error ) {
50- collection := db . GetDB (). Collection ( "users" )
48+ func (r * usersRepositoryImpl ) FindUserByEmail (email string ) (* models.User , error ) {
49+ collection := r . collection ( )
5150 var user models.User
5251 err := collection .FindOne (context .Background (), map [string ]interface {}{
5352 "email" : email ,
@@ -58,8 +57,8 @@ func (impl *usersRepositoryImpl) FindUserByEmail(email string) (*models.User, er
5857 return & user , nil
5958}
6059
61- func (impl * usersRepositoryImpl ) FindUserByUsername (username string ) (* models.User , error ) {
62- collection := db . GetDB (). Collection ( "users" )
60+ func (r * usersRepositoryImpl ) FindUserByUsername (username string ) (* models.User , error ) {
61+ collection := r . collection ( )
6362 var user models.User
6463 err := collection .FindOne (context .Background (), map [string ]interface {}{
6564 "username" : username ,
@@ -70,14 +69,14 @@ func (impl *usersRepositoryImpl) FindUserByUsername(username string) (*models.Us
7069 return & user , nil
7170}
7271
73- func (impl * usersRepositoryImpl ) FindUserByUsernameOrEmail (username string , email string ) (* models.User , error ) {
72+ func (r * usersRepositoryImpl ) FindUserByUsernameOrEmail (username string , email string ) (* models.User , error ) {
7473 if username != "" {
75- return impl .FindUserByUsername (username )
74+ return r .FindUserByUsername (username )
7675
7776 }
7877
7978 if email != "" {
80- return impl .FindUserByEmail (email )
79+ return r .FindUserByEmail (email )
8180 }
8281
8382 return nil , fmt .Errorf ("username or email must be provided" )
0 commit comments