-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtypes.go
55 lines (46 loc) · 1.3 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
package db
import "github.com/google/uuid"
type CreateUser struct {
Username string `json:"username" validate:"required,alphanum,min=3,max=30"`
Password string `json:"password" validate:"required"`
}
func (u *CreateUser) IntoUser() User {
user := User{
Username: u.Username,
}
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 UpdateBook struct {
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 {
Name *string `json:"name,omitempty" validate:"omitempty,max=80"`
Slug *string `json:"slug,omitempty" validate:"omitempty,max=80,slug"`
}