Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修改system参数 #4

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/cloudmind-system.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions biz/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ type SystemServerImpl struct {
SystemService service.SystemService
}

func (s *SystemServerImpl) UpateNotifications(ctx context.Context, req *system.UpdateNotificationsReq) (resp *system.UpdateNotificationsResp, err error) {
return s.SystemService.UpateNotifications(ctx, req)
}

func (s *SystemServerImpl) DeleteNotifications(ctx context.Context, req *system.DeleteNotificationsReq) (resp *system.DeleteNotificationsResp, err error) {
return s.SystemService.DeleteNotifications(ctx, req)
}

func (s *SystemServerImpl) GetSliders(ctx context.Context, req *system.GetSlidersReq) (resp *system.GetSlidersResp, err error) {
return s.SystemService.GetSliders(ctx, req)
}
Expand All @@ -29,18 +37,10 @@ func (s *SystemServerImpl) DeleteSlider(ctx context.Context, req *system.DeleteS
return s.SystemService.DeleteSlider(ctx, req)
}

func (s *SystemServerImpl) ReadNotifications(ctx context.Context, req *system.ReadNotificationsReq) (res *system.ReadNotificationsResp, err error) {
return s.SystemService.ReadNotifications(ctx, req)
}

func (s *SystemServerImpl) GetNotifications(ctx context.Context, req *system.GetNotificationsReq) (res *system.GetNotificationsResp, err error) {
return s.SystemService.GetNotifications(ctx, req)
}

func (s *SystemServerImpl) CleanNotification(ctx context.Context, req *system.CleanNotificationReq) (res *system.CleanNotificationResp, err error) {
return s.SystemService.CleanNotification(ctx, req)
}

func (s *SystemServerImpl) GetNotificationCount(ctx context.Context, req *system.GetNotificationCountReq) (res *system.GetNotificationCountResp, err error) {
return s.SystemService.GetNotificationCount(ctx, req)
}
Expand Down
100 changes: 65 additions & 35 deletions biz/application/service/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,78 @@ import (
gensystem "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/system"
"github.com/google/wire"
"github.com/samber/lo"
"go.mongodb.org/mongo-driver/bson/primitive"
)

type SystemService interface {
GetNotifications(ctx context.Context, req *gensystem.GetNotificationsReq) (resp *gensystem.GetNotificationsResp, err error)
GetNotificationCount(ctx context.Context, req *gensystem.GetNotificationCountReq) (resp *gensystem.GetNotificationCountResp, 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)
UpdateSlider(ctx context.Context, req *gensystem.UpdateSliderReq) (resp *gensystem.UpdateSliderResp, err error)
CreateSlider(ctx context.Context, req *gensystem.CreateSliderReq) (resp *gensystem.CreateSliderResp, err error)
GetSliders(ctx context.Context, req *gensystem.GetSlidersReq) (resp *gensystem.GetSlidersResp, err error)
DeleteNotifications(ctx context.Context, req *gensystem.DeleteNotificationsReq) (resp *gensystem.DeleteNotificationsResp, err error)
UpateNotifications(ctx context.Context, req *gensystem.UpdateNotificationsReq) (resp *gensystem.UpdateNotificationsResp, err error)
}

type SystemServiceImpl struct {
NotificationMongoMapper notificationmapper.INotificationMongoMapper
SliderMongoMapper slidermapper.ISliderMongoMapper
}

func (s *SystemServiceImpl) DeleteNotifications(ctx context.Context, req *gensystem.DeleteNotificationsReq) (resp *gensystem.DeleteNotificationsResp, err error) {
if err = s.NotificationMongoMapper.DeleteNotifications(ctx, &notificationmapper.FilterOptions{
OnlyUserId: req.OnlyUserId,
OnlyType: req.OnlyType,
OnlyIsRead: req.OnlyIsRead,
OnlyNotificationIds: req.OnlyNotificationIds,
}); err != nil {
return resp, err
}
return resp, nil
}

func (s *SystemServiceImpl) UpateNotifications(ctx context.Context, req *gensystem.UpdateNotificationsReq) (resp *gensystem.UpdateNotificationsResp, err error) {
if err = s.NotificationMongoMapper.UpdateNotifications(ctx, &notificationmapper.FilterOptions{
OnlyUserId: req.OnlyUserId,
OnlyType: req.OnlyType,
OnlyIsRead: req.OnlyIsRead,
OnlyNotificationIds: req.OnlyNotificationIds,
}, req.IsRead); err != nil {
return resp, err
}
return resp, nil
}

func (s *SystemServiceImpl) DeleteSlider(ctx context.Context, req *gensystem.DeleteSliderReq) (resp *gensystem.DeleteSliderResp, err error) {
resp = new(gensystem.DeleteSliderResp)
if err = s.SliderMongoMapper.DeleteOne(ctx, req.SliderId); err != nil {
return resp, err
}
return resp, nil
}

