-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
63 lines (54 loc) · 2.08 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
54
55
56
57
58
59
60
61
62
63
package domain
import (
"e-course/pkg/resp"
"time"
"gorm.io/gorm"
)
type User struct {
ID int64 `json:"id"`
Name string `json:"name"`
Password string `json:"-"`
Email string `json:"email"`
CodeVerified string `json:"-"`
EmailVerifiedAt *time.Time `json:"email_verified_at"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at"`
CreatedByID *int64 `json:"created_by" gorm:"column:created_by"`
CreatedBy *Admin `json:"-" gorm:"foreignKey:CreatedByID;references:ID"`
UpdatedByID *int64 `json:"updated_by" gorm:"column:updated_by"`
UpdatedBy *Admin `json:"-" gorm:"foreignKey:UpdatedByID;references:ID"`
}
type UserRepository interface {
FindAll(offset int, limit int) []User
FindOneByID(id int) (*User, *resp.ErrorResp)
FindByEmail(email string) (*User, *resp.ErrorResp)
FindOneByVerificationCode(email string) (*User, *resp.ErrorResp)
Create(u User) (*User, *resp.ErrorResp)
Update(u User) (*User, *resp.ErrorResp)
Delete(u User) *resp.ErrorResp
TotalCountUser() int64
}
type UserCreateRequestBody struct {
Name string `json:"name" binding:"required"`
Email string `json:"email" binding:"email"`
Password string `json:"password" binding:"required"`
CreatedBy *int64 `json:"created_by"`
}
type UserUpdateRequestBody struct {
Name *string `json:"name" `
Email *string `json:"email"`
Password *string `json:"password"`
EmailVerifiedAt *time.Time `json:"email_verified_at"`
UpdatedBy *int64 `json:"updated_by"`
}
type UserUsecase interface {
Create(data UserCreateRequestBody) (*User, *resp.ErrorResp)
FindByEmail(email string) (*User, *resp.ErrorResp)
FindOneByID(id int) (*User, *resp.ErrorResp)
FindAll(offset int, limit int) []User
FindOneByCodeVerified(codeVerified string) (*User, *resp.ErrorResp)
Delete(id int) *resp.ErrorResp
TotalCountUser() int64
UpdatePassword(id int, data UserUpdateRequestBody) (*User, *resp.ErrorResp)
}