52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// Photo table.
|
|
type Photo struct {
|
|
ID uint64 `gorm:"primaryKey"`
|
|
UserID uint64 `gorm:"index"`
|
|
Filename string
|
|
CroppedFilename string // if cropped, e.g. for profile photo
|
|
Filesize int64
|
|
Caption string
|
|
Flagged bool // photo has been reported by the community
|
|
Visibility PhotoVisibility
|
|
Gallery bool // photo appears in the public gallery (if public)
|
|
Explicit bool // is an explicit photo
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
// PhotoVisibility settings.
|
|
type PhotoVisibility string
|
|
|
|
const (
|
|
PhotoPublic PhotoVisibility = "public" // on profile page and/or public gallery
|
|
PhotoFriends = "friends" // only friends can see it
|
|
PhotoPrivate = "private" // private
|
|
)
|
|
|
|
// CreatePhoto with most of the settings you want (not ID or timestamps) in the database.
|
|
func CreatePhoto(tmpl Photo) (*Photo, error) {
|
|
if tmpl.UserID == 0 {
|
|
return nil, errors.New("UserID required")
|
|
}
|
|
|
|
p := &Photo{
|
|
UserID: tmpl.UserID,
|
|
Filename: tmpl.Filename,
|
|
CroppedFilename: tmpl.CroppedFilename,
|
|
Caption: tmpl.Caption,
|
|
Visibility: tmpl.Visibility,
|
|
Gallery: tmpl.Gallery,
|
|
Explicit: tmpl.Explicit,
|
|
}
|
|
|
|
result := DB.Create(p)
|
|
return p, result.Error
|
|
}
|