Initial commit
This commit is contained in:
commit
c0cb826917
63 changed files with 2069 additions and 0 deletions
42
internal/domain/entities/user.go
Normal file
42
internal/domain/entities/user.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package entities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const UserTable = "users"
|
||||
|
||||
type User struct {
|
||||
Id uuid.UUID `db:"id"`
|
||||
UserName string `db:"username"`
|
||||
Password string `db:"password"`
|
||||
}
|
||||
|
||||
func CreateUser(userName string, password string) (user User, err error) {
|
||||
user = User{
|
||||
Id: uuid.New(),
|
||||
UserName: userName,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
err = user.Validate()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (u *User) Validate() error {
|
||||
if err := uuid.Validate(u.Id.String()); err != nil {
|
||||
return errors.New("Invalid user.id")
|
||||
}
|
||||
if u.UserName == "" {
|
||||
return errors.New("Empty user.name")
|
||||
}
|
||||
|
||||
if u.Password == "" {
|
||||
return errors.New("Empty user.password")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue