diff --git a/biz/adaptor/server.go b/biz/adaptor/server.go index 25d4e81..1f14eb3 100644 --- a/biz/adaptor/server.go +++ b/biz/adaptor/server.go @@ -13,6 +13,10 @@ type SystemServerImpl struct { SystemService service.SystemService } +func (s *SystemServerImpl) DeleteNotifications(ctx context.Context, req *system.DeleteNotificationsReq) (res *system.DeleteNotificationsResp, err error) { + return s.SystemService.DeleteNotifications(ctx, req) +} + func (s *SystemServerImpl) CreateNotificationCount(ctx context.Context, req *system.CreateNotificationCountReq) (res *system.CreateNotificationCountResp, err error) { return s.SystemService.CreateNotificationCount(ctx, req) } diff --git a/biz/application/service/system.go b/biz/application/service/system.go index 1e8c404..597cc74 100644 --- a/biz/application/service/system.go +++ b/biz/application/service/system.go @@ -26,6 +26,7 @@ type SystemService interface { GetNotificationCount(ctx context.Context, req *gensystem.GetNotificationCountReq) (resp *gensystem.GetNotificationCountResp, err error) CreateNotifications(ctx context.Context, req *gensystem.CreateNotificationsReq) (resp *gensystem.CreateNotificationsResp, err error) CreateNotificationCount(ctx context.Context, req *gensystem.CreateNotificationCountReq) (resp *gensystem.CreateNotificationCountResp, err error) + DeleteNotifications(ctx context.Context, req *gensystem.DeleteNotificationsReq) (resp *gensystem.DeleteNotificationsResp, err error) } type SystemServiceImpl struct { @@ -35,6 +36,17 @@ type SystemServiceImpl struct { Redis *redis.Redis } +func (s *SystemServiceImpl) DeleteNotifications(ctx context.Context, req *gensystem.DeleteNotificationsReq) (resp *gensystem.DeleteNotificationsResp, err error) { + if err = s.NotificationMongoMapper.DeleteNotifications(ctx, ¬ificationmapper.FilterOptions{ + OnlyUserId: lo.ToPtr(req.UserId), + OnlyNotificationIds: req.NotificationIds, + OnlyType: req.OnlyType, + }); err != nil { + return resp, err + } + return resp, nil +} + func (s *SystemServiceImpl) CreateNotificationCount(ctx context.Context, req *gensystem.CreateNotificationCountReq) (resp *gensystem.CreateNotificationCountResp, err error) { uid, _ := primitive.ObjectIDFromHex(req.UserId) err = s.NotificationCountMongoMapper.CreateNotificationCount(ctx, ¬ificationcountmapper.NotificationCount{ @@ -57,7 +69,6 @@ func (s *SystemServiceImpl) UpdateSlider(ctx context.Context, req *gensystem.Upd ID: oid, ImageUrl: req.ImageUrl, LinkUrl: req.LinkUrl, - Type: req.Type, IsPublic: req.IsPublic, }); err != nil { return resp, err @@ -69,7 +80,6 @@ func (s *SystemServiceImpl) CreateSlider(ctx context.Context, req *gensystem.Cre if err = s.SliderMongoMapper.InsertOne(ctx, &slidermapper.Slider{ ImageUrl: req.ImageUrl, LinkUrl: req.LinkUrl, - Type: req.Type, IsPublic: req.IsPublic, }); err != nil { return resp, err diff --git a/biz/infrastructure/convertor/convertor.go b/biz/infrastructure/convertor/convertor.go index c9734e6..991f8e6 100644 --- a/biz/infrastructure/convertor/convertor.go +++ b/biz/infrastructure/convertor/convertor.go @@ -24,7 +24,6 @@ func SliderMapperToSlider(in *slidermapper.Slider) *gensystem.Slider { SliderId: in.ID.Hex(), ImageUrl: in.ImageUrl, LinkUrl: in.LinkUrl, - Type: in.Type, IsPublic: in.IsPublic, CreateTime: in.CreateAt.UnixMilli(), UpdateTime: in.UpdateAt.UnixMilli(), diff --git a/biz/infrastructure/mapper/notification/filter.go b/biz/infrastructure/mapper/notification/filter.go index f9c7375..3aa77d2 100644 --- a/biz/infrastructure/mapper/notification/filter.go +++ b/biz/infrastructure/mapper/notification/filter.go @@ -2,13 +2,16 @@ package notification import ( "github.com/CloudStriver/cloudmind-system/biz/infrastructure/consts" + "github.com/samber/lo" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" ) type FilterOptions struct { - OnlyUserId *string - OnlyUserIds []string - OnlyType *int64 + OnlyUserId *string + OnlyUserIds []string + OnlyType *int64 + OnlyNotificationIds []string } type MongoFilter struct { @@ -27,9 +30,20 @@ func (f *MongoFilter) toBson() bson.M { f.CheckOnlyUserId() f.CheckOnlyType() f.CheckOnlyUserIds() + f.CheckOnlyNotificationIds() return f.m } +func (f *MongoFilter) CheckOnlyNotificationIds() { + if f.OnlyNotificationIds != nil { + f.m[consts.ID] = bson.M{ + "$in": lo.Map[string, primitive.ObjectID](f.OnlyNotificationIds, func(item string, _ int) primitive.ObjectID { + oid, _ := primitive.ObjectIDFromHex(item) + return oid + }), + } + } +} func (f *MongoFilter) CheckOnlyUserId() { if f.OnlyUserId != nil { f.m[consts.TargetUserId] = *f.OnlyUserId diff --git a/biz/infrastructure/mapper/slider/mongo.go b/biz/infrastructure/mapper/slider/mongo.go index 0abbd49..53e8428 100644 --- a/biz/infrastructure/mapper/slider/mongo.go +++ b/biz/infrastructure/mapper/slider/mongo.go @@ -39,7 +39,6 @@ type ( ID primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"` ImageUrl string `bson:"imageUrl,omitempty" json:"imageUrl,omitempty"` LinkUrl string `bson:"linkUrl,omitempty" json:"linkUrl,omitempty"` - Type int64 `bson:"type,omitempty" json:"type,omitempty"` IsPublic int64 `bson:"isPublic,omitempty" json:"isPublic,omitempty"` UpdateAt time.Time `bson:"updateAt,omitempty" json:"updateAt,omitempty"` CreateAt time.Time `bson:"createAt,omitempty" json:"createAt,omitempty"` diff --git a/go.mod b/go.mod index a9bb341..e7f8a88 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-20240316123600-5ec7ab682e84 + github.com/CloudStriver/service-idl-gen-go v0.0.0-20240320133349-b226a7105473 github.com/cloudwego/kitex v0.8.0 github.com/google/wire v0.5.0 github.com/kitex-contrib/obs-opentelemetry v0.2.5 diff --git a/go.sum b/go.sum index 7aa343d..db6e2c3 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudStriver/go-pkg v0.0.0-20240117111745-b4ba57a38f44 h1:7exnHSz2LCeghuVDVD8IS+JaPB/bxDJWFEL7xH5L2Tg= 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-20240316123600-5ec7ab682e84 h1:kvEoAN/3SJPxXG9FQBi6VlUKKFdm1vQbYWeE1lK4hGQ= -github.com/CloudStriver/service-idl-gen-go v0.0.0-20240316123600-5ec7ab682e84/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240320133349-b226a7105473 h1:DmHH+V9hMFgGcXZSV8n/IW9OvD0ge9AiA+ZE+I73zUo= +github.com/CloudStriver/service-idl-gen-go v0.0.0-20240320133349-b226a7105473/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=