-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
42 lines (37 loc) · 1.32 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
package xclone
import (
"context"
"errors"
"time"
)
var (
ErrUsernameTaken = errors.New("username taken")
ErrEmailTaken = errors.New("email taken")
ErrGenAccessToken = errors.New("generate access token error")
ErrNotFound = errors.New("not found")
ErrValidation = errors.New("validation error")
ErrBadCredentials = errors.New("email/password wrong combination")
ErrInvalidAccessToken = errors.New("invalid access token")
ErrNoUserIDInContext = errors.New("no user id in context")
ErrUnauthenticated = errors.New("unauthenticated")
ErrInvalidUUID = errors.New("invalid uuid")
ErrForbidden = errors.New("forbidden")
)
type UserRepo interface {
Create(ctx context.Context, user User) (User, error)
GetByUsername(ctx context.Context, username string) (User, error)
GetByEmail(ctx context.Context, email string) (User, error)
GetByID(ctx context.Context, id string) (User, error)
GetByIds(ctx context.Context, ids []string) ([]User, error)
}
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type UserService interface {
GetByID(ctx context.Context, id string) (User, error)
}