From 6b742a1db4d785348659aca9e4f6aa247631b794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kris=20N=C3=B3va?= Date: Thu, 11 Feb 2021 13:46:28 -0800 Subject: [PATCH] Adding GetAlbum method and unite tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kris NĂ³va --- api/v1/album.go | 11 +++++ api/v1/client.go | 12 +++++ examples/{list.go => album.go} | 5 +- internal/api/album.go | 2 +- .../photoprism/storage/cache/sessions.json | 45 ++++++++++++++++++ sample-app/photoprism/storage/index.db | Bin 425984 -> 425984 bytes .../2021/02/20210204_031706_5B740007.yml | 6 +-- test/album_test.go | 23 +++++++++ test/main_test.go | 4 +- 9 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 api/v1/album.go rename examples/{list.go => album.go} (83%) create mode 100644 test/album_test.go diff --git a/api/v1/album.go b/api/v1/album.go new file mode 100644 index 0000000..74d4cbc --- /dev/null +++ b/api/v1/album.go @@ -0,0 +1,11 @@ +package api + +// GET /api/v1/albums +func (v1 *V1Client) GetAlbum(uuid string) (Album, error) { + album := Album{} + + // NOTE: Even though this method is singular GetAlbum + // if will call the "albums" plural endpoint. + err := v1.GET("/api/v1/albums/%s", uuid).JSON(&album) + return album, err +} \ No newline at end of file diff --git a/api/v1/client.go b/api/v1/client.go index a2dd454..49d1d15 100644 --- a/api/v1/client.go +++ b/api/v1/client.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/kris-nova/logger" "io/ioutil" "net/http" "net/url" @@ -40,6 +41,17 @@ type V1Response struct { Body []byte } +// String is used to represent the body of the response as a string. +func (r *V1Response) String() string { + if r.Error != nil { + // Handle errors from the HTTP request first + logger.Warning("during HTTP request: %v", r.Error) + return "{}" + } + return string(r.Body) +} + +// JSON will unmarshal onto whatever interface is passed in. func (r *V1Response) JSON(i interface{}) error { if r.Error != nil { // Handle errors from the HTTP request first diff --git a/examples/list.go b/examples/album.go similarity index 83% rename from examples/list.go rename to examples/album.go index 43076b5..6457136 100644 --- a/examples/list.go +++ b/examples/album.go @@ -1,6 +1,7 @@ package main import ( + "fmt" photoprism "github.com/kris-nova/client-go" "github.com/kris-nova/logger" ) @@ -16,6 +17,7 @@ func main() { logger.Level = 4 // // --- + uuid := "aqnzih81icziiyae" client := photoprism.New("http://localhost:8080") err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy")) @@ -24,6 +26,7 @@ func main() { } logger.Always("Logged in...") - + album, err := client.V1().GetAlbum(uuid) + fmt.Println(album) } diff --git a/internal/api/album.go b/internal/api/album.go index 02abd18..5ae3f86 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -40,7 +40,7 @@ func SaveAlbumAsYaml(a entity.Album) { } } -// GET /api/v1/albums +// GET /api/v1/albums/:uuid func GetAlbums(router *gin.RouterGroup) { router.GET("/albums", func(c *gin.Context) { s := Auth(SessionID(c), acl.ResourceAlbums, acl.ActionSearch) diff --git a/sample-app/photoprism/storage/cache/sessions.json b/sample-app/photoprism/storage/cache/sessions.json index 04a62a2..3de5ce1 100644 --- a/sample-app/photoprism/storage/cache/sessions.json +++ b/sample-app/photoprism/storage/cache/sessions.json @@ -39,6 +39,11 @@ "tokens": null, "expiration": 1613501612939596202 }, + "0f257f1b73a31dbb0cf7209bfdf46c02094f99da64e21e05": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613684753597482209 + }, "0f58fcf81fdef7038db70a777b7eef0eee21ec715fdd3eb2": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -59,6 +64,11 @@ "tokens": null, "expiration": 1613522078076464014 }, + "1df4c9db0a9092076596fb78727d069689c4b3083372a1fe": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683482108919987 + }, "21a2853a53625574889c1b0d653170efaf3ba51489c3da85": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -164,6 +174,11 @@ "tokens": null, "expiration": 1613509579377741749 }, + "4b390db50d53378cfd6e3e3b08aa2a02b1df8fdcf1bda5c5": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683106227931942 + }, "5225f5600acaefec701d3ab1f3cfe2cf4b10ad025f2bf58e": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -209,6 +224,11 @@ "tokens": null, "expiration": 1613502943460686773 }, + "7a22f182d99dad428cc639c1c132060a7aaedb2dfdadf260": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613684752546409992 + }, "7a82ce501006461a4fe1f69fca24f0a4ccdb716b47fe735e": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -259,6 +279,11 @@ "tokens": null, "expiration": 1613513997238837821 }, + "8df748d6cb902b922dbd7c86dfe1a176ed5ab77d8f6f6397": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613682894304104797 + }, "910c4f6a3943e402e338511b235f43f8728d6f7e18b2c1b3": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -294,6 +319,11 @@ "tokens": null, "expiration": 1613526336803063121 }, + "961077032ebb89103c4e200be0e7517242cbfd0cbb989afc": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683429612623757 + }, "988de1401f8dfe14a3766ea883ac54fa14dfd3149cefff6d": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -344,11 +374,21 @@ "tokens": null, "expiration": 1613529105851594272 }, + "b03c0a0ffd4568804db70522319c1958aed2f46af39d1b5c": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683163586189931 + }, "b12bcc8e03f51a00b17584596a213e41f3cddb5b4b14a29a": { "user": "uqnzie01i1nypnt9", "tokens": null, "expiration": 1613502660685792657 }, + "b68ba2f95b38fcef5ccb7307406eef6e68b49ec779240e8d": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613683356092862862 + }, "b796ead30cc71b1a7dc3865f5271f00061a7c81bf7805f5a": { "user": "uqnzie01i1nypnt9", "tokens": null, @@ -454,6 +494,11 @@ "tokens": null, "expiration": 1613525903142014501 }, + "fdbeb275182730c03ee00fc84da57dc080e60fb9d1dc587e": { + "user": "uqnzie01i1nypnt9", + "tokens": null, + "expiration": 1613682948079600558 + }, "ff3f257a8a8d59834194117ec388228a6c2c4c799ffee9c6": { "user": "uqnzie01i1nypnt9", "tokens": null, diff --git a/sample-app/photoprism/storage/index.db b/sample-app/photoprism/storage/index.db index 47fb180e6435d0b06fd611ce122b7fc5017d02b4..eaab8c448b372a3cccdbd3dc4147040a2e286c89 100644 GIT binary patch delta 226 zcmZo@kZNdiaH5Pe;tqF{ZZ-tButxQa$25jrB||4UJ69OpML9E5@OLAm{*#ZGyUOv7WwJCdstkx v5H2#aFf%tbvozE;Ft9Q(FfuSQ)HN{DML1;o!o4ht?Q{3AY@fS_HTf_Am6Aac delta 211 zcmZo@kZNdQxkb8(m(nOIm_nwzyxe#;2NOxq{FWfm)7 z;;^4SH=ae6!_ZK{(9+7pbn=FE64O7#vd9B9vGAE%85`qM&PFVPK#T5FDbAYpZRhXJl*v)?k#Im{*#ZGyUOv7WwJC zdstjS4pA^OHa9dgFgDdTFt9Q(FfuSQ)HN{Dh1d@=c>2P