feat(user): add unscoped filter to include soft-deleted records in user queries
This commit is contained in:
parent
a9c832cb7c
commit
67f16ead82
@ -19,6 +19,7 @@ type (
|
|||||||
Size int `form:"size"`
|
Size int `form:"size"`
|
||||||
Search string `form:"search,omitempty"`
|
Search string `form:"search,omitempty"`
|
||||||
UserId *int64 `form:"user_id,omitempty"`
|
UserId *int64 `form:"user_id,omitempty"`
|
||||||
|
Unscoped bool `form:"unscoped,omitempty"`
|
||||||
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
||||||
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ func (l *GetUserListLogic) GetUserList(req *types.GetUserListRequest) (*types.Ge
|
|||||||
list, total, err := l.svcCtx.UserModel.QueryPageList(l.ctx, req.Page, req.Size, &user.UserFilterParams{
|
list, total, err := l.svcCtx.UserModel.QueryPageList(l.ctx, req.Page, req.Size, &user.UserFilterParams{
|
||||||
UserId: req.UserId,
|
UserId: req.UserId,
|
||||||
Search: req.Search,
|
Search: req.Search,
|
||||||
|
Unscoped: req.Unscoped,
|
||||||
SubscribeId: req.SubscribeId,
|
SubscribeId: req.SubscribeId,
|
||||||
UserSubscribeId: req.UserSubscribeId,
|
UserSubscribeId: req.UserSubscribeId,
|
||||||
Order: "DESC",
|
Order: "DESC",
|
||||||
|
|||||||
@ -62,6 +62,7 @@ type UserFilterParams struct {
|
|||||||
SubscribeId *int64
|
SubscribeId *int64
|
||||||
UserSubscribeId *int64
|
UserSubscribeId *int64
|
||||||
Order string // Order by id, e.g., "desc"
|
Order string // Order by id, e.g., "desc"
|
||||||
|
Unscoped bool // Whether to include soft-deleted records
|
||||||
}
|
}
|
||||||
|
|
||||||
type customUserLogicModel interface {
|
type customUserLogicModel interface {
|
||||||
@ -148,6 +149,9 @@ func (m *customUserModel) QueryPageList(ctx context.Context, page, size int, fil
|
|||||||
if filter.Order != "" {
|
if filter.Order != "" {
|
||||||
conn = conn.Order(fmt.Sprintf("user.id %s", filter.Order))
|
conn = conn.Order(fmt.Sprintf("user.id %s", filter.Order))
|
||||||
}
|
}
|
||||||
|
if filter.Unscoped {
|
||||||
|
conn = conn.Unscoped()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return conn.Model(&User{}).Group("user.id").Count(&total).Limit(size).Offset((page - 1) * size).Preload("UserDevices").Preload("AuthMethods").Find(&list).Error
|
return conn.Model(&User{}).Group("user.id").Count(&total).Limit(size).Offset((page - 1) * size).Preload("UserDevices").Preload("AuthMethods").Find(&list).Error
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1043,6 +1043,7 @@ type GetUserListRequest struct {
|
|||||||
Size int `form:"size"`
|
Size int `form:"size"`
|
||||||
Search string `form:"search,omitempty"`
|
Search string `form:"search,omitempty"`
|
||||||
UserId *int64 `form:"user_id,omitempty"`
|
UserId *int64 `form:"user_id,omitempty"`
|
||||||
|
Unscoped bool `form:"unscoped,omitempty"`
|
||||||
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
SubscribeId *int64 `form:"subscribe_id,omitempty"`
|
||||||
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
UserSubscribeId *int64 `form:"user_subscribe_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user