/
user.go
43 lines (35 loc) · 929 Bytes
/
user.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
package models
import (
"fmt"
"strings"
"github.com/jinzhu/gorm"
)
// User the user of our application
type User struct {
gorm.Model
Email string `gorm:"type:varchar(100);unique_index"`
Password string
Profile Profile
Posts []Post
}
// Profile the users profile
type Profile struct {
gorm.Model
UserID uint
NickName string `gorm:"size:128"`
FirstName string `gorm:"size:128"`
LastName string `gorm:"size:128"`
PhotoURL string `gorm:"size:2000"`
PublicEmail string `gorm:"size:256"`
Phone string `gorm:"size:30"`
Twitter string `gorm:"size:128"`
Github string `gorm:"size:128"`
Note string `gorm:"type:TEXT"`
}
// DisplayName returns either the nickname if it's not empty, or the First+Last Name
func (p *Profile) DisplayName() string {
if strings.TrimSpace(p.NickName) != "" {
return p.NickName
}
return fmt.Sprintf("%s %s", p.FirstName, p.LastName)
}