go-gallery/models/photo.go

53 lines
1.1 KiB
Go
Raw Normal View History

2018-04-17 09:16:03 +00:00
package models
2018-04-30 02:13:01 +00:00
import (
"time"
"git.trj.tw/golang/utils/dbtool"
)
2018-04-17 09:16:03 +00:00
// Photo model
type Photo struct {
2018-04-25 07:50:45 +00:00
ID string `sql:"id" cc:"id"`
Album string `sql:"album" cc:"album"`
Name string `sql:"name" cc:"name"`
Thumbnail string `sql:"thumbnail" cc:"thumbnail"`
Ctime time.Time `sql:"ctime" cc:"ctime"`
Mtime time.Time `sql:"mtime" cc:"mtime"`
2018-04-17 09:16:03 +00:00
}
2018-04-30 02:13:01 +00:00
// GetPhotos -
func GetPhotos(album string) (photo []Photo, err error) {
rows, err := x.Query(`select "id", "album", "name", "thumbnail", "ctime", "mtime" from "storage"."photo" where "album" = $1`, album)
if err != nil {
return nil, err
}
err = dbtool.ScanToStructAll(rows, &photo)
if err != nil {
return nil, err
}
return
}
// GetPhoto -
2018-05-25 09:26:29 +00:00
func GetPhoto(album, id string) (photo *Photo, err error) {
rows, err := x.Query(`select "id", "album", "name", "thumbnail", "ctime", "mtime" from "storage"."photo" where "album" = $1 and "id" = $2`, album, id)
2018-04-30 02:13:01 +00:00
if err != nil {
return nil, err
}
photo = &Photo{}
ok, err := dbtool.ScanToStruct(rows, photo)
if err != nil {
return nil, err
}
if !ok {
return nil, nil
}
return
}