-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
82 lines (71 loc) · 1.68 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
package repository
import (
"database/sql"
"github.com/TVBlackman1/telegram-go/pkg/lib/presenter/types"
"github.com/TVBlackman1/telegram-go/pkg/repository/utils"
"github.com/google/uuid"
)
type UserRepository interface {
Add(query CreateUserDto) (uuid.UUID, error)
Remove(interface{})
Edit(interface{})
GetList(query UserListQuery) UsersDbMetaDto
GetOne(query UserQuery) (UserDbDto, error)
SetNewStateUUID(userUUID uuid.UUID, stateUUID uuid.UUID) error
// TODO SetNewStateOnFly(state interface{}) error
}
type CreateUserDto struct {
Id uuid.UUID `db:"id"`
Name string `db:"name"`
Login string `db:"login"`
ChatId types.ChatId `db:"chat_id"`
StateId uuid.UUID `db:"state_id"`
}
type UserDbDto struct {
Id uuid.UUID
Name string
Login string
ChatId types.ChatId
StateId uuid.UUID
State StateDbDto
}
type UserDb struct {
Id uuid.UUID `db:"id"`
Name sql.NullString `db:"name"`
Login sql.NullString `db:"login"`
ChatId types.ChatId `db:"chat_id"`
StateId uuid.UUID `db:"state_id"`
State StateDbDto `db:"state"`
}
type UsersDbMetaDto struct {
Data []UserDbDto
Meta utils.Pagination
}
type UserListQuery struct {
Pagination utils.QueryPagination
Name string
State string
}
type UserQuery struct {
Login string
ChatId types.ChatId
}
const (
USERS_LIMIT = 30
USERS_TABLENAME = "users"
)
func UserDbToUserDbDto(userDb UserDb) UserDbDto {
user := UserDbDto{
Id: userDb.Id,
ChatId: userDb.ChatId,
StateId: userDb.StateId,
State: userDb.State,
}
if userDb.Name.Valid {
user.Name = userDb.Name.String
}
if userDb.Login.Valid {
user.Login = userDb.Login.String
}
return user
}