53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.trj.tw/golang/utils/dbtool"
|
|
)
|
|
|
|
// Photo model
|
|
type Photo struct {
|
|
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"`
|
|
}
|
|
|
|
// 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 -
|
|
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)
|
|
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
|
|
}
|