-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtypes.go
78 lines (65 loc) · 2.06 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" minLength:"3" maxLength:"30" pattern:"[a-zA-Z0-9]+"`
Password string `json:"password"`
Name *string `json:"name" require:"false" maxLength:"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" required:"true" minLength:"1" maxLength:"80"`
Slug string `json:"slug" required:"true" minLength:"1" maxLength:"80" pattern:"[a-z0-9-]+"`
IsPublic bool `json:"isPublic,omitempty" default:"false"`
}
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" required:"true" minLength:"1" maxLength:"80"`
Slug string `json:"slug" required:"true" minLength:"1" maxLength:"80" pattern:"[a-z0-9-]+"`
}
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:"-" hidden:"true" readOnly:"true"`
Name *string `json:"name" require:"false" maxLength:"128"`
}
type UpdateUserPassword struct {
ExistingPassword string `json:"existingPassword"`
NewPassword string `json:"newPassword"`
}
type UpdateBook struct {
UpdatedAt time.Time `json:"-" hidden:"true" readOnly:"true"`
Name *string `json:"name,omitempty" minLength:"1" maxLength:"80"`
Slug *string `json:"slug,omitempty" minLength:"1" maxLength:"80" pattern:"[a-z0-9-]+"`
IsPublic *bool `json:"isPublic,omitempty"`
}
type UpdateNote struct {
UpdatedAt time.Time `json:"-" hidden:"true" readOnly:"true"`
Name *string `json:"name,omitempty" minLength:"1" maxLength:"80"`
Slug *string `json:"slug,omitempty" minLength:"1" maxLength:"80" pattern:"[a-z0-9-]+"`
}