A lot of work with albums and photos, still working but want to save working tests/methods

Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
Kris Nóva 2021-02-11 17:16:37 -08:00
parent 6436478402
commit 194f0acb28
79 changed files with 1028 additions and 23 deletions

View file

@ -111,7 +111,7 @@ func (v1 *V1Client) DislikeAlbum(uuid string) error {
}
// POST /api/v1/albums/:uid/clone
func (v1 *V1Client) CloneAlbums(object Album) (Album, error) {
func (v1 *V1Client) CloneAlbum(object Album) (Album, error) {
if object.AlbumUID == "" {
return object, fmt.Errorf("missing album.AlbumUID in album")
}
@ -121,14 +121,24 @@ func (v1 *V1Client) CloneAlbums(object Album) (Album, error) {
}
// POST /api/v1/albums/:uid/photos
func (v1 *V1Client) AddPhotosToAlbum(albumUUID string, objects []Photo) error {
resp := v1.POST(&objects, "/api/v1/albums/%s/photos", albumUUID)
func (v1 *V1Client) AddPhotosToAlbum(albumUUID string, photoIDs []string) error {
payload := struct {
Photos []string `json:"photos"`
}{
Photos: photoIDs,
}
resp := v1.POST(&payload, "/api/v1/albums/%s/photos", albumUUID)
return resp.Error
}
// DELETE /api/v1/albums/:uid/photos
func (v1 *V1Client) DeletePhotosFromAlbum(albumUUID string, objects []Photo) error {
resp := v1.DELETE(&objects, "/api/v1/albums/%s/photos", albumUUID)
func (v1 *V1Client) DeletePhotosFromAlbum(albumUUID string, photoIDs []string) error {
payload := struct {
Photos []string `json:"photos"`
}{
Photos: photoIDs,
}
resp := v1.DELETE(&payload, "/api/v1/albums/%s/photos", albumUUID)
return resp.Error
}

View file

@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/kris-nova/logger"
"io/ioutil"
"net/http"
"net/url"
"strings"
"github.com/kris-nova/logger"
)
const (

13
api/v1/index.go Normal file
View file

@ -0,0 +1,13 @@
package api
// POST /api/v1/index
func (v1 *V1Client) Index() error {
resp := v1.POST(nil, "/api/v1/index")
return resp.Error
}
// DELETE /api/v1/index
func (v1 *V1Client) CancelIndex() error {
resp := v1.DELETE(nil, "/api/v1/index")
return resp.Error
}

View file

@ -1,7 +1,5 @@
package api
// GET /api/v1/photos/:uuid
//
// Parameters:
@ -14,6 +12,52 @@ func (v1 *V1Client) GetPhoto(uuid string) (Photo, error) {
return object, err
}
type PhotoOptions struct {
Count int
Offset int
AlbumUID string
Filter string
Merged bool
Country string
Camera int
Order string
Q string
}
const (
DefaultPhotoOptionsCount = 60
DefaultPhotoOptionsOffset = 0
DefaultPhotoOptionsMerged = true
DefaultPhotoOptionsCamera = 0
DefaultPhotoOptionsOrder = "oldest"
)
// GET /api/v1/photos/
//
// http://localhost:8080/api/v1/photos?
// count=60&offset=0&album=aqoe4m9204aigugh&filter=&merged=true&country=&camera=0&order=oldest&q=
func (v1 *V1Client) GetPhotos(options *PhotoOptions) ([]Photo, error) {
var photos []Photo
if options == nil {
options = &PhotoOptions{
Count: DefaultPhotoOptionsCount,
Offset: DefaultPhotoOptionsOffset,
Merged: DefaultPhotoOptionsMerged,
Order: DefaultPhotoOptionsOrder,
Camera: DefaultPhotoOptionsCamera,
}
}
if options.Count == 0 {
return photos, nil
}
if options.Order == "" {
options.Order = DefaultPhotoOptionsOrder
}
err := v1.GET("/api/v1/photos?count=%d&offset=%d&album=%s&filter=%s&merged=%t&country=%s&camera=%d&order=%s&q=%s",
options.Count, options.Offset, options.AlbumUID, options.Filter, options.Merged, options.Country, options.Camera, options.Order, options.Q).JSON(&photos)
return photos, err
}
// PUT /api/v1/photos/:uid
//
// Parameters:

View file

@ -5,10 +5,12 @@ import (
"time"
)
type Photos []Photo
// Photo represents a photo, all its properties, and link to all its images and sidecar files.
type Photo struct {
Meta
ID uint `gorm:"primary_key" yaml:"-"`
//ID uint `gorm:"primary_key" yaml:"-"`
UUID string `gorm:"type:VARBINARY(42);index;" json:"DocumentID,omitempty" yaml:"DocumentID,omitempty"`
TakenAt time.Time `gorm:"type:datetime;index:idx_photos_taken_uid;" json:"TakenAt" yaml:"TakenAt"`
TakenAtLocal time.Time `gorm:"type:datetime;" yaml:"-"`
@ -52,13 +54,13 @@ type Photo struct {
CameraSrc string `gorm:"type:VARBINARY(8);" json:"CameraSrc" yaml:"-"`
LensID uint `gorm:"index:idx_photos_camera_lens;default:1" json:"LensID" yaml:"-"`
Details *Details `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Details" yaml:"Details"`
Camera *Camera `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Camera" yaml:"-"`
Lens *Lens `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Lens" yaml:"-"`
Cell *Cell `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Cell" yaml:"-"`
Place *Place `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Place" yaml:"-"`
Keywords []Keyword `json:"-" yaml:"-"`
Albums []Album `json:"-" yaml:"-"`
Files []File `yaml:"-"`
Camera *Camera `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Camera" yaml:"-"`
Lens *Lens `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Lens" yaml:"-"`
Cell *Cell `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Cell" yaml:"-"`
Place *Place `gorm:"association_autoupdate:false;association_autocreate:false;association_save_reference:false" json:"Place" yaml:"-"`
Keywords []Keyword `json:"-" yaml:"-"`
Albums []Album `json:"-" yaml:"-"`
Files []File `yaml:"-"`
//Labels []PhotoLabel `yaml:"-"`
CreatedAt time.Time `yaml:"CreatedAt,omitempty"`
UpdatedAt time.Time `yaml:"UpdatedAt,omitempty"`
@ -193,7 +195,6 @@ type PhotoAlbum struct {
Album *Album `gorm:"PRELOAD:true" yaml:"-"`
}
// File represents an image or sidecar file that belongs to a photo.
type File struct {
ID uint `gorm:"primary_key" json:"-" yaml:"-"`
@ -267,7 +268,6 @@ type FileShare struct {
UpdatedAt time.Time
}
// PhotoLabel represents the many-to-many relation between Photo and label.
// Labels are weighted by uncertainty (100 - confidence)
type PhotoLabel struct {