-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
100 lines (85 loc) · 2.28 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package admin
import (
"context"
pmbulbi "github.com/PMBULBI/types/schemas"
)
func (r *UserRepository) Fetch(ctx context.Context) (val []pmbulbi.Admin, err error) {
err = r.db.
WithContext(ctx).
Find(&val).
Error
return
}
func (r *UserRepository) GetById(ctx context.Context, id string) (val pmbulbi.Admin, err error) {
err = r.db.
WithContext(ctx).
Where("id_admin = ? ", id).
First(&val).
Error
return
}
func (r *UserRepository) Insert(ctx context.Context, val pmbulbi.Admin) (err error) {
err = r.db.
WithContext(ctx).
Create(&val).
Error
return
}
func (r *UserRepository) Update(ctx context.Context, id string, val pmbulbi.Admin) (err error) {
err = r.db.
WithContext(ctx).
Where("id_admin = ?", id).
Updates(&val).
Error
return
}
func (r *UserRepository) Delete(ctx context.Context, id string) (err error) {
err = r.db.
WithContext(ctx).
Where("id_admin = ?", id).
Delete(&pmbulbi.Admin{}).
Error
return
}
func (r *UserRepository) GetByEmailPass(ctx context.Context, email, password string) (data pmbulbi.Admin, err error) {
err = r.db.WithContext(ctx).
Where("email = ? AND password = ?", email, password).
First(&data).
Error
return
}
func (r *UserRepository) GetByPhoneNumPass(ctx context.Context, phoneNum, password string) (data pmbulbi.Admin, err error) {
err = r.db.WithContext(ctx).
Where("no_hp = ? AND password = ?", phoneNum, password).
First(&data).
Error
return
}
func (r *UserRepository) CheckUserExists(ctx context.Context, email, phoneNum string) (data pmbulbi.Admin, err error) {
err = r.db.WithContext(ctx).
Where("no_hp = ? AND password = ?", phoneNum, email).
First(&data).
Error
return
}
func (r *UserRepository) GetByEmailOrPhone(ctx context.Context, email, phoneNum string) (data pmbulbi.Admin, err error) {
data, err = r.GetByPhone(ctx, phoneNum)
if err != nil {
data, err = r.GetByEmail(ctx, email)
}
return
}
func (r *UserRepository) GetByPhone(ctx context.Context, phoneNum string) (data pmbulbi.Admin, err error) {
err = r.db.WithContext(ctx).
Where("no_hp = ?", phoneNum).
First(&data).
Error
return
}
func (r *UserRepository) GetByEmail(ctx context.Context, email string) (data pmbulbi.Admin, err error) {
err = r.db.WithContext(ctx).
Where("email = ?", email).
First(&data).
Error
return
}