diff --git a/biz/adaptor/server.go b/biz/adaptor/server.go index 7333396..9338964 100644 --- a/biz/adaptor/server.go +++ b/biz/adaptor/server.go @@ -45,10 +45,6 @@ func (s *SystemServerImpl) GetNotificationCount(ctx context.Context, req *system return s.SystemService.GetNotificationCount(ctx, req) } -func (s *SystemServerImpl) ReadNotification(ctx context.Context, req *system.ReadNotificationReq) (res *system.ReadNotificationResp, err error) { - return s.SystemService.ReadNotification(ctx, req) -} - -func (s *SystemServerImpl) CreateNotification(ctx context.Context, req *system.CreateNotificationReq) (res *system.CreateNotificationResp, err error) { - return s.SystemService.CreateNotification(ctx, req) +func (s *SystemServerImpl) CreateNotifications(ctx context.Context, req *system.CreateNotificationsReq) (res *system.CreateNotificationsResp, err error) { + return s.SystemService.CreateNotifications(ctx, req) } diff --git a/biz/application/service/system.go b/biz/application/service/system.go index 9295e11..634ec25 100644 --- a/biz/application/service/system.go +++ b/biz/application/service/system.go @@ -13,10 +13,9 @@ import ( ) type SystemService interface { - ReadNotification(ctx context.Context, req *gensystem.ReadNotificationReq) (resp *gensystem.ReadNotificationResp, err error) GetNotifications(ctx context.Context, req *gensystem.GetNotificationsReq) (resp *gensystem.GetNotificationsResp, err error) GetNotificationCount(ctx context.Context, req *gensystem.GetNotificationCountReq) (resp *gensystem.GetNotificationCountResp, err error) - CreateNotification(ctx context.Context, req *gensystem.CreateNotificationReq) (resp *gensystem.CreateNotificationResp, err error) + CreateNotifications(ctx context.Context, req *gensystem.CreateNotificationsReq) (resp *gensystem.CreateNotificationsResp, err error) ReadNotifications(ctx context.Context, req *gensystem.ReadNotificationsReq) (resp *gensystem.ReadNotificationsResp, err error) CleanNotification(ctx context.Context, req *gensystem.CleanNotificationReq) (resp *gensystem.CleanNotificationResp, err error) DeleteSlider(ctx context.Context, req *gensystem.DeleteSliderReq) (resp *gensystem.DeleteSliderResp, err error) @@ -72,14 +71,6 @@ func (s *SystemServiceImpl) GetSliders(ctx context.Context, req *gensystem.GetSl return resp, nil } -func (s *SystemServiceImpl) ReadNotification(ctx context.Context, req *gensystem.ReadNotificationReq) (resp *gensystem.ReadNotificationResp, err error) { - resp = new(gensystem.ReadNotificationResp) - if err = s.NotificationMongoMapper.ReadNotification(ctx, req.NotificationId); err != nil { - return resp, err - } - return resp, nil -} - func (s *SystemServiceImpl) GetNotifications(ctx context.Context, req *gensystem.GetNotificationsReq) (resp *gensystem.GetNotificationsResp, err error) { resp = new(gensystem.GetNotificationsResp) p := pconvertor.PaginationOptionsToModelPaginationOptions(req.PaginationOptions) @@ -114,9 +105,12 @@ func (s *SystemServiceImpl) GetNotificationCount(ctx context.Context, req *gensy return resp, nil } -func (s *SystemServiceImpl) CreateNotification(ctx context.Context, req *gensystem.CreateNotificationReq) (resp *gensystem.CreateNotificationResp, err error) { - resp = new(gensystem.CreateNotificationResp) - if err = s.NotificationMongoMapper.InsertOne(ctx, convertor.NotificationToNotificationMapper(req.Notification)); err != nil { +func (s *SystemServiceImpl) CreateNotifications(ctx context.Context, req *gensystem.CreateNotificationsReq) (resp *gensystem.CreateNotificationsResp, err error) { + resp = new(gensystem.CreateNotificationsResp) + notifications := lo.Map[*gensystem.Notification, *notificationmapper.Notification](req.Notifications, func(item *gensystem.Notification, _ int) *notificationmapper.Notification { + return convertor.NotificationToNotificationMapper(item) + }) + if err = s.NotificationMongoMapper.InsertMany(ctx, notifications); err != nil { return resp, err } return resp, nil diff --git a/biz/infrastructure/mapper/notification/mongo.go b/biz/infrastructure/mapper/notification/mongo.go index e8ce680..b4f683b 100644 --- a/biz/infrastructure/mapper/notification/mongo.go +++ b/biz/infrastructure/mapper/notification/mongo.go @@ -32,7 +32,7 @@ type ( ReadNotification(ctx context.Context, id string) error Count(ctx context.Context, fopts *FilterOptions) (int64, error) ReadNotifications(ctx context.Context, fopts *FilterOptions) error - InsertOne(ctx context.Context, data *Notification) error + InsertMany(ctx context.Context, data []*Notification) error GetNotificationsAndCount(ctx context.Context, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter mongop.MongoCursor) ([]*Notification, int64, error) } Notification struct { @@ -97,14 +97,16 @@ func (m *MongoMapper) GetNotificationsAndCount(ctx context.Context, fopts *Filte return data, count, nil } -func (m *MongoMapper) InsertOne(ctx context.Context, data *Notification) error { - if data.ID.IsZero() { - data.ID = primitive.NewObjectID() - } - data.CreateAt = time.Now() - data.UpdateAt = time.Now() - key := prefixNotificationCacheKey + data.ID.Hex() - _, err := m.conn.InsertOne(ctx, key, data) +func (m *MongoMapper) InsertMany(ctx context.Context, datas []*Notification) error { + lo.ForEach(datas, func(data *Notification, _ int) { + if data.ID.IsZero() { + data.ID = primitive.NewObjectID() + } + data.CreateAt = time.Now() + data.UpdateAt = time.Now() + }) + + _, err := m.conn.InsertMany(ctx, lo.ToAnySlice(datas)) return err } func (m *MongoMapper) GetNotifications(ctx context.Context, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter mongop.MongoCursor) ([]*Notification, int64, error) { diff --git a/go.mod b/go.mod index a32c5c2..853def4 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44 - github.com/CloudStriver/service-idl-gen-go v0.0.0-20240126122141-e60927663187 + github.com/CloudStriver/service-idl-gen-go v0.0.0-20240127152507-ef2faaa085cd github.com/cloudwego/kitex v0.8.0 github.com/google/wire v0.5.0 github.com/kitex-contrib/obs-opentelemetry v0.2.5 @@ -14,6 +14,10 @@ require ( google.golang.org/grpc v1.61.0 ) +//replace ( +// github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go +//) + require ( github.com/apache/thrift v0.16.0 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index 079c4f3..e8be331 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44 h1:7exnHSz2LCe github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44/go.mod h1:SsAxWs5EIcaDE/0e5buoFOWsM4lTvFZhySkV68+RT3g= github.com/CloudStriver/service-idl-gen-go v0.0.0-20240126122141-e60927663187 h1:x4nwoY+7PbBe7GpMeY4svfiz1YepvjIcB6N5L2oyvjg= github.com/CloudStriver/service-idl-gen-go v0.0.0-20240126122141-e60927663187/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240127152507-ef2faaa085cd h1:sC6f5hFtiUN51BCIbkfgteLn9UjRpWnjgl77fo7MzFw= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240127152507-ef2faaa085cd/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=