-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
53 lines (47 loc) · 1.71 KB
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package konference
import (
"context"
"errors"
"time"
)
var (
ErrEmailAlreadyTaken = errors.New("the email is already taken")
ErrInvalidEmailAddress = errors.New("invalid email id")
ErrInvalidPassword = errors.New("invalid password")
ErrUserNotFound = errors.New("user not found")
)
// User type represents the User domain in the system.
type User struct {
ID uint `json:"id" gorm:"primarykey"`
Email string `json:"email" gorm:"unique"`
FirstName string `json:"firstName" gorm:"size:191"`
LastName string `json:"lastName" gorm:"size:191"`
Password string `json:"-" gorm:"size:255"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}
// NewUser creates a new user
func NewUser(email, firstName, lastName, password string) *User {
return &User{
Email: email,
FirstName: firstName,
LastName: lastName,
Password: password,
}
}
// UserRepository defines the methods to interact with the User storage.
type UserRepository interface {
Store(ctx context.Context, u *User) error
Update(ctx context.Context, u *User) error
FindById(ctx context.Context, id uint) (*User, error)
FindByEmail(ctx context.Context, email string) (*User, error)
}
// UserService defines the domain service methods for User domain.
type UserService interface {
// CreateUser creates a new user in the system.
CreateUser(ctx context.Context, email, firstName, lastName, plaintextPassword string) error
// Authenticate verifies the credentials and returns the associated user if they match.
Authenticate(ctx context.Context, email, password string) (*User, error)
// GetUserDetails returns the details of the user
GetUserDetails(ctx context.Context, userId uint) (*User, error)
}