Skip to content

Commit

Permalink
fix problem on repository package
Browse files Browse the repository at this point in the history
  • Loading branch information
ErfiDev committed Nov 30, 2021
1 parent a37a0ae commit f600e44
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 5 additions & 6 deletions repository/dbrepo/dbrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dbrepo
import (
"context"
"database/sql"
"errors"
"github.com/erfidev/hotel-web-app/config"
"github.com/erfidev/hotel-web-app/models"
"github.com/erfidev/hotel-web-app/repository"
Expand Down Expand Up @@ -228,7 +227,7 @@ func (psdb postgresDbRepo) GetUserById(id int) (models.User , error) {
return user , nil
}

func (psdb postgresDbRepo) Authenticate(email , password string) (bool , error) {
func (psdb postgresDbRepo) Authenticate(email , password string) (bool , string) {
ctx , cancel := context.WithTimeout(context.Background() , 3 * time.Second)
defer cancel()

Expand All @@ -243,18 +242,18 @@ func (psdb postgresDbRepo) Authenticate(email , password string) (bool , error)

err := row.Scan(&pass)
if err != nil {
return false , err
return false , "can't find user with this email!"
}

// check passwords
hashError := bcrypt.CompareHashAndPassword([]byte(pass) , []byte(password))
if hashError == bcrypt.ErrMismatchedHashAndPassword {
return false , errors.New("mismatched hash and password")
return false , "mismatched hash and password"
} else if hashError != nil {
return false , hashError
return false , "unexpected error"
}

return true , nil
return true , ""
}

func (psdb postgresDbRepo) UpdateUser(user models.User) (bool , error) {
Expand Down
16 changes: 16 additions & 0 deletions repository/dbrepo/test-db.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,20 @@ func (psdb testDbRepo) SearchAvailabilityForAllRooms(start , end time.Time) ([]m
func (psdb testDbRepo) FindRoomById(id int) (models.Room,error){
var room models.Room
return room , nil
}

func (psdb testDbRepo) InsertUser(user models.User) (bool , error) {
return true , nil
}

func (psdb testDbRepo) GetUserById(id int) (models.User , error) {
return models.User{} , nil
}

func (psdb testDbRepo) Authenticate(email , password string) (bool , string) {
return true , ""
}

func (psdb testDbRepo) UpdateUser(user models.User) (bool , error) {
return true , nil
}
2 changes: 1 addition & 1 deletion repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ type DatabaseRepository interface {
FindRoomById(id int) (models.Room,error)
InsertUser(user models.User) (bool , error)
GetUserById(id int) (models.User , error)
Authenticate(email , password string) (bool , error)
Authenticate(email , password string) (bool , string)
UpdateUser(user models.User) (bool , error)
}

0 comments on commit f600e44

Please sign in to comment.