func (s *SystemServiceImpl) UpdateSlider(ctx context.Context, req *gensystem.UpdateSliderReq) (resp *gensystem.UpdateSliderResp, err error) {
resp = new(gensystem.UpdateSliderResp)
if err = s.SliderMongoMapper.UpdateOne(ctx, convertor.SliderToSliderMapper(req.Slider)); err != nil {
oid, _ := primitive.ObjectIDFromHex(req.SliderId)
if err = s.SliderMongoMapper.UpdateOne(ctx, &slidermapper.Slider{
ID: oid,
ImageUrl: req.ImageUrl,
LinkUrl: req.LinkUrl,
Type: req.Type,
IsPublic: req.IsPublic,
}); err != nil {
return resp, err
}
return resp, nil
}

func (s *SystemServiceImpl) CreateSlider(ctx context.Context, req *gensystem.CreateSliderReq) (resp *gensystem.CreateSliderResp, err error) {
resp = new(gensystem.CreateSliderResp)
if err = s.SliderMongoMapper.InsertOne(ctx, convertor.SliderToSliderMapper(req.Slider)); err != nil {
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
}
return resp, nil
Expand All @@ -56,74 +90,70 @@ func (s *SystemServiceImpl) CreateSlider(ctx context.Context, req *gensystem.Cre
func (s *SystemServiceImpl) GetSliders(ctx context.Context, req *gensystem.GetSlidersReq) (resp *gensystem.GetSlidersResp, err error) {
resp = new(gensystem.GetSlidersResp)
p := pconvertor.PaginationOptionsToModelPaginationOptions(req.PaginationOptions)
sliders, total, err := s.SliderMongoMapper.GetSlidersAndCount(ctx, convertor.SliderFilterOptionsToMapper(req.FilterOptions), p, mongop.IdCursorType)
sliders, total, err := s.SliderMongoMapper.GetSlidersAndCount(ctx, &slidermapper.FilterOptions{
OnlyType: req.OnlyType,
OnlyIsPublic: req.OnlyIsPublic,
}, p, mongop.IdCursorType)
if err != nil {
return resp, err
}
if p.LastToken != nil {
resp.Token = *p.LastToken
}

resp.Sliders = lo.Map[*slidermapper.Slider, *gensystem.Slider](sliders,
func(item *slidermapper.Slider, _ int) *gensystem.Slider {
return convertor.SliderMapperToSlider(item)
})

if p.LastToken != nil {
resp.Token = *p.LastToken
}
resp.Total = total
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)
notifications, total, err := s.NotificationMongoMapper.GetNotificationsAndCount(ctx, convertor.NotificationFilterOptionsToMapper(req.FilterOptions), p, mongop.IdCursorType)
notifications, total, err := s.NotificationMongoMapper.GetNotificationsAndCount(ctx, &notificationmapper.FilterOptions{
OnlyUserId: req.OnlyUserId,
OnlyType: req.OnlyType,
OnlyIsRead: req.OnlyIsRead,
}, p, mongop.IdCursorType)
if err != nil {
return resp, err
}
if p.LastToken != nil {
resp.Token = *p.LastToken
}
resp.Notifications = lo.Map[*notificationmapper.Notification, *gensystem.Notification](notifications,
func(item *notificationmapper.Notification, index int) *gensystem.Notification {
return convertor.NotificationMapperToNotification(item)
})
resp.Total = total
return resp, nil
}

func (s *SystemServiceImpl) CleanNotification(ctx context.Context, req *gensystem.CleanNotificationReq) (resp *gensystem.CleanNotificationResp, err error) {
resp = new(gensystem.CleanNotificationResp)
if err = s.NotificationMongoMapper.CleanNotification(ctx, req.UserId); err != nil {
return resp, err
if p.LastToken != nil {
resp.Token = *p.LastToken
}
resp.Total = total
return resp, nil
}

func (s *SystemServiceImpl) GetNotificationCount(ctx context.Context, req *gensystem.GetNotificationCountReq) (resp *gensystem.GetNotificationCountResp, err error) {
resp = new(gensystem.GetNotificationCountResp)
if resp.Total, err = s.NotificationMongoMapper.Count(ctx, convertor.NotificationFilterOptionsToMapper(req.FilterOptions)); err != nil {
if resp.Total, err = s.NotificationMongoMapper.Count(ctx, &notificationmapper.FilterOptions{
OnlyUserId: req.OnlyUserId,
OnlyType: req.OnlyType,
OnlyIsRead: req.OnlyIsRead,
}); err != nil {
return resp, err
}
return resp, 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)
notifications := lo.Map[*gensystem.NotificationInfo, *notificationmapper.Notification](req.Notifications, func(item *gensystem.NotificationInfo, _ int) *notificationmapper.Notification {
return convertor.NotificationInfoToNotificationMapper(item)
})
if err = s.NotificationMongoMapper.InsertMany(ctx, notifications); err != nil {
return resp, err
}
return resp, nil
}

func (s *SystemServiceImpl) ReadNotifications(ctx context.Context, req *gensystem.ReadNotificationsReq) (resp *gensystem.ReadNotificationsResp, err error) {
resp = new(gensystem.ReadNotificationsResp)
if err = s.NotificationMongoMapper.ReadNotifications(ctx, convertor.NotificationFilterOptionsToMapper(req.FilterOptions)); err != nil {
return resp, err
}
return resp, nil
}

var SystemSet = wire.NewSet(
wire.Struct(new(SystemServiceImpl), "*"),
wire.Bind(new(SystemService), new(*SystemServiceImpl)),
Expand Down
42 changes: 2 additions & 40 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import (
notificationmapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/notification"
slidermapper "github.com/CloudStriver/cloudmind-system/biz/infrastructure/mapper/slider"
gensystem "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/system"
"go.mongodb.org/mongo-driver/bson/primitive"
)

func NotificationToNotificationMapper(in *gensystem.Notification) *notificationmapper.Notification {
oid, _ := primitive.ObjectIDFromHex(in.NotificationId)
func NotificationInfoToNotificationMapper(in *gensystem.NotificationInfo) *notificationmapper.Notification {
return &notificationmapper.Notification{
ID: oid,
TargetUserId: in.TargetUserId,
SourceUserId: in.SourceUserId,
SourceContentId: in.SourceContentId,
Expand All @@ -30,36 +27,11 @@ func NotificationMapperToNotification(in *notificationmapper.Notification) *gens
TargetType: in.TargetType,
Type: in.Type,
Text: in.Text,
CreateAt: in.CreateAt.UnixMilli(),
CreateTime: in.CreateAt.UnixMilli(),
IsRead: in.IsRead,
}
}

func NotificationFilterOptionsToMapper(in *gensystem.NotificationFilterOptions) *notificationmapper.FilterOptions {
if in == nil {
return &notificationmapper.FilterOptions{}
}
return &notificationmapper.FilterOptions{
OnlyUserId: in.OnlyUserId,
OnlyType: in.OnlyType,
OnlyTargetType: in.OnlyTargetType,
OnlyFirstId: in.OnlyFirstId,
OnlyLastId: in.OnlyLastId,
OnlyIsRead: in.OnlyIsRead,
}
}

func SliderToSliderMapper(in *gensystem.Slider) *slidermapper.Slider {
oid, _ := primitive.ObjectIDFromHex(in.SliderId)
return &slidermapper.Slider{
ID: oid,
ImageUrl: in.ImageUrl,
LinkUrl: in.LinkUrl,
Type: in.Type,
IsPublic: in.IsPublic,
}
}

func SliderMapperToSlider(in *slidermapper.Slider) *gensystem.Slider {
return &gensystem.Slider{
SliderId: in.ID.Hex(),
Expand All @@ -71,13 +43,3 @@ func SliderMapperToSlider(in *slidermapper.Slider) *gensystem.Slider {
UpdateTime: in.UpdateAt.UnixMilli(),
}
}

func SliderFilterOptionsToMapper(in *gensystem.SliderFilterOptions) *slidermapper.FilterOptions {
if in == nil {
return &slidermapper.FilterOptions{}
}
return &slidermapper.FilterOptions{
OnlyType: in.OnlyType,
OnlyIsPublic: in.OnlyIsPublic,
}
}
38 changes: 16 additions & 22 deletions biz/infrastructure/mapper/notification/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +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
OnlyType *int64
OnlyTargetType *int64
OnlyFirstId *string
OnlyLastId *string
OnlyIsRead *bool
OnlyUserId *string
OnlyType *int64
OnlyIsRead *bool
OnlyNotificationIds []string
}

type MongoFilter struct {
Expand All @@ -30,12 +29,21 @@ func MakeBsonFilter(options *FilterOptions) bson.M {
func (f *MongoFilter) toBson() bson.M {
f.CheckOnlyUserId()
f.CheckOnlyType()
f.CheckOnlyTargetType()
f.CheckRange()
f.CheckOnlyIsRead()
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, index int) primitive.ObjectID {
oid, _ := primitive.ObjectIDFromHex(item)
return oid
}),
}
}
}

func (f *MongoFilter) CheckOnlyUserId() {
if f.OnlyUserId != nil {
f.m[consts.TargetUserId] = *f.OnlyUserId
Expand All @@ -48,20 +56,6 @@ func (f *MongoFilter) CheckOnlyType() {
}
}

func (f *MongoFilter) CheckOnlyTargetType() {
if f.OnlyTargetType != nil {
f.m[consts.TargetType] = *f.OnlyTargetType
}
}

func (f *MongoFilter) CheckRange() {
if f.OnlyLastId != nil && f.OnlyFirstId != nil {
firstId, _ := primitive.ObjectIDFromHex(*f.OnlyFirstId)
lastId, _ := primitive.ObjectIDFromHex(*f.OnlyLastId)
f.m[consts.ID] = bson.M{"$gte": firstId, "$lte": lastId}
}
}

func (f *MongoFilter) CheckOnlyIsRead() {
if f.OnlyIsRead != nil {
f.m[consts.IsRead] = bson.M{"$exists": *f.OnlyIsRead}
Expand Down
Loading
Loading