photoprism/internal/entity/marker_json.go
2021-09-05 17:10:52 +02:00

60 lines
1.2 KiB
Go

package entity
import (
"encoding/json"
"time"
)
// MarshalJSON returns the JSON encoding.
func (m *Marker) MarshalJSON() ([]byte, error) {
var subj *Subject
var name string
if subj = m.Subject(); subj == nil {
name = m.MarkerName
} else {
name = subj.SubjectName
}
return json.Marshal(&struct {
UID string
FileUID string
FileHash string
CropArea string
Type string
Src string
Name string
Invalid bool
Review bool
FaceID string
SubjectUID string
SubjectSrc string
X float32
Y float32
W float32 `json:",omitempty"`
H float32 `json:",omitempty"`
Size int `json:",omitempty"`
Score int `json:",omitempty"`
CreatedAt time.Time
}{
UID: m.MarkerUID,
FileUID: m.FileUID,
FileHash: m.FileHash,
CropArea: m.CropArea,
Type: m.MarkerType,
Src: m.MarkerSrc,
Name: name,
Invalid: m.MarkerInvalid,
Review: m.Review,
FaceID: m.FaceID,
SubjectUID: m.SubjectUID,
SubjectSrc: m.SubjectSrc,
X: m.X,
Y: m.Y,
W: m.W,
H: m.H,
Size: m.Size,
Score: m.Score,
CreatedAt: m.CreatedAt,
})
}