combined Invites.Count and Invites.CountActive
This commit is contained in:
parent
922fa34302
commit
5d3ccc7184
@ -158,11 +158,8 @@ type InvitesService interface {
|
||||
// List returns a list of all the valid invites
|
||||
List(ctx context.Context) ([]Invite, error)
|
||||
|
||||
// Count returns the total number of invites.
|
||||
Count(context.Context) (uint, error)
|
||||
|
||||
// CountActive returns the total number of active invites.
|
||||
CountActive(context.Context) (uint, error)
|
||||
// Count returns the total number of invites, optionally excluding inactive invites
|
||||
Count(ctx context.Context, onlyActive bool) (uint, error)
|
||||
|
||||
// Revoke removes a active invite and invalidates it for future use.
|
||||
Revoke(ctx context.Context, id int64) error
|
||||
|
@ -250,18 +250,12 @@ func (i Invites) List(ctx context.Context) ([]roomdb.Invite, error) {
|
||||
return invs, nil
|
||||
}
|
||||
|
||||
func (i Invites) Count(ctx context.Context) (uint, error) {
|
||||
count, err := models.Invites().Count(ctx, i.db)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
func (i Invites) Count(ctx context.Context, onlyActive bool) (uint, error) {
|
||||
queryMod := qm.Where("1")
|
||||
if onlyActive {
|
||||
queryMod = qm.Where("active = true")
|
||||
}
|
||||
return uint(count), nil
|
||||
}
|
||||
|
||||
func (i Invites) CountActive(ctx context.Context) (uint, error) {
|
||||
count, err := models.Invites(
|
||||
qm.Where("active = true"),
|
||||
).Count(ctx, i.db)
|
||||
count, err := models.Invites(queryMod).Count(ctx, i.db)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (h dashboardHandler) overview(w http.ResponseWriter, req *http.Request) (in
|
||||
return nil, fmt.Errorf("failed to count members: %w", err)
|
||||
}
|
||||
|
||||
inviteCount, err := h.dbs.Invites.CountActive(ctx)
|
||||
inviteCount, err := h.dbs.Invites.Count(ctx, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to count active invites: %w", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user