From 87f161da0810ff5eebd71b9b0cab101f4cc3bedb Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Mon, 30 Nov 2020 15:41:45 +0000 Subject: [PATCH] Moved identity image endpoints to multi-accounts api --- services/accounts/multiaccounts.go | 38 ++++++++++++++++++++++++++++++ services/ext/api.go | 38 ------------------------------ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/services/accounts/multiaccounts.go b/services/accounts/multiaccounts.go index 52d4f867d..afccb0399 100644 --- a/services/accounts/multiaccounts.go +++ b/services/accounts/multiaccounts.go @@ -2,6 +2,7 @@ package accounts import ( "errors" + "github.com/status-im/status-go/images" "github.com/status-im/status-go/account" "github.com/status-im/status-go/multiaccounts" @@ -25,3 +26,40 @@ type MultiAccountsAPI struct { func (api *MultiAccountsAPI) UpdateAccount(account multiaccounts.Account) error { return api.db.UpdateAccount(account) } + +// +// Profile Images +// + +// GetIdentityImages returns an array of json marshalled IdentityImages assigned to the user's identity +func (api *MultiAccountsAPI) GetIdentityImages(keyUID string) ([]*images.IdentityImage, error) { + return api.db.GetIdentityImages(keyUID) +} + +// GetIdentityImage returns a json object representing the image with the given name +func (api *MultiAccountsAPI) GetIdentityImage(keyUID, name string) (*images.IdentityImage, error) { + return api.db.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 *MultiAccountsAPI) 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 nil, err + } + + err = api.db.StoreIdentityImages(keyUID, iis) + if err != nil { + return nil, err + } + + return iis, err +} + +// DeleteIdentityImage deletes an IdentityImage from the db with the given name +func (api *MultiAccountsAPI) DeleteIdentityImage(keyUID string) error { + return api.db.DeleteIdentityImage(keyUID) +} diff --git a/services/ext/api.go b/services/ext/api.go index a39ce5363..5eea9248b 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -14,7 +14,6 @@ import ( "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" - "github.com/status-im/status-go/images" "github.com/status-im/status-go/mailserver" "github.com/status-im/status-go/protocol" "github.com/status-im/status-go/protocol/common" @@ -584,43 +583,6 @@ func (api *PublicAPI) Echo(ctx context.Context, message string) (string, error) return message, nil } -// -// Profile Images -// - -// GetIdentityImages returns an array of json marshalled IdentityImages assigned to the user's identity -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) (*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) ([]*images.IdentityImage, error) { - iis, err := images.GenerateIdentityImages(filepath, aX, aY, bX, bY) - if err != nil { - return nil, err - } - - err = api.service.multiAccountsDB.StoreIdentityImages(keyUID, iis) - if err != nil { - return nil, err - } - - return iis, err -} - -// DeleteIdentityImage deletes an IdentityImage from the db with the given name -func (api *PublicAPI) DeleteIdentityImage(keyUID string) error { - return api.service.multiAccountsDB.DeleteIdentityImage(keyUID) -} - // ----- // HELPER // -----