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 returns a list of all the valid invites
|
||||||
List(ctx context.Context) ([]Invite, error)
|
List(ctx context.Context) ([]Invite, error)
|
||||||
|
|
||||||
// Count returns the total number of invites.
|
// Count returns the total number of invites, optionally excluding inactive invites
|
||||||
Count(context.Context) (uint, error)
|
Count(ctx context.Context, onlyActive bool) (uint, error)
|
||||||
|
|
||||||
// CountActive returns the total number of active invites.
|
|
||||||
CountActive(context.Context) (uint, error)
|
|
||||||
|
|
||||||
// Revoke removes a active invite and invalidates it for future use.
|
// Revoke removes a active invite and invalidates it for future use.
|
||||||
Revoke(ctx context.Context, id int64) error
|
Revoke(ctx context.Context, id int64) error
|
||||||
|
|
|
@ -250,18 +250,12 @@ func (i Invites) List(ctx context.Context) ([]roomdb.Invite, error) {
|
||||||
return invs, nil
|
return invs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Invites) Count(ctx context.Context) (uint, error) {
|
func (i Invites) Count(ctx context.Context, onlyActive bool) (uint, error) {
|
||||||
count, err := models.Invites().Count(ctx, i.db)
|
queryMod := qm.Where("1")
|
||||||
if err != nil {
|
if onlyActive {
|
||||||
return 0, err
|
queryMod = qm.Where("active = true")
|
||||||
}
|
}
|
||||||
return uint(count), nil
|
count, err := models.Invites(queryMod).Count(ctx, i.db)
|
||||||
}
|
|
||||||
|
|
||||||
func (i Invites) CountActive(ctx context.Context) (uint, error) {
|
|
||||||
count, err := models.Invites(
|
|
||||||
qm.Where("active = true"),
|
|
||||||
).Count(ctx, i.db)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to count active invites: %w", err)
|
return nil, fmt.Errorf("failed to count active invites: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue