-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtypes.go
78 lines (65 loc) · 1.82 KB
/
types.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
package db
import (
"time"
"github.com/google/uuid"
)
type CreateUser struct {
Username string `json:"username" validate:"required,alphanum,min=3,max=30"`
Password string `json:"password" validate:"required"`
Name *string `json:"name" validate:"omitempty,max=128"`
}
func (u *CreateUser) IntoUser() User {
user := User{
Username: u.Username,
Name: u.Name,
}
user.SetPassword(u.Password)
return user
}
type CreateBook struct {
Name string `json:"name" validate:"required,max=80"`
Slug string `json:"slug" validate:"required,max=80,slug"`
IsPublic bool `json:"isPublic"`
}
func (b *CreateBook) IntoBook(ownerID uuid.UUID) Book {
return Book{
Name: b.Name,
Slug: b.Slug,
OwnerID: ownerID,
IsPublic: b.IsPublic,
}
}
type CreateNote struct {
Name string `json:"name" validate:"required,max=80"`
Slug string `json:"slug" validate:"required,max=80,slug"`
}
func (n *CreateNote) IntoNote(bookID uuid.UUID) Note {
return Note{
Name: n.Name,
Slug: n.Slug,
BookID: bookID,
}
}
type ValueWithSlug struct {
Value any `json:"value"`
Slug string `json:"slug"`
}
type UpdateUser struct {
UpdatedAt time.Time `json:"-"`
Name *string `json:"name" validate:"omitempty,max=128"`
}
type UpdateUserPassword struct {
ExistingPassword string `json:"existingPassword"`
NewPassword string `json:"newPassword"`
}
type UpdateBook struct {
UpdatedAt time.Time `json:"-"`
Name *string `json:"name,omitempty" validate:"omitempty,max=80"`
Slug *string `json:"slug,omitempty" validate:"omitempty,max=80,slug"`
IsPublic *bool `json:"isPublic,omitempty"`
}
type UpdateNote struct {
UpdatedAt time.Time `json:"-"`
Name *string `json:"name,omitempty" validate:"omitempty,max=80"`
Slug *string `json:"slug,omitempty" validate:"omitempty,max=80,slug"`
}