/
link.go
59 lines (50 loc) · 1.89 KB
/
link.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
package models
import (
"encoding/json"
"time"
"github.com/gobuffalo/pop"
"github.com/gobuffalo/pop/nulls"
"github.com/gobuffalo/uuid"
"github.com/gobuffalo/validate"
"github.com/gobuffalo/validate/validators"
)
type Link struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
Name string `json:"name" db:"name"`
Url string `json:"url" db:"url"`
Description nulls.String `json:"description" db:"description"`
UserID uuid.UUID `json:"user_id" db:"user_id"`
UpdatedBy uuid.UUID `json:"updated_by" db:"updated_by"`
}
// String is not required by pop and may be deleted
func (l Link) String() string {
jl, _ := json.Marshal(l)
return string(jl)
}
// Links is not required by pop and may be deleted
type Links []Link
// String is not required by pop and may be deleted
func (l Links) String() string {
jl, _ := json.Marshal(l)
return string(jl)
}
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
// This method is not required and may be deleted.
func (l *Link) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.StringIsPresent{Field: l.Name, Name: "Name"},
&validators.StringIsPresent{Field: l.Url, Name: "Url"},
), nil
}
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
// This method is not required and may be deleted.
func (l *Link) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
return validate.NewErrors(), nil
}
// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
// This method is not required and may be deleted.
func (l *Link) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
return validate.NewErrors(), nil
}