From 279697128df2049f98ca8ad12c390873e01fdb9b Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Mon, 30 Nov 2020 15:22:26 +0000 Subject: [PATCH] Update API endpoint to return objects --- services/ext/api.go | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/services/ext/api.go b/services/ext/api.go index 79c9386e1..a39ce5363 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -3,7 +3,6 @@ package ext import ( "context" "encoding/hex" - "encoding/json" "errors" "fmt" "math/big" @@ -590,47 +589,31 @@ func (api *PublicAPI) Echo(ctx context.Context, message string) (string, error) // // GetIdentityImages returns an array of json marshalled IdentityImages assigned to the user's identity -func (api *PublicAPI) GetIdentityImages(keyUID string) (string, error) { - iis, err := api.service.multiAccountsDB.GetIdentityImages(keyUID) - if err != nil { - return "", err - } - - js, err := json.Marshal(iis) - - return string(js), err +func (api *PublicAPI) GetIdentityImages(keyUID string) ([]*images.IdentityImage, error) { + return api.service.multiAccountsDB.GetIdentityImages(keyUID) } // GetIdentityImage returns a json object representing the image with the given name -func (api *PublicAPI) GetIdentityImage(keyUID, name string) (string, error) { - ii, err := api.service.multiAccountsDB.GetIdentityImage(keyUID, name) - if err != nil { - return "", err - } - - js, err := json.Marshal(ii) - - return string(js), err +func (api *PublicAPI) GetIdentityImage(keyUID, name string) (*images.IdentityImage, error) { + return api.service.multiAccountsDB.GetIdentityImage(keyUID, name) } // StoreIdentityImage takes the filepath of an image, crops it as per the rect coords and finally resizes the image. // The resulting image(s) will be stored in the DB along with other user account information. // aX and aY represent the pixel coordinates of the upper left corner of the image's cropping area // bX and bY represent the pixel coordinates of the lower right corner of the image's cropping area -func (api *PublicAPI) StoreIdentityImage(keyUID, filepath string, aX, aY, bX, bY int) (string, error) { +func (api *PublicAPI) StoreIdentityImage(keyUID, filepath string, aX, aY, bX, bY int) ([]*images.IdentityImage, error) { iis, err := images.GenerateIdentityImages(filepath, aX, aY, bX, bY) if err != nil { - return "", err + return nil, err } err = api.service.multiAccountsDB.StoreIdentityImages(keyUID, iis) if err != nil { - return "", err + return nil, err } - js, err := json.Marshal(iis) - - return string(js), err + return iis, err } // DeleteIdentityImage deletes an IdentityImage from the db with the given name