Adding initial album feature work

Signed-off-by: Kris Nóva <kris@nivenly.com>
main
Kris Nóva 2021-02-11 15:32:03 -08:00
parent 06fff46e43
commit 6436478402
18 changed files with 346 additions and 18 deletions

View File

@ -1,5 +1,7 @@
package api
import "fmt"
type AlbumOptions struct {
ParamType string
Q string
@ -57,3 +59,83 @@ func (v1 *V1Client) GetAlbum(uuid string) (Album, error) {
err := v1.GET("/api/v1/albums/%s", uuid).JSON(&album)
return album, err
}
// CreateAlbum is used to create a new Album.
//
// CreateAlbum will default to sane values
// such that an empty Album{} object will still
// create a new album.
//
//POST /api/v1/albums
func (v1 *V1Client) CreateAlbum(object Album) (Album, error) {
err := v1.POST(&object, "/api/v1/albums").JSON(&object)
return object, err
}
// PUT /api/v1/albums/:uid
func (v1 *V1Client) UpdateAlbum(object Album) (Album, error) {
if object.AlbumUID == "" {
return object, fmt.Errorf("missing album.AlbumUID in album")
}
err := v1.PUT(&object, "/api/v1/albums/%s", object.AlbumUID).JSON(&object)
return object, err
}
// POST /api/v1/batch/albums/delete
func (v1 *V1Client) DeleteAlbums(uuids []string) error {
payload := struct {
Albums []string `json:"albums"`
}{
Albums: uuids,
}
resp := v1.POST(payload, "/api/v1/batch/albums/delete")
return resp.Error
}
// POST /api/v1/albums/:uid/like
//
// Parameters:
// uid: string Album UID
func (v1 *V1Client) LikeAlbum(uuid string) error {
resp := v1.POST(nil, "/api/v1/albums/%s/like", uuid)
return resp.Error
}
// DELETE /api/v1/albums/:uid/like
//
// Parameters:
// uid: string Album UID
func (v1 *V1Client) DislikeAlbum(uuid string) error {
resp := v1.DELETE(nil, "/api/v1/albums/%s/like", uuid)
return resp.Error
}
// POST /api/v1/albums/:uid/clone
func (v1 *V1Client) CloneAlbums(object Album) (Album, error) {
if object.AlbumUID == "" {
return object, fmt.Errorf("missing album.AlbumUID in album")
}
newAlbum := Album{}
err := v1.POST(&object, "/api/v1/albums/%s/clone", object.AlbumUID).JSON(&newAlbum)
return newAlbum, err
}
// 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)
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)
return resp.Error
}
// GET /api/v1/albums/:uid/dl
func (v1 *V1Client) GetAlbumDownload(uuid string) ([]byte, error) {
// NOTE: Even though this method is singular GetAlbum
// if will call the "albums" plural endpoint.
resp := v1.GET("/api/v1/albums/%s", uuid)
return resp.Body, resp.Error
}

View File

