From 598c886aa6975e1a2af346ee230cbfc53a872df2 Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Mon, 14 Nov 2022 14:45:26 +0700 Subject: [PATCH 1/9] nats model campaign --- client/social_post.go | 41 +++++++++++++++++++++++++ model/file_response.go | 56 +++++++++++++++++++++++++++++++++++ model/social_post_request.go | 8 +++++ model/social_post_response.go | 49 ++++++++++++++++++++++++++++++ subject/config.go | 2 ++ subject/social_post.go | 15 ++++++++++ 6 files changed, 171 insertions(+) create mode 100644 client/social_post.go create mode 100644 model/file_response.go create mode 100644 model/social_post_request.go create mode 100644 model/social_post_response.go create mode 100644 subject/social_post.go diff --git a/client/social_post.go b/client/social_post.go new file mode 100644 index 0000000..f8bcc3b --- /dev/null +++ b/client/social_post.go @@ -0,0 +1,41 @@ +package client + +import ( + "encoding/json" + "errors" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// SocialPost ... +type SocialPost struct{} + +// GetSocialPost ... +func GetSocialPost() SocialPost { + return SocialPost{} +} + +// GetListSocialPostAppInfoByIDs ... +func (s Seller) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppByIDsRequest) (*model.ResponseListSocialPostAppInfo, error) { + msg, err := natsio.GetServer().Request(subject.SocialPost.GetListSocialPostAppInfoByIDs, toBytes(p)) + + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseListSocialPostAppInfo `json:"data"` + Error string `json:"error"` + } + + if err = json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + + if r.Error != "" { + return nil, errors.New(r.Error) + + } + return r.Data, nil +} diff --git a/model/file_response.go b/model/file_response.go new file mode 100644 index 0000000..6eff304 --- /dev/null +++ b/model/file_response.go @@ -0,0 +1,56 @@ +package model + +import "go.mongodb.org/mongo-driver/bson/primitive" + +// FilePhoto ... +type FilePhoto struct { + ID string `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"` +} + +// ListPhoto ... +type ListPhoto []*FilePhoto + +// Video ... +type Video struct { + ID primitive.ObjectID `json:"_id"` + Name string `json:"name"` + Dimensions *FileVideoDimensions `json:"dimensions"` + VideoExtension string `json:"ext"` + Thumbnail *FilePhoto `json:"thumbnail"` + Status string `json:"status"` +} + +// FileVideoDimensions ... +type FileVideoDimensions struct { + Dimension480p *FileVideoSize `json:"size480p"` + Dimension720p *FileVideoSize `json:"size720p"` + Dimension1080p *FileVideoSize `json:"size1080p"` + DimensionOriginal *FileVideoSize `json:"original"` +} + +// FileVideoSize ... +type FileVideoSize struct { + Name string `json:"name"` + Width int `json:"width"` + Height int `json:"height"` + Size string `json:"size"` + URL string `json:"url"` +} + +// ListVideo ... +type ListVideo []Video diff --git a/model/social_post_request.go b/model/social_post_request.go new file mode 100644 index 0000000..179e378 --- /dev/null +++ b/model/social_post_request.go @@ -0,0 +1,8 @@ +package model + +import "go.mongodb.org/mongo-driver/bson/primitive" + +// GetListSocialPostAppByIDsRequest ... +type GetListSocialPostAppByIDsRequest struct { + SocialPostIDs []primitive.ObjectID `json:"socialPostIDs"` +} diff --git a/model/social_post_response.go b/model/social_post_response.go new file mode 100644 index 0000000..cb6469b --- /dev/null +++ b/model/social_post_response.go @@ -0,0 +1,49 @@ +package model + +import ( + "go.mongodb.org/mongo-driver/bson/primitive" + "time" +) + +// ResponseListSocialPostAppInfo ... +type ResponseListSocialPostAppInfo struct { + SocialPosts []SocialPostAppInfo `json:"socialPosts"` +} + +// SocialPostAppInfo ... +type SocialPostAppInfo struct { + ID primitive.ObjectID `json:"_id"` + Title string `json:"title"` + Content string `json:"content"` + Statistic SocialPostStatistic `json:"statistic"` + Author *SocialPostSellerInfo `json:"author"` + Photos ListPhoto `json:"photos"` + PublishedAt time.Time `json:"publishedAt"` + IsLiked bool `json:"isLiked"` + IsPin bool `json:"isPin"` + Contributor *SocialPostSellerInfo `json:"contributor"` + CreatedAt time.Time `json:"createdAt"` + Status string `json:"status"` + HasUpdate bool `json:"hasUpdate"` + Order int `json:"order"` + Videos ListVideo `json:"videos"` +} + +// SocialPostStatistic ... +type SocialPostStatistic struct { + Views int `json:"views"` + UniqueViews int `json:"uniqueViews"` + Likes int `json:"likes"` + Shares int `json:"shares"` + UniqueShares int `json:"uniqueShares"` + Comments int `json:"comments"` +} + +// SocialPostSellerInfo ... +type SocialPostSellerInfo struct { + ID primitive.ObjectID `json:"_id"` + Name string `json:"name"` + Membership SellerMembershipInfo `json:"membership"` + Logo *FilePhoto `json:"logo"` + IsMine bool `json:"isMine"` +} diff --git a/subject/config.go b/subject/config.go index 90a014f..e8cf263 100644 --- a/subject/config.go +++ b/subject/config.go @@ -11,6 +11,7 @@ var prefixes = struct { Seller string SupplierUser string SupplierRole string + SocialPost string }{ Communication: "communication", Order: "order", @@ -22,4 +23,5 @@ var prefixes = struct { Seller: "seller", SupplierUser: "supplier_user", SupplierRole: "supplier_role", + SocialPost: "social_post", } diff --git a/subject/social_post.go b/subject/social_post.go new file mode 100644 index 0000000..ff585c9 --- /dev/null +++ b/subject/social_post.go @@ -0,0 +1,15 @@ +package subject + +import "fmt" + +// getSocialPostValue ... +func getSocialPostValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.SocialPost, val) +} + +// SocialPost ... +var SocialPost = struct { + GetListSocialPostAppInfoByIDs string +}{ + GetListSocialPostAppInfoByIDs: getSocialPostValue("get_list_social_post_app_info_by_ids"), +} From 18f4444156d1358181b6748c7118800b1396ad59 Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Mon, 14 Nov 2022 15:11:04 +0700 Subject: [PATCH 2/9] fix --- client/social_post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/social_post.go b/client/social_post.go index f8bcc3b..bae985d 100644 --- a/client/social_post.go +++ b/client/social_post.go @@ -17,7 +17,7 @@ func GetSocialPost() SocialPost { } // GetListSocialPostAppInfoByIDs ... -func (s Seller) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppByIDsRequest) (*model.ResponseListSocialPostAppInfo, error) { +func (s SocialPost) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppByIDsRequest) (*model.ResponseListSocialPostAppInfo, error) { msg, err := natsio.GetServer().Request(subject.SocialPost.GetListSocialPostAppInfoByIDs, toBytes(p)) if err != nil { From 7a213f4b4d64b3d82c55e6122f8c4d8b300935f4 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Wed, 16 Nov 2022 16:38:41 +0700 Subject: [PATCH 3/9] nats model campaign admin --- client/social_post.go | 24 ++++++++++++++++++++++++ model/social_post_request.go | 5 +++++ model/social_post_response.go | 11 +++++++++++ subject/social_post.go | 6 ++++-- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/client/social_post.go b/client/social_post.go index bae985d..e6d9395 100644 --- a/client/social_post.go +++ b/client/social_post.go @@ -39,3 +39,27 @@ func (s SocialPost) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppBy } return r.Data, nil } + +// GetBriefDetailSocialPostAdminByIDsRequest ... +func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefDetailSocialPostAdminByIDsRequest) (*model.ResponseDetailSocialPostAdminInfo, error) { + msg, err := natsio.GetServer().Request(subject.SocialPost.GetBriefDetailSocialPostAdminByIDs, toBytes(p)) + + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseDetailSocialPostAdminInfo `json:"data"` + Error string `json:"error"` + } + + if err = json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + + if r.Error != "" { + return nil, errors.New(r.Error) + + } + return r.Data, nil +} diff --git a/model/social_post_request.go b/model/social_post_request.go index 179e378..72cd803 100644 --- a/model/social_post_request.go +++ b/model/social_post_request.go @@ -6,3 +6,8 @@ import "go.mongodb.org/mongo-driver/bson/primitive" type GetListSocialPostAppByIDsRequest struct { SocialPostIDs []primitive.ObjectID `json:"socialPostIDs"` } + +// GetBriefDetailSocialPostAdminByIDsRequest ... +type GetBriefDetailSocialPostAdminByIDsRequest struct { + SocialPostIDs []primitive.ObjectID `json:"socialPostIDs"` +} diff --git a/model/social_post_response.go b/model/social_post_response.go index cb6469b..94371f5 100644 --- a/model/social_post_response.go +++ b/model/social_post_response.go @@ -47,3 +47,14 @@ type SocialPostSellerInfo struct { Logo *FilePhoto `json:"logo"` IsMine bool `json:"isMine"` } + +// ResponseDetailSocialPostAdminInfo ... +type ResponseDetailSocialPostAdminInfo struct { + SocialPosts SocialPostAdminInfo `json:"socialPosts"` +} + +type SocialPostAdminInfo struct { + ID primitive.ObjectID `json:"_id"` + Title string `json:"title"` + Status string `json:"status"` +} diff --git a/subject/social_post.go b/subject/social_post.go index ff585c9..a90106a 100644 --- a/subject/social_post.go +++ b/subject/social_post.go @@ -9,7 +9,9 @@ func getSocialPostValue(val string) string { // SocialPost ... var SocialPost = struct { - GetListSocialPostAppInfoByIDs string + GetListSocialPostAppInfoByIDs string + GetBriefDetailSocialPostAdminByIDs string }{ - GetListSocialPostAppInfoByIDs: getSocialPostValue("get_list_social_post_app_info_by_ids"), + GetListSocialPostAppInfoByIDs: getSocialPostValue("get_list_social_post_app_info_by_ids"), + GetBriefDetailSocialPostAdminByIDs: getSocialPostValue("get_brief_detail_social_post_admin_by_ids"), } From 6e21f72ac00bc7cd94bd73338adeaf01a72fb023 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Wed, 16 Nov 2022 17:21:37 +0700 Subject: [PATCH 4/9] fix name func --- client/social_post.go | 4 ++-- model/social_post_request.go | 4 ++-- subject/social_post.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/social_post.go b/client/social_post.go index e6d9395..9e614c0 100644 --- a/client/social_post.go +++ b/client/social_post.go @@ -41,8 +41,8 @@ func (s SocialPost) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppBy } // GetBriefDetailSocialPostAdminByIDsRequest ... -func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefDetailSocialPostAdminByIDsRequest) (*model.ResponseDetailSocialPostAdminInfo, error) { - msg, err := natsio.GetServer().Request(subject.SocialPost.GetBriefDetailSocialPostAdminByIDs, toBytes(p)) +func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefInfoSocialPostAdminByIDsRequest) (*model.ResponseDetailSocialPostAdminInfo, error) { + msg, err := natsio.GetServer().Request(subject.SocialPost.GetBriefInfoSocialPostAdminByIDs, toBytes(p)) if err != nil { return nil, err diff --git a/model/social_post_request.go b/model/social_post_request.go index 72cd803..efeb983 100644 --- a/model/social_post_request.go +++ b/model/social_post_request.go @@ -7,7 +7,7 @@ type GetListSocialPostAppByIDsRequest struct { SocialPostIDs []primitive.ObjectID `json:"socialPostIDs"` } -// GetBriefDetailSocialPostAdminByIDsRequest ... -type GetBriefDetailSocialPostAdminByIDsRequest struct { +// GetBriefInfoSocialPostAdminByIDsRequest ... +type GetBriefInfoSocialPostAdminByIDsRequest struct { SocialPostIDs []primitive.ObjectID `json:"socialPostIDs"` } diff --git a/subject/social_post.go b/subject/social_post.go index a90106a..029f876 100644 --- a/subject/social_post.go +++ b/subject/social_post.go @@ -9,9 +9,9 @@ func getSocialPostValue(val string) string { // SocialPost ... var SocialPost = struct { - GetListSocialPostAppInfoByIDs string - GetBriefDetailSocialPostAdminByIDs string + GetListSocialPostAppInfoByIDs string + GetBriefInfoSocialPostAdminByIDs string }{ - GetListSocialPostAppInfoByIDs: getSocialPostValue("get_list_social_post_app_info_by_ids"), - GetBriefDetailSocialPostAdminByIDs: getSocialPostValue("get_brief_detail_social_post_admin_by_ids"), + GetListSocialPostAppInfoByIDs: getSocialPostValue("get_list_social_post_app_info_by_ids"), + GetBriefInfoSocialPostAdminByIDs: getSocialPostValue("get_brief_info_social_post_admin_by_ids"), } From 26f8b64258d5e30d1a55aa448b072b4ff0e3ec63 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Wed, 16 Nov 2022 17:33:29 +0700 Subject: [PATCH 5/9] fix --- model/social_post_response.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/model/social_post_response.go b/model/social_post_response.go index 94371f5..811d791 100644 --- a/model/social_post_response.go +++ b/model/social_post_response.go @@ -48,9 +48,9 @@ type SocialPostSellerInfo struct { IsMine bool `json:"isMine"` } -// ResponseDetailSocialPostAdminInfo ... -type ResponseDetailSocialPostAdminInfo struct { - SocialPosts SocialPostAdminInfo `json:"socialPosts"` +// ResponseListSocialPostAdminInfo ... +type ResponseListSocialPostAdminInfo struct { + SocialPosts []SocialPostAdminInfo `json:"socialPosts"` } type SocialPostAdminInfo struct { From b8f10912c1129a5ca8790a869ab38a7e019ea7c6 Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Thu, 17 Nov 2022 09:27:45 +0700 Subject: [PATCH 6/9] rename --- client/social_post.go | 6 +++--- model/social_post_response.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/social_post.go b/client/social_post.go index 9e614c0..72b1781 100644 --- a/client/social_post.go +++ b/client/social_post.go @@ -41,7 +41,7 @@ func (s SocialPost) GetListSocialPostAppInfoByIDs(p model.GetListSocialPostAppBy } // GetBriefDetailSocialPostAdminByIDsRequest ... -func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefInfoSocialPostAdminByIDsRequest) (*model.ResponseDetailSocialPostAdminInfo, error) { +func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefInfoSocialPostAdminByIDsRequest) (*model.ResponseListSocialPostAdminInfo, error) { msg, err := natsio.GetServer().Request(subject.SocialPost.GetBriefInfoSocialPostAdminByIDs, toBytes(p)) if err != nil { @@ -49,8 +49,8 @@ func (s SocialPost) GetBriefDetailSocialPostAdminByIDsRequest(p model.GetBriefIn } var r struct { - Data *model.ResponseDetailSocialPostAdminInfo `json:"data"` - Error string `json:"error"` + Data *model.ResponseListSocialPostAdminInfo `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { diff --git a/model/social_post_response.go b/model/social_post_response.go index 811d791..e0765f5 100644 --- a/model/social_post_response.go +++ b/model/social_post_response.go @@ -53,6 +53,7 @@ type ResponseListSocialPostAdminInfo struct { SocialPosts []SocialPostAdminInfo `json:"socialPosts"` } +// SocialPostAdminInfo ... type SocialPostAdminInfo struct { ID primitive.ObjectID `json:"_id"` Title string `json:"title"` From 549aee36d052a27e846d530202853d75789e7a21 Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Fri, 18 Nov 2022 14:52:05 +0700 Subject: [PATCH 7/9] update notification opts --- js/model/selly.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/model/selly.go b/js/model/selly.go index a8e0a60..856da44 100644 --- a/js/model/selly.go +++ b/js/model/selly.go @@ -12,8 +12,9 @@ type PushNotification struct { // NotificationOptions ... type NotificationOptions struct { - Title string `json:"title"` - Content string `json:"content"` + Title string `json:"title"` + Content string `json:"content"` + CampaignID string `json:"campaignId,omitempty"` } // PayloadUpdateSellerAffiliateStatistic ... From 0dd3dce224ab1357c8165c18cf66376da721f49e Mon Sep 17 00:00:00 2001 From: tuannt20 <105765641+tuannt20@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:04:40 +0700 Subject: [PATCH 8/9] add nats staff --- client/staff.go | 41 +++++++++++++++++++++++++++++++++++++++++ model/staff_request.go | 6 ++++++ model/staff_response.go | 12 ++++++++++++ subject/config.go | 2 ++ subject/staff.go | 14 ++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 client/staff.go create mode 100644 model/staff_request.go create mode 100644 model/staff_response.go create mode 100644 subject/staff.go diff --git a/client/staff.go b/client/staff.go new file mode 100644 index 0000000..b175f53 --- /dev/null +++ b/client/staff.go @@ -0,0 +1,41 @@ +package client + +import ( + "encoding/json" + "errors" + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Staff ... +type Staff struct{} + +func GetStaff() Staff { + return Staff{} +} + +// GetListStaffInfoByIds ... +func (s Staff) GetListStaffInfoByIds(p model.GetListStaffRequest) (*model.ResponseListStaffInfo, error) { + msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfo, toBytes(p)) + + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseListStaffInfo `json:"data"` + Error string `json:"error"` + } + + if err := json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + + if r.Error != "" { + return nil, errors.New(r.Error) + } + + return r.Data, nil + +} diff --git a/model/staff_request.go b/model/staff_request.go new file mode 100644 index 0000000..176b34e --- /dev/null +++ b/model/staff_request.go @@ -0,0 +1,6 @@ +package model + +// GetListStaffRequest ... +type GetListStaffRequest struct { + StaffIds []string `json:"staffIds"` +} diff --git a/model/staff_response.go b/model/staff_response.go new file mode 100644 index 0000000..5076d0c --- /dev/null +++ b/model/staff_response.go @@ -0,0 +1,12 @@ +package model + +// ResponseListStaffInfo ... +type ResponseListStaffInfo struct { + Staffs []ResponseStaffInfo `json:"staffs"` +} + +// ResponseStaffInfo ... +type ResponseStaffInfo struct { + ID string `json:"_id"` + Name string `json:"name"` +} diff --git a/subject/config.go b/subject/config.go index e8cf263..2a2f743 100644 --- a/subject/config.go +++ b/subject/config.go @@ -12,6 +12,7 @@ var prefixes = struct { SupplierUser string SupplierRole string SocialPost string + Staff string }{ Communication: "communication", Order: "order", @@ -24,4 +25,5 @@ var prefixes = struct { SupplierUser: "supplier_user", SupplierRole: "supplier_role", SocialPost: "social_post", + Staff: "staff", } diff --git a/subject/staff.go b/subject/staff.go new file mode 100644 index 0000000..4777f06 --- /dev/null +++ b/subject/staff.go @@ -0,0 +1,14 @@ +package subject + +import "fmt" + +func getStaffValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Staff, val) +} + +// Staff ... +var Staff = struct { + GetListStaffInfo string +}{ + GetListStaffInfo: getStaffValue("get_list_staff_info"), +} From dbf8ad502f061c3ff19226bafd0ff3665c1cce3b Mon Sep 17 00:00:00 2001 From: Nguyen Minh Date: Wed, 23 Nov 2022 16:54:31 +0700 Subject: [PATCH 9/9] fix --- model/social_post_response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/social_post_response.go b/model/social_post_response.go index e0765f5..85a2445 100644 --- a/model/social_post_response.go +++ b/model/social_post_response.go @@ -44,7 +44,7 @@ type SocialPostSellerInfo struct { ID primitive.ObjectID `json:"_id"` Name string `json:"name"` Membership SellerMembershipInfo `json:"membership"` - Logo *FilePhoto `json:"logo"` + Logo *FilePhoto `json:"avatar"` IsMine bool `json:"isMine"` }