Skip to content

Commit

Permalink
feat: 添加删除帖子
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx committed Mar 22, 2024
1 parent 63adc92 commit a96e788
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions biz/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 12 additions & 2 deletions biz/application/service/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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, &notificationmapper.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, &notificationcountmapper.NotificationCount{
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
20 changes: 17 additions & 3 deletions biz/infrastructure/mapper/notification/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion biz/infrastructure/mapper/slider/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit a96e788

Please sign in to comment.