@ -1,9 +1,8 @@
package main
import (
"fmt"
photoprism "github.com/kris-nova/client-go"
"github.com/kris-nova/client-go/api/v1"
"github.com/kris-nova/logger"
)
@ -18,7 +17,6 @@ func main() {
logger.Level = 4
//
// ---
uuid := "aqnzih81icziiyae"
client := photoprism.New("http://localhost:8080")
err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy"))
@ -27,18 +25,17 @@ func main() {
}
logger.Always("Logged in...")
album, err := client.V1().GetAlbum(uuid)
if err != nil {
halt(3, "Error getting album %s", uuid)
}
fmt.Println(album)
albums, err := client.V1().GetAlbums(nil)
if err != nil {
halt(2, "Error listing albums: %v", err)
}
for _, album := range albums {
fmt.Println(album)
album := api.Album{
AlbumTitle: "NovaAlbum",
}
newAlbum, err := client.V1().CreateAlbum(album)
if err != nil {
halt(2, "Error creating album: %v", err)
}
err = client.V1().DeleteAlbums([]string{newAlbum.AlbumUID})
if err != nil {
halt(1, "Error deleting album: %v", err)
}
}

View File

@ -0,0 +1,44 @@
package main
import (
"fmt"
photoprism "github.com/kris-nova/client-go"
"github.com/kris-nova/logger"
)
func main() {
// ---
// Log Level 4 (Most)
// Log Level 3
// Log Level 2
// Log Level 1
// Log Level 0 (Least)
//
logger.Level = 4
//
// ---
uuid := "aqnzih81icziiyae"
client := photoprism.New("http://localhost:8080")
err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy"))
if err != nil {
halt(4, "Error logging into API: %v", err)
}
logger.Always("Logged in...")
album, err := client.V1().GetAlbum(uuid)
if err != nil {
halt(3, "Error getting album %s", uuid)
}
fmt.Println(album)
albums, err := client.V1().GetAlbums(nil)
if err != nil {
halt(2, "Error listing albums: %v", err)
}
for _, album := range albums {
fmt.Println(album)
}
}

View File

@ -0,0 +1,9 @@
UID: aqoe01hgxpo1hjih
Slug: novaalbum
Type: album
Title: NovaAlbum
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:03:18Z
UpdatedAt: 2021-02-11T23:03:18Z
DeletedAt: 2021-02-11T23:14:45.771988424Z

View File

@ -0,0 +1,9 @@
UID: aqoe0941aw0wz0rj
Slug: testalbum
Type: album
Title: TestAlbum
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:07:53Z
UpdatedAt: 2021-02-11T23:07:53Z
DeletedAt: 2021-02-11T23:14:36.400063828Z

View File

@ -0,0 +1,9 @@
UID: aqoe0j0nog2wtd98
Slug: february-2021
Type: album
Title: February 2021
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:13:49Z
UpdatedAt: 2021-02-11T23:13:49Z
DeletedAt: 2021-02-11T23:14:30.637709439Z

View File

@ -0,0 +1,10 @@
UID: aqoe0o1v8rjprqy6
Slug: testalbum
Type: album
Title: TestAlbum
Description: An updated album description
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:16:49Z
UpdatedAt: 2021-02-11T23:16:49.091245891Z
DeletedAt: 2021-02-11T23:18:32.10184988Z

View File

@ -0,0 +1,9 @@
UID: aqoe0xu1149t43i3
Slug: testalbum
Type: album
Title: TestAlbum
Description: An updated album description
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:22:42Z
UpdatedAt: 2021-02-11T23:22:42.31692892Z

View File

@ -0,0 +1,10 @@
UID: aqoe0zl3h1wak08f
Slug: testalbum
Type: album
Title: TestAlbum
Description: An updated album description
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:23:46Z
UpdatedAt: 2021-02-11T23:23:45.864716162Z
DeletedAt: 2021-02-11T23:24:31.729202695Z

View File

@ -0,0 +1,9 @@
UID: aqoe1231tb94a48k
Slug: testalbum
Type: album
Title: TestAlbum
Description: An updated album description
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:25:16Z
UpdatedAt: 2021-02-11T23:25:15.61908592Z

View File

@ -0,0 +1,8 @@
UID: aqoe1981fbhzaou2
Slug: novaalbum
Type: album
Title: NovaAlbum
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:29:33Z
UpdatedAt: 2021-02-11T23:29:33Z

View File

@ -0,0 +1,8 @@
UID: aqoe1bw1ywyawhlb
Slug: novaalbum
Type: album
Title: NovaAlbum
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:31:08Z
UpdatedAt: 2021-02-11T23:31:08Z

View File

@ -0,0 +1,9 @@
UID: aqoe1cs1rrfaer9d
Slug: testalbum
Type: album
Title: TestAlbum
Description: An updated album description
Order: oldest
Country: zz
CreatedAt: 2021-02-11T23:31:41Z
UpdatedAt: 2021-02-11T23:31:40.791556222Z

View File

@ -24,6 +24,11 @@
"tokens": null,
"expiration": 1613523028656083744
},
"0bab87ab1e73344a73e4693465cfa7cd20bc3a448c11db72": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613691100770470924
},
"0bc03c7776136e860865c7cd2c30d6678e896805d0e0bba8": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -64,6 +69,11 @@
"tokens": null,
"expiration": 1613522078076464014
},
"1ba9c019aaf278b159770a919acc5d1583948c1a8de9a5b3": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690715601777218
},
"1c2319c0a31690d8c0d9c5bb857ce4b94f7bef2e3289ae4a": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -204,6 +214,11 @@
"tokens": null,
"expiration": 1613512362197250367
},
"542cf5000fd4adbc7d1b7d6f2919b3d73afcb4620784adb0": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690210163840938
},
"54f0731493c76d77c00d186f56ee6adc78e27bebd6b92ff3": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -239,6 +254,11 @@
"tokens": null,
"expiration": 1613512018478271866
},
"69a5ba6601a0b258d6437ec792376eb0401c31b03b786629": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613689397688309140
},
"6b00829c3aa13681213f90fd643a209949649ae88f4eb42f": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -274,6 +294,11 @@
"tokens": null,
"expiration": 1613513949594487106
},
"7f1f06b8c49a3a01e73aebdca48bfdeeaf88ef787d2aee26": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690716677589751
},
"81000ef1dad0e84ef593d3838fb4ccb28a409d60cfaa7ef7": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -299,6 +324,11 @@
"tokens": null,
"expiration": 1613517781243806242
},
"86acf10dff5dfab564a21f7b32c9ec566b4bd36e47eef949": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690562297926322
},
"86e47c8475bbab147dc714ca6ae10b2ea64471d20a74e248": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -329,6 +359,11 @@
"tokens": null,
"expiration": 1613682894304104797
},
"8e476122d25b0acc53f7c39d66c41dbd471cb4744f0a649d": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690626957554055
},
"910c4f6a3943e402e338511b235f43f8728d6f7e18b2c1b3": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -354,6 +389,11 @@
"tokens": null,
"expiration": 1613500880573233477
},
"9220029905f142122fd03387a4d05f8a87f4dd9ac232f2b9": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690625840353698
},
"9223b8bc874aa1b1242ecbfc768221a8cd9e888c305700d2": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -439,16 +479,31 @@
"tokens": null,
"expiration": 1613675188854967428
},
"b7effc2db3f4e76c1c89fcd722fafaee3677a78cf4a8a38f": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613691101882965054
},
"c053cc843cd5a58b6e7e4dfb0b896180734df58c6cf6ca88": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613528519484379600
},
"c27771d21e4c9ff2138ce837aa3ec1c17d878ee4ffb1c58d": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613689672561735257
},
"c3440286c8cf0b619ec0a5883a836115de84752c519f625c": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613525841223849602
},
"c441f23ff44d11d2f081ca17a69442b088f239589c22ee26": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690209070329699
},
"c558cccdd25917056e8b7b72a2a3e5f40215d707a6fac1aa": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -469,6 +524,11 @@
"tokens": null,
"expiration": 1613513847101926534
},
"cd761cc3f15466f29eb789f5909bf26757d15661710e778c": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690028972954078
},
"cf5e23f28813fe367d3e1a5de1fc066b76988cae3d14343d": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -479,6 +539,16 @@
"tokens": null,
"expiration": 1613675187685124347
},
"d5cc9946cfa1d25fe55d42bf32e95d3690c856eaf81b549e": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690972875693176
},
"d67b4bf0a826d445959290e5de933409b06a6f593b0c665c": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613691068036487540
},
"d86c17fdb63eb3ef0665cb91fe3b29e8d823dd04eed50bac": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -489,6 +559,11 @@
"tokens": null,
"expiration": 1613514267386702538
},
"da47e471e7e0a996446fc88475ebe001baf4fa0d727a83be": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613690563421338386
},
"dcd50767e8b3450a095c535963f521b3b52457d4bdcdb7c6": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
@ -499,6 +574,11 @@
"tokens": null,
"expiration": 1613511459136720858
},
"e435fcbb9a19b7f4108d793705366ef9150d368b318787e4": {
"user": "uqnzie01i1nypnt9",
"tokens": null,
"expiration": 1613689673738164054
},
"e8f29a4ea45aff82722b11d21754fc4adcb63d2671545e0c": {
"user": "uqnzie01i1nypnt9",
"tokens": null,

View File

@ -3,7 +3,7 @@ UID: pqnzigq351j2fqgn
Type: image
Title: A really great photo!
TitleSrc: manual
Description: 'Sample App Description: 2021-02-11 14:19:37.7961079 -0800 PST m=+6.239338909'
Description: 'Sample App Description: 2021-02-11 15:31:40.812509789 -0800 PST m=+1.281183587'
DescriptionSrc: manual
OriginalName: IMG_3044
Year: -1
@ -13,5 +13,5 @@ Details:
Keywords: green, tambourine
KeywordsSrc: manual
CreatedAt: 2021-02-04T03:17:14.613092062Z
UpdatedAt: 2021-02-11T22:19:37.804340087Z
EditedAt: 2021-02-11T22:19:38Z
UpdatedAt: 2021-02-11T23:31:40.821110735Z
EditedAt: 2021-02-11T23:31:41Z

View File

@ -65,3 +65,37 @@ func TestSadGetAlbums(t *testing.T) {
t.FailNow()
}
}
// TestHappyCreateUpdateDeleteAlbum
func TestHappyCreateUpdateDeleteAlbum(t *testing.T) {
album := api.Album{
AlbumTitle: WellKnownAlbumTitle,
}
newAlbum, err := Client.V1().CreateAlbum(album)
if err != nil {
t.Errorf("expected success creating album: %v", err)
t.FailNow()
}
newAlbum.AlbumDescription = "An updated album description"
newAlbum, err = Client.V1().UpdateAlbum(newAlbum)
if err != nil {
t.Errorf("unable to update test album: %v", err)
// Note: We do NOT FailNow() here because we want to clean up
}
err = Client.V1().DeleteAlbums([]string{newAlbum.AlbumUID})
if err != nil {
t.Errorf("expected delete album %s, album not deleted: %v", newAlbum.AlbumUID, err)
t.FailNow()
}
}
// LikeAlbum
// DislikeAlbum
// CloneAlbums
// AddPhotosToAlbum
// DeletePhotosFromAlbum
// GetAlbumDownload

View File

@ -22,6 +22,7 @@ const (
UnknownAlbumID = "1234567890"
WellKnownSampleAppConnectionString = "http://localhost:8080"
UnknownCategory = "Furries"
WellKnownAlbumTitle = "TestAlbum"
)
// Client is a pre-authenticated client that can be used