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
|
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
|
var query bson.M
|
||||||
if search != "" {
|
if search != "" {
|
||||||
query = bson.M{
|
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}}
|
sort := bson.D{{"CreatedAt", -1}}
|
||||||
|
|
||||||
cur, err := d.colAcc.Find(ctx, query, options.Find().SetLimit(limit).SetSkip(limit*offset).SetSort(sort))
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var result []model.Account
|
var items []model.Account
|
||||||
if err := cur.All(ctx, &result); err != nil {
|
if err := cur.All(ctx, &items); err != nil {
|
||||||
return nil, err
|
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) {
|
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"`
|
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AccountPage struct {
|
||||||
|
Count int64 `json:"count" bson:"count"`
|
||||||
|
Items []Account `json:"items"`
|
||||||
|
}
|
||||||
|
|
||||||
type RespErrorValidate struct {
|
type RespErrorValidate struct {
|
||||||
Field string `json:"field"`
|
Field string `json:"field"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
|
Loading…
Reference in New Issue
Block a user