From c33715bdd5656747e9a1e271e98eb8eca0e3435b Mon Sep 17 00:00:00 2001 From: Hoang Date: Mon, 22 Nov 2021 17:35:21 +0700 Subject: [PATCH] update userAvatar --- action.go | 2 +- model/db.go | 2 +- model/user_request.go | 1 + model/user_response.go | 1 + user/handle.go | 6 ++++-- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/action.go b/action.go index 3774fdd..8c8b708 100644 --- a/action.go +++ b/action.go @@ -65,7 +65,7 @@ func (s Service) HasPermission(userID, permission string) bool { } // UpdateUserAvatar ... -func (s Service) UpdateUserAvatar(userID, avatar string) error { +func (s Service) UpdateUserAvatar(userID string, avatar interface{}) error { return user.UpdateAvatar(userID, avatar) } diff --git a/model/db.go b/model/db.go index 6eec155..1a34908 100644 --- a/model/db.go +++ b/model/db.go @@ -28,7 +28,7 @@ type DBUser struct { Status string `bson:"status"` RoleID primitive.ObjectID `bson:"roleId"` RequireToChangePassword bool `bson:"requireToChangePassword"` - Avatar string `bson:"avatar"` + Avatar interface{} `bson:"avatar"` Deleted bool `bson:"deleted"` Other interface{} `bson:"other"` // object CreatedAt time.Time `bson:"createdAt"` diff --git a/model/user_request.go b/model/user_request.go index 9e3f2a3..ccdc684 100644 --- a/model/user_request.go +++ b/model/user_request.go @@ -16,6 +16,7 @@ type UserCreateOptions struct { RoleID string RequireToChangePassword bool Other interface{} + Avatar interface{} // if not, pass default file object } // UserUpdateOptions ... diff --git a/model/user_response.go b/model/user_response.go index 47872cb..b6bf148 100644 --- a/model/user_response.go +++ b/model/user_response.go @@ -13,6 +13,7 @@ type User struct { Status string `json:"status"` Role RoleShort `json:"role"` Other interface{} `json:"other"` + Avatar interface{} `json:"avatar"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } diff --git a/user/handle.go b/user/handle.go index dae3dc9..b6062bd 100644 --- a/user/handle.go +++ b/user/handle.go @@ -70,6 +70,7 @@ func newUser(payload model.UserCreateOptions) model.DBUser { Status: payload.Status, RoleID: roleID, Other: payload.Other, + Avatar: payload.Avatar, CreatedAt: timeNow, UpdatedAt: timeNow, } @@ -177,6 +178,7 @@ func getResponse(ctx context.Context, user model.DBUser) model.User { Level: roleRaw.Level, IsAdmin: roleRaw.IsAdmin, }, + Avatar: user.Avatar, Other: user.Other, CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, @@ -443,12 +445,12 @@ func checkUserHasPermissionFromCache(roleID primitive.ObjectID, permission strin } // UpdateAvatar ... -func UpdateAvatar(userID string, avatar string) error { +func UpdateAvatar(userID string, avatar interface{}) error { var ( ctx = context.Background() ) - if avatar == "" { + if avatar == nil { return errors.New("no avatar data") }