API: Add composite id to photo search results

This commit is contained in:
Michael Mayer 2021-01-10 15:30:12 +01:00
parent b408538f68
commit 5eea2eac41
2 changed files with 3 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import (
// PhotoResult contains found photos and their main file plus other meta data.
type PhotoResult struct {
ID uint `json:"-"`
CompositeID string `json:"ID"`
UUID string `json:"DocumentID,omitempty"`
PhotoUID string `json:"UID"`
PhotoType string `json:"Type"`
@ -124,6 +125,7 @@ func (m PhotoResults) Merged() (PhotoResults, int, error) {
}
file.ID = res.FileID
res.CompositeID = fmt.Sprintf("%d-%d", res.ID, res.FileID)
if lastId == res.ID && i > 0 {
merged[i-1].Files = append(merged[i-1].Files, file)

View file

@ -27,7 +27,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
// Main search query, avoids (slow) left joins.
s = s.Table("photos").
Select(`photos.*,
Select(`photos.*, photos.id AS composite_id,
files.id AS file_id, files.file_uid, files.instance_id, files.file_primary, files.file_missing, files.file_name,
files.file_root, files.file_hash, files.file_codec, files.file_type, files.file_mime, files.file_width,
files.file_height, files.file_portrait, files.file_aspect_ratio, files.file_orientation, files.file_main_color,