-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Added user.SelectByUsername. Renamed 'users' package to 'user'
- Loading branch information
1 parent
4828186
commit 901f432
Showing
22 changed files
with
288 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package user | ||
|
||
import "time" | ||
|
||
// DAO represents a user | ||
type DAO struct { | ||
ID int `json:"id"` | ||
Username string `json:"username"` | ||
Password string `json:"password_hash"` | ||
CreatedAt time.Time `json:"created_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package user | ||
|
||
// DTO represents a user to be inserted into the 'user' table | ||
type DTO struct { | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package user | ||
|
||
import "errors" | ||
|
||
var ( | ||
FailedToInsertUser = errors.New("failed to insert user") | ||
FailedToRetrieveIfUserAlreadyExists = errors.New("failed to retrieve if user already exists") | ||
NoUserFoundForTheGivenUsername = errors.New("no user found for the given username") | ||
FailedExecuteQueryToRetrieveUser = errors.New("failed to execute query to retrieve user") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package user | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
// MockExists mocks Exists function | ||
func MockExists(userExists bool, err error) Exists { | ||
return func(ctx context.Context, username string) (bool, error) { | ||
return userExists, err | ||
} | ||
} | ||
|
||
// MockInsert mocks Insert function | ||
func MockInsert(err error) Insert { | ||
return func(ctx context.Context, user DTO) error { | ||
return err | ||
} | ||
} | ||
|
||
// MockDTO mocks user DTO | ||
func MockDTO() DTO { | ||
return DTO{ | ||
Username: "test@test.com", | ||
Password: "password", | ||
} | ||
} | ||
|
||
// MockDAO mocks user DAO | ||
func MockDAO() DAO { | ||
return DAO{ | ||
ID: 1, | ||
Username: "username", | ||
Password: "password", | ||
CreatedAt: time.Date(2006, time.January, 1, 0, 0, 0, 0, time.Local), | ||
} | ||
} | ||
|
||
// MockScanUserDAOValues mocks the properties of user DAO to be used in the Scan function | ||
func MockScanUserDAOValues(dao DAO) []any { | ||
return []any{ | ||
dao.ID, | ||
dao.Username, | ||
dao.Password, | ||
dao.CreatedAt, | ||
} | ||
} |
Oops, something went wrong.