/
abstract.go
71 lines (60 loc) · 2.42 KB
/
abstract.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
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 Abstract 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"`
UserID uuid.UUID `json:"user_id" db:"user_id"`
UpdatedBy uuid.UUID `json:"updated_by" db:"updated_by"`
Title string `json:"title" db:"title"`
OneSentenceDescription nulls.String `json:"one_sentence_description" db:"one_sentence_description"`
ShortDescription nulls.String `json:"short_description" db:"short_description"`
Abstract string `json:"abstract" db:"abstract"`
TalkType nulls.String `json:"talk_type" db:"talk_type"`
}
// SelectLabel - label for select tag options
func (a Abstract) SelectLabel() string {
return a.Title
}
// SelectValue - value for select tag options
func (a Abstract) SelectValue() interface{} {
return a.ID
}
// String is not required by pop and may be deleted
func (a Abstract) String() string {
ja, _ := json.Marshal(a)
return string(ja)
}
// Abstracts is not required by pop and may be deleted
type Abstracts []Abstract
// String is not required by pop and may be deleted
func (a Abstracts) String() string {
ja, _ := json.Marshal(a)
return string(ja)
}
// 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 (a *Abstract) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.StringIsPresent{Field: a.Title, Name: "Title"},
&validators.StringIsPresent{Field: a.Abstract, Name: "Abstract"},
), nil
}
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
// This method is not required and may be deleted.
func (a *Abstract) 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 (a *Abstract) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
return validate.NewErrors(), nil
}