Skip to content

Commit

Permalink
fix: token
Browse files Browse the repository at this point in the history
  • Loading branch information
Cbgogogog committed Dec 24, 2023
1 parent 1cfc3f4 commit a5579f2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
18 changes: 11 additions & 7 deletions biz/application/service/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,16 @@ func (s *SystemServiceImpl) DeleteCommunity(ctx context.Context, req *system.Del
}

func (s *SystemServiceImpl) ListNotification(ctx context.Context, req *system.ListNotificationReq) (resp *system.ListNotificationResp, err error) {
resp = new(system.ListNotificationResp)

notification, total, err := s.NotificationModel.ListNotification(ctx, req, mongop.IdCursorType)
var notifications []*db.Notification
filter := util.ParseNotificationFilter(req)
p := util.ParsePagination(req.PaginationOptions)
notifications, resp.Total, err = s.NotificationModel.ListNotification(ctx, filter, p, mongop.IdCursorType)
if err != nil {
return nil, err
}
notRead, err := s.NotificationModel.CountNotification(ctx, &system.CountNotificationReq{
resp.NotRead, err = s.NotificationModel.CountNotification(ctx, &system.CountNotificationReq{
UserId: req.GetUserId(),
Type: req.Type,
TargetType: req.TargetType,
Expand All @@ -607,11 +611,11 @@ func (s *SystemServiceImpl) ListNotification(ctx context.Context, req *system.Li
return nil, err
}

return &system.ListNotificationResp{
Notifications: util.ConvertNotifications(notification),
NotRead: notRead,
Total: total,
}, nil
if p.LastToken != nil {
resp.Token = *p.LastToken
}
resp.Notifications = util.ConvertNotifications(notifications)
return resp, nil
}

func (s *SystemServiceImpl) CountNotification(ctx context.Context, req *system.CountNotificationReq) (resp *system.CountNotificationResp, err error) {
Expand Down
18 changes: 6 additions & 12 deletions biz/infrastructure/mapper/notification/notification_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/xh-polaris/meowchat-system/biz/infrastructure/consts"
"github.com/xh-polaris/meowchat-system/biz/infrastructure/data/db"
"github.com/xh-polaris/meowchat-system/biz/infrastructure/mapper"
"github.com/xh-polaris/meowchat-system/biz/infrastructure/util"
)

const (
Expand All @@ -31,7 +30,7 @@ type (
// and implement the added methods in customNotificationModel.
NotificationModel interface {
notificationModel
ListNotification(ctx context.Context, req *system.ListNotificationReq, sorter mongop.MongoCursor) ([]*db.Notification, int64, error)
ListNotification(ctx context.Context, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter mongop.MongoCursor) ([]*db.Notification, int64, error)
CleanNotification(ctx context.Context, userId string) error
ReadNotification(ctx context.Context, notificationId string) error
CountNotification(ctx context.Context, req *system.CountNotificationReq) (int64, error)
Expand All @@ -43,25 +42,20 @@ type (
}
)

func (m customNotificationModel) ListNotification(ctx context.Context, req *system.ListNotificationReq, sorter mongop.MongoCursor) ([]*db.Notification, int64, error) {
func (m customNotificationModel) ListNotification(ctx context.Context, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter mongop.MongoCursor) ([]*db.Notification, int64, error) {
var data []*db.Notification
popts := util.ParsePagination(req.GetPaginationOptions())
p := mongop.NewMongoPaginator(pagination.NewRawStore(sorter), popts)
f := &FilterOptions{
OnlyUserId: req.UserId,
OnlyType: req.Type,
OnlyTargetType: req.TargetType,
}
filter := makeMongoFilter(f)

filter := makeMongoFilter(fopts)
sort, err := p.MakeSortOptions(ctx, filter)
if err != nil {
return nil, 0, err
}

if err = m.conn.Find(ctx, &data, filter, &options.FindOptions{
Sort: sort,
Limit: req.PaginationOptions.Limit,
Skip: req.PaginationOptions.Offset,
Limit: popts.Limit,
Skip: popts.Offset,
}); err != nil {
return nil, 0, err
}
Expand Down
14 changes: 14 additions & 0 deletions biz/infrastructure/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"

"github.com/xh-polaris/meowchat-system/biz/infrastructure/data/db"
"github.com/xh-polaris/meowchat-system/biz/infrastructure/mapper/notification"
)

func ConvertAdmin(in *db.Admin) *system.Admin {
Expand Down Expand Up @@ -114,3 +115,16 @@ func ParallelRun(fns ...func()) {
}
wg.Wait()
}

func ParseNotificationFilter(req *system.ListNotificationReq) (filter *notification.FilterOptions) {
if req == nil {
filter = &notification.FilterOptions{}
} else {
filter = &notification.FilterOptions{
OnlyUserId: req.UserId,
OnlyType: req.Type,
OnlyTargetType: req.TargetType,
}
}
return
}

0 comments on commit a5579f2

Please sign in to comment.