Moved identity image endpoints to multi-accounts api

This commit is contained in:
Samuel Hawksby-Robinson 2020-11-30 15:41:45 +00:00 committed by Andrea Maria Piana
parent 279697128d
commit 87f161da08
2 changed files with 38 additions and 38 deletions

View File

@ -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)
}

View File

@ -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
// -----