From 3507d1702961928305c667de7b4cb6538e6663d6 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 8 Nov 2022 18:02:42 +0700 Subject: [PATCH] build auth sms --- client/supplier_user.go | 40 ++++++++++++++++++++++++++++++++++ model/supplier_user_request.go | 9 ++++++++ subject/supplier_user.go | 40 +++++++++++++++++++--------------- 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/client/supplier_user.go b/client/supplier_user.go index 8f0762b..f7b52ad 100644 --- a/client/supplier_user.go +++ b/client/supplier_user.go @@ -37,6 +37,26 @@ func (s SupplierUser) LoginUser(p model.LoginUserRequest) (*model.LoginUserRespo return r.Data, nil } +func (s SupplierUser) Logout(p model.LogoutRequest) error { + msg, err := natsio.GetServer().Request(subject.SupplierUser.Logout, toBytes(p)) + if err != nil { + return err + } + + var r struct { + Error string `json:"error"` + } + + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + + return nil +} + func (s SupplierUser) GetListUser(p model.GetListUserRequest) (*model.GetListUserResponse, error) { msg, err := natsio.GetServer().Request(subject.SupplierUser.GetListUser, toBytes(p)) if err != nil { @@ -201,3 +221,23 @@ func (s SupplierUser) ResetPassword(p model.ResetPasswordRequest) (*model.ResetP return r.Data, nil } + +func (s SupplierUser) ChangePassword(p model.ChangePasswordRequest) error { + msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStatus, toBytes(p)) + if err != nil { + return err + } + + var r struct { + Error string `json:"error"` + } + + if err = json.Unmarshal(msg.Data, &r); err != nil { + return err + } + if r.Error != "" { + return errors.New(r.Error) + } + + return nil +} diff --git a/model/supplier_user_request.go b/model/supplier_user_request.go index fe359bb..401a1d1 100644 --- a/model/supplier_user_request.go +++ b/model/supplier_user_request.go @@ -17,6 +17,10 @@ type LoginUserRequest struct { IsMobile bool `json:"isMobile"` } +type LogoutRequest struct { + ID string `json:"_id"` +} + type GetListUserRequest struct { Page int `json:"page"` Limit int `json:"limit"` @@ -75,3 +79,8 @@ type UpdateStatusRequest struct { type ResetPasswordRequest struct { ID string `json:"_id"` } + +type ChangePasswordRequest struct { + ID string `json:"_id"` + Password string `json:"password"` +} diff --git a/subject/supplier_user.go b/subject/supplier_user.go index e70c032..49d186c 100644 --- a/subject/supplier_user.go +++ b/subject/supplier_user.go @@ -8,24 +8,28 @@ func getSupplierUserValue(val string) string { var SupplierUser = struct { // Users - LoginUser string - GetListUser string - DetailUser string - CreateOwner string - UpdateOwner string - CreateStaff string - UpdateStaff string - UpdateStatus string - ResetPassword string + LoginUser string + Logout string + GetListUser string + DetailUser string + CreateOwner string + UpdateOwner string + CreateStaff string + UpdateStaff string + UpdateStatus string + ResetPassword string + ChangePassword string }{ // Users - LoginUser: getSupplierUserValue("login_user"), - GetListUser: getSupplierUserValue("get_list_user"), - DetailUser: getSupplierUserValue("detail_user"), - CreateOwner: getSupplierUserValue("create_owner"), - UpdateOwner: getSupplierUserValue("update_owner"), - CreateStaff: getSupplierUserValue("create_staff"), - UpdateStaff: getSupplierUserValue("update_staff"), - UpdateStatus: getSupplierUserValue("update_status"), - ResetPassword: getSupplierUserValue("reset_password"), + LoginUser: getSupplierUserValue("login_user"), + Logout: getSupplierUserValue("logout"), + GetListUser: getSupplierUserValue("get_list_user"), + DetailUser: getSupplierUserValue("detail_user"), + CreateOwner: getSupplierUserValue("create_owner"), + UpdateOwner: getSupplierUserValue("update_owner"), + CreateStaff: getSupplierUserValue("create_staff"), + UpdateStaff: getSupplierUserValue("update_staff"), + UpdateStatus: getSupplierUserValue("update_status"), + ResetPassword: getSupplierUserValue("reset_password"), + ChangePassword: getSupplierUserValue("change_password"), }