Changes:
Добавлено количество элементов для эндпоинта /account/pagination dal.go: GetAccountPage добавлен запрос в бд о количество элементов. model.go добавлена модель AccountPage для запроса dal GetAccountPage
This commit is contained in:
parent
f20868747a
commit
ca1b898d79
@ -881,7 +881,7 @@ func (d *DAL) GetAccountByUserID(ctx context.Context, userId string) (*model.Acc
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (d *DAL) GetAccountPage(ctx context.Context, search string, offset, limit int64) ([]model.Account, error) {
|
||||
func (d *DAL) GetAccountPage(ctx context.Context, search string, offset, limit int64) (*model.AccountPage, error) {
|
||||
var query bson.M
|
||||
if search != "" {
|
||||
query = bson.M{
|
||||
@ -891,6 +891,8 @@ func (d *DAL) GetAccountPage(ctx context.Context, search string, offset, limit i
|
||||
}
|
||||
}
|
||||
|
||||
count, err := d.colAcc.CountDocuments(ctx, query)
|
||||
|
||||
sort := bson.D{{"CreatedAt", -1}}
|
||||
|
||||
cur, err := d.colAcc.Find(ctx, query, options.Find().SetLimit(limit).SetSkip(limit*offset).SetSort(sort))
|
||||
@ -898,12 +900,12 @@ func (d *DAL) GetAccountPage(ctx context.Context, search string, offset, limit i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []model.Account
|
||||
if err := cur.All(ctx, &result); err != nil {
|
||||
var items []model.Account
|
||||
if err := cur.All(ctx, &items); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return &model.AccountPage{Count: count, Items: items}, nil
|
||||
}
|
||||
|
||||
func (d *DAL) SetAccountRole(ctx context.Context, userId, role string) (*model.Account, error) {
|
||||
|
@ -51,6 +51,11 @@ type Account struct {
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
type AccountPage struct {
|
||||
Count int64 `json:"count" bson:"count"`
|
||||
Items []Account `json:"items"`
|
||||
}
|
||||
|
||||
type RespErrorValidate struct {
|
||||
Field string `json:"field"`
|
||||
Tag string `json:"tag"`
|
||||
|
Loading…
Reference in New Issue
Block a user