From 9a72716fd039e6cc198471e73a6504902c4712e5 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Wed, 29 Jun 2022 09:00:30 +0700 Subject: [PATCH 1/7] [Update] Check permission payload --- struct.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/struct.go b/struct.go index 5e394e6..160205f 100644 --- a/struct.go +++ b/struct.go @@ -63,14 +63,25 @@ type Config struct { Nats natsio.Config } +// Agent ... +type Agent struct { + Source string `json:"source"` + IP string `json:"ip"` + Platform string `json:"platform"` + Version string `json:"version"` +} + // StaffCheckPermissionBody ... type StaffCheckPermissionBody struct { - StaffID string `json:"staffId"` - Token string `json:"token"` - Permission []string `json:"permission"` - Source string `json:"source"` - Code string `json:"code,omitempty"` - IsRoot string `json:"isRoot"` + StaffID string `json:"staffId"` + Token string `json:"token"` + Permission []string `json:"permission"` + Source string `json:"source"` + Code string `json:"code,omitempty"` + IsRoot string `json:"isRoot"` + Agent Agent `json:"agent"` + DeviceId string `json:"deviceId"` + Payload PayloadCheckPermission `json:"payload"` } // PayloadCheckPermission ... From 8f2060a7dc61573e9565b7fe5775c26d17c0895b Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Thu, 30 Jun 2022 11:20:00 +0700 Subject: [PATCH 2/7] [Update] Get staff info --- constants.go | 5 +++-- request.go | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/constants.go b/constants.go index eefc318..c89d0fd 100644 --- a/constants.go +++ b/constants.go @@ -5,8 +5,9 @@ const ( SubjectRequestNatsGetPermission = "authentication.request.staff.list_permission" SubjectRequestNatsSyncStaff = "authentication.request.staff.sync_data" - SubjectRequestNatsStaffCreate = "authentication.request.staff.create" - SubjectRequestNatsStaffUpdate = "authentication.request.staff.update" + SubjectRequestNatsStaffCreate = "authentication.request.staff.create" + SubjectRequestNatsStaffUpdate = "authentication.request.staff.update" + SubjectRequestNatsStaffGetInfo = "authentication.request.staff.get_info" SubjectRequestNatsAddLogs = "authentication.request.logs.create" SubjectRequestNatsLogsGetList = "authentication.request.logs.list" diff --git a/request.go b/request.go index 1bddcf1..bd4d034 100644 --- a/request.go +++ b/request.go @@ -29,6 +29,11 @@ func (Request) UpdateStaff(payload Staff) (*Response, error) { return requestNats(SubjectRequestNatsStaffUpdate, toBytes(payload)) } +// GetInfoStaff ... +func (Request) GetInfoStaff(payload *CommonQuery) (*Response, error) { + return requestNats(SubjectRequestNatsStaffGetInfo, toBytes(payload)) +} + // SaveLog ... func (Request) SaveLog(payload Log) (*Response, error) { return requestNats(SubjectRequestNatsAddLogs, toBytes(payload)) From 1e02009620be56ba069f21e4dff5c08c53821aa1 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Thu, 30 Jun 2022 11:26:22 +0700 Subject: [PATCH 3/7] [Update] Get staff info --- request.go | 2 +- struct.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/request.go b/request.go index bd4d034..06044af 100644 --- a/request.go +++ b/request.go @@ -30,7 +30,7 @@ func (Request) UpdateStaff(payload Staff) (*Response, error) { } // GetInfoStaff ... -func (Request) GetInfoStaff(payload *CommonQuery) (*Response, error) { +func (Request) GetInfoStaff(payload GetInfoStaff) (*Response, error) { return requestNats(SubjectRequestNatsStaffGetInfo, toBytes(payload)) } diff --git a/struct.go b/struct.go index 160205f..6cff8bf 100644 --- a/struct.go +++ b/struct.go @@ -14,6 +14,11 @@ type CommonQuery struct { StaffID string `json:"staffID"` } +// GetInfoStaff ... +type GetInfoStaff struct { + Condition interface{} `json:"condition"` +} + // Log ... type Log struct { Reference string `json:"reference"` From 1b03ec9c794524235562a66fbee0b77c74162ed0 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Thu, 30 Jun 2022 12:07:07 +0700 Subject: [PATCH 4/7] [Update] Get staff info --- constants.go | 1 + request.go | 5 +++++ struct.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/constants.go b/constants.go index c89d0fd..a107bb1 100644 --- a/constants.go +++ b/constants.go @@ -8,6 +8,7 @@ const ( SubjectRequestNatsStaffCreate = "authentication.request.staff.create" SubjectRequestNatsStaffUpdate = "authentication.request.staff.update" SubjectRequestNatsStaffGetInfo = "authentication.request.staff.get_info" + SubjectRequestNatsStaffGetList = "authentication.request.staff.list" SubjectRequestNatsAddLogs = "authentication.request.logs.create" SubjectRequestNatsLogsGetList = "authentication.request.logs.list" diff --git a/request.go b/request.go index 06044af..a80a6e1 100644 --- a/request.go +++ b/request.go @@ -34,6 +34,11 @@ func (Request) GetInfoStaff(payload GetInfoStaff) (*Response, error) { return requestNats(SubjectRequestNatsStaffGetInfo, toBytes(payload)) } +// GetListStaff ... +func (Request) GetListStaff(payload GetInfoStaff) (*Response, error) { + return requestNats(SubjectRequestNatsStaffGetList, toBytes(payload)) +} + // SaveLog ... func (Request) SaveLog(payload Log) (*Response, error) { return requestNats(SubjectRequestNatsAddLogs, toBytes(payload)) diff --git a/struct.go b/struct.go index 6cff8bf..0074aa6 100644 --- a/struct.go +++ b/struct.go @@ -3,6 +3,8 @@ package authentication import ( "github.com/Selly-Modules/natsio" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "time" ) // CommonQuery ... @@ -128,3 +130,46 @@ type Response struct { Data []byte `json:"data,omitempty"` Message string `json:"message"` } + +// StaffInfo ... +type StaffInfo struct { + ID primitive.ObjectID `json:"_id"` + Name string `json:"name"` + SearchString string `json:"searchString"` + Email string `json:"email"` + Phone string `json:"phone"` + Active bool `json:"active"` + Role primitive.ObjectID `json:"role,omitempty"` + Avatar *FilePhoto `json:"avatar,omitempty"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + IsRoot bool `json:"isRoot"` + Permissions []string `json:"permissions"` + Source []string `json:"source"` + NotAllowedLoginAdmin bool `json:"notAllowedLoginAdmin"` +} + +// ListStaffInfo ... +type ListStaffInfo struct { + Staffs []StaffInfo `json:"staff"` +} + +// FilePhoto ... +type FilePhoto struct { + ID primitive.ObjectID `json:"_id"` + Name string `json:"name,omitempty"` + Dimensions *FileDimensions `json:"dimensions"` +} + +// FileSize ... +type FileSize struct { + Width int `json:"width"` + Height int `json:"height"` + URL string `json:"url"` +} + +// FileDimensions ... +type FileDimensions struct { + Small *FileSize `json:"sm"` + Medium *FileSize `json:"md"` +} From 33b40fe8da06beca71f61565551c116c29cd177b Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Thu, 30 Jun 2022 13:56:47 +0700 Subject: [PATCH 5/7] [Update] v2 --- struct.go | 45 --------------------------------------------- 1 file changed, 45 deletions(-) diff --git a/struct.go b/struct.go index 66da354..4968145 100644 --- a/struct.go +++ b/struct.go @@ -3,8 +3,6 @@ package authentication import ( "github.com/Selly-Modules/natsio" "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "time" ) // CommonQuery ... @@ -140,46 +138,3 @@ type Response struct { Data []byte `json:"data,omitempty"` Message string `json:"message"` } - -// StaffInfo ... -type StaffInfo struct { - ID primitive.ObjectID `json:"_id"` - Name string `json:"name"` - SearchString string `json:"searchString"` - Email string `json:"email"` - Phone string `json:"phone"` - Active bool `json:"active"` - Role primitive.ObjectID `json:"role,omitempty"` - Avatar *FilePhoto `json:"avatar,omitempty"` - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` - IsRoot bool `json:"isRoot"` - Permissions []string `json:"permissions"` - Source []string `json:"source"` - NotAllowedLoginAdmin bool `json:"notAllowedLoginAdmin"` -} - -// ListStaffInfo ... -type ListStaffInfo struct { - Staffs []StaffInfo `json:"staff"` -} - -// FilePhoto ... -type FilePhoto struct { - ID primitive.ObjectID `json:"_id"` - Name string `json:"name,omitempty"` - Dimensions *FileDimensions `json:"dimensions"` -} - -// FileSize ... -type FileSize struct { - Width int `json:"width"` - Height int `json:"height"` - URL string `json:"url"` -} - -// FileDimensions ... -type FileDimensions struct { - Small *FileSize `json:"sm"` - Medium *FileSize `json:"md"` -} From 94fa0d0231e027ddf99886be934f0177c2f92d0e Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Fri, 1 Jul 2022 09:20:57 +0700 Subject: [PATCH 6/7] [Update] Get staff info --- authentication.go | 7 +++++++ request.go | 4 ++-- struct.go | 9 +++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/authentication.go b/authentication.go index 4e747f5..0992675 100644 --- a/authentication.go +++ b/authentication.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "github.com/Selly-Modules/natsio" + "go.mongodb.org/mongo-driver/bson" ) // Client ... @@ -69,3 +70,9 @@ func toBytes(data interface{}) []byte { b, _ := json.Marshal(data) return b } + +// bsonToBytes ... +func bsonToBytes(data interface{}) []byte { + b, _ := bson.Marshal(data) + return b +} diff --git a/request.go b/request.go index e3e88b3..325255c 100644 --- a/request.go +++ b/request.go @@ -31,12 +31,12 @@ func (Request) UpdateStaff(payload Staff) (*Response, error) { // GetInfoStaff ... func (Request) GetInfoStaff(payload GetInfoStaff) (*Response, error) { - return requestNats(SubjectRequestNatsStaffGetInfo, toBytes(payload)) + return requestNats(SubjectRequestNatsStaffGetInfo, bsonToBytes(payload)) } // GetListStaff ... func (Request) GetListStaff(payload GetInfoStaff) (*Response, error) { - return requestNats(SubjectRequestNatsStaffGetList, toBytes(payload)) + return requestNats(SubjectRequestNatsStaffGetList, bsonToBytes(payload)) } // SaveLog ... diff --git a/struct.go b/struct.go index 4968145..4359444 100644 --- a/struct.go +++ b/struct.go @@ -24,9 +24,14 @@ type GetTokenByPhoneResponse struct { Token string `json:"token"` } -// GetInfoStaff ... +// GetInfoStaff +// Convert to bson bytes +// When partner use. Bson unmarshal convert to struct type GetInfoStaff struct { - Condition interface{} `json:"condition"` + Condition interface{} + Page int + Limit int + Sort bson.D } // Log ... From 912e1bf7a34fc09b456534973b6251138e9c86d0 Mon Sep 17 00:00:00 2001 From: trunglt251292 Date: Fri, 1 Jul 2022 09:26:32 +0700 Subject: [PATCH 7/7] [Update] Get staff info --- struct.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/struct.go b/struct.go index 4359444..01cafaf 100644 --- a/struct.go +++ b/struct.go @@ -29,8 +29,8 @@ type GetTokenByPhoneResponse struct { // When partner use. Bson unmarshal convert to struct type GetInfoStaff struct { Condition interface{} - Page int - Limit int + Page int64 + Limit int64 Sort bson.D }