Adding GetAlbum method and unite tests
Signed-off-by: Kris Nóva <kris@nivenly.com>main
parent
0476727633
commit
6b742a1db4
|
@ -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
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/kris-nova/logger"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -40,6 +41,17 @@ type V1Response struct {
|
||||||
Body []byte
|
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 {
|
func (r *V1Response) JSON(i interface{}) error {
|
||||||
if r.Error != nil {
|
if r.Error != nil {
|
||||||
// Handle errors from the HTTP request first
|
// Handle errors from the HTTP request first
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
photoprism "github.com/kris-nova/client-go"
|
photoprism "github.com/kris-nova/client-go"
|
||||||
"github.com/kris-nova/logger"
|
"github.com/kris-nova/logger"
|
||||||
)
|
)
|
||||||
|
@ -16,6 +17,7 @@ func main() {
|
||||||
logger.Level = 4
|
logger.Level = 4
|
||||||
//
|
//
|
||||||
// ---
|
// ---
|
||||||
|
uuid := "aqnzih81icziiyae"
|
||||||
|
|
||||||
client := photoprism.New("http://localhost:8080")
|
client := photoprism.New("http://localhost:8080")
|
||||||
err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy"))
|
err := client.Auth(photoprism.NewClientAuthLogin("admin", "missy"))
|
||||||
|
@ -24,6 +26,7 @@ func main() {
|
||||||
}
|
}
|
||||||
logger.Always("Logged in...")
|
logger.Always("Logged in...")
|
||||||
|
|
||||||
|
album, err := client.V1().GetAlbum(uuid)
|
||||||
|
fmt.Println(album)
|
||||||
|
|
||||||
}
|
}
|
|
@ -40,7 +40,7 @@ func SaveAlbumAsYaml(a entity.Album) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/v1/albums
|
// GET /api/v1/albums/:uuid
|
||||||
func GetAlbums(router *gin.RouterGroup) {
|
func GetAlbums(router *gin.RouterGroup) {
|
||||||
router.GET("/albums", func(c *gin.Context) {
|
router.GET("/albums", func(c *gin.Context) {
|
||||||
s := Auth(SessionID(c), acl.ResourceAlbums, acl.ActionSearch)
|
s := Auth(SessionID(c), acl.ResourceAlbums, acl.ActionSearch)
|
||||||
|
|
|
@ -39,6 +39,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613501612939596202
|
"expiration": 1613501612939596202
|
||||||
},
|
},
|
||||||
|
"0f257f1b73a31dbb0cf7209bfdf46c02094f99da64e21e05": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613684753597482209
|
||||||
|
},
|
||||||
"0f58fcf81fdef7038db70a777b7eef0eee21ec715fdd3eb2": {
|
"0f58fcf81fdef7038db70a777b7eef0eee21ec715fdd3eb2": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -59,6 +64,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613522078076464014
|
"expiration": 1613522078076464014
|
||||||
},
|
},
|
||||||
|
"1df4c9db0a9092076596fb78727d069689c4b3083372a1fe": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613683482108919987
|
||||||
|
},
|
||||||
"21a2853a53625574889c1b0d653170efaf3ba51489c3da85": {
|
"21a2853a53625574889c1b0d653170efaf3ba51489c3da85": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -164,6 +174,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613509579377741749
|
"expiration": 1613509579377741749
|
||||||
},
|
},
|
||||||
|
"4b390db50d53378cfd6e3e3b08aa2a02b1df8fdcf1bda5c5": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613683106227931942
|
||||||
|
},
|
||||||
"5225f5600acaefec701d3ab1f3cfe2cf4b10ad025f2bf58e": {
|
"5225f5600acaefec701d3ab1f3cfe2cf4b10ad025f2bf58e": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -209,6 +224,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613502943460686773
|
"expiration": 1613502943460686773
|
||||||
},
|
},
|
||||||
|
"7a22f182d99dad428cc639c1c132060a7aaedb2dfdadf260": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613684752546409992
|
||||||
|
},
|
||||||
"7a82ce501006461a4fe1f69fca24f0a4ccdb716b47fe735e": {
|
"7a82ce501006461a4fe1f69fca24f0a4ccdb716b47fe735e": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -259,6 +279,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613513997238837821
|
"expiration": 1613513997238837821
|
||||||
},
|
},
|
||||||
|
"8df748d6cb902b922dbd7c86dfe1a176ed5ab77d8f6f6397": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613682894304104797
|
||||||
|
},
|
||||||
"910c4f6a3943e402e338511b235f43f8728d6f7e18b2c1b3": {
|
"910c4f6a3943e402e338511b235f43f8728d6f7e18b2c1b3": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -294,6 +319,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613526336803063121
|
"expiration": 1613526336803063121
|
||||||
},
|
},
|
||||||
|
"961077032ebb89103c4e200be0e7517242cbfd0cbb989afc": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613683429612623757
|
||||||
|
},
|
||||||
"988de1401f8dfe14a3766ea883ac54fa14dfd3149cefff6d": {
|
"988de1401f8dfe14a3766ea883ac54fa14dfd3149cefff6d": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -344,11 +374,21 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613529105851594272
|
"expiration": 1613529105851594272
|
||||||
},
|
},
|
||||||
|
"b03c0a0ffd4568804db70522319c1958aed2f46af39d1b5c": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613683163586189931
|
||||||
|
},
|
||||||
"b12bcc8e03f51a00b17584596a213e41f3cddb5b4b14a29a": {
|
"b12bcc8e03f51a00b17584596a213e41f3cddb5b4b14a29a": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613502660685792657
|
"expiration": 1613502660685792657
|
||||||
},
|
},
|
||||||
|
"b68ba2f95b38fcef5ccb7307406eef6e68b49ec779240e8d": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613683356092862862
|
||||||
|
},
|
||||||
"b796ead30cc71b1a7dc3865f5271f00061a7c81bf7805f5a": {
|
"b796ead30cc71b1a7dc3865f5271f00061a7c81bf7805f5a": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
@ -454,6 +494,11 @@
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
"expiration": 1613525903142014501
|
"expiration": 1613525903142014501
|
||||||
},
|
},
|
||||||
|
"fdbeb275182730c03ee00fc84da57dc080e60fb9d1dc587e": {
|
||||||
|
"user": "uqnzie01i1nypnt9",
|
||||||
|
"tokens": null,
|
||||||
|
"expiration": 1613682948079600558
|
||||||
|
},
|
||||||
"ff3f257a8a8d59834194117ec388228a6c2c4c799ffee9c6": {
|
"ff3f257a8a8d59834194117ec388228a6c2c4c799ffee9c6": {
|
||||||
"user": "uqnzie01i1nypnt9",
|
"user": "uqnzie01i1nypnt9",
|
||||||
"tokens": null,
|
"tokens": null,
|
||||||
|
|
Binary file not shown.
|
@ -3,7 +3,7 @@ UID: pqnzigq351j2fqgn
|
||||||
Type: image
|
Type: image
|
||||||
Title: A really great photo!
|
Title: A really great photo!
|
||||||
TitleSrc: manual
|
TitleSrc: manual
|
||||||
Description: 'Sample App Description: 2021-02-11 11:24:13.252619614 -0800 PST m=+6.238053352'
|
Description: 'Sample App Description: 2021-02-11 13:45:52.564527024 -0800 PST m=+1.150507976'
|
||||||
DescriptionSrc: manual
|
DescriptionSrc: manual
|
||||||
OriginalName: IMG_3044
|
OriginalName: IMG_3044
|
||||||
Year: -1
|
Year: -1
|
||||||
|
@ -13,5 +13,5 @@ Details:
|
||||||
Keywords: green, tambourine
|
Keywords: green, tambourine
|
||||||
KeywordsSrc: manual
|
KeywordsSrc: manual
|
||||||
CreatedAt: 2021-02-04T03:17:14.613092062Z
|
CreatedAt: 2021-02-04T03:17:14.613092062Z
|
||||||
UpdatedAt: 2021-02-11T19:46:41.863716035Z
|
UpdatedAt: 2021-02-11T21:45:52.568675691Z
|
||||||
EditedAt: 2021-02-11T19:24:13Z
|
EditedAt: 2021-02-11T21:45:53Z
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHappyGetAlbum(t *testing.T) {
|
||||||
|
_, err := Client.V1().GetAlbum(WellKnownAlbumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected success getting well known album: %v", err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSadGetAlbum(t *testing.T) {
|
||||||
|
album, err := Client.V1().GetAlbum(UnknownAlbumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("success returning error for unknown album: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Errorf("expected error for unknown album: %d", album.ID)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
|
@ -18,6 +18,8 @@ const (
|
||||||
BadPassword = "charlie"
|
BadPassword = "charlie"
|
||||||
WellKnownPhotoID = "pqnzigq351j2fqgn" // This is a photo in the persistent sample app
|
WellKnownPhotoID = "pqnzigq351j2fqgn" // This is a photo in the persistent sample app
|
||||||
UnknownPhotoID = "1234567890"
|
UnknownPhotoID = "1234567890"
|
||||||
|
WellKnownAlbumID = "aqnzih81icziiyae"
|
||||||
|
UnknownAlbumID = "1234567890"
|
||||||
WellKnownSampleAppConnectionString = "http://localhost:8080"
|
WellKnownSampleAppConnectionString = "http://localhost:8080"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ func TestMain(m *testing.M) {
|
||||||
logger.Always("Success!")
|
logger.Always("Success!")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
}else {
|
} else {
|
||||||
logger.Always("Photoprism already running...")
|
logger.Always("Photoprism already running...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue