34 lines
850 B
Go
34 lines
850 B
Go
package shared
|
|
|
|
import (
|
|
"context"
|
|
|
|
"galaxy/lobby/internal/domain/common"
|
|
"galaxy/lobby/internal/domain/membership"
|
|
"galaxy/lobby/internal/ports"
|
|
)
|
|
|
|
// CountActiveMemberships returns the number of memberships in
|
|
// membership.StatusActive attached to gameID. It is used by the
|
|
// application services (submitapplication, approveapplication) to
|
|
// evaluate the max_players + start_gap_players roster cap and the
|
|
// gap-window activation threshold without each service re-implementing
|
|
// the same scan + filter.
|
|
func CountActiveMemberships(
|
|
ctx context.Context,
|
|
store ports.MembershipStore,
|
|
gameID common.GameID,
|
|
) (int, error) {
|
|
records, err := store.GetByGame(ctx, gameID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
count := 0
|
|
for _, record := range records {
|
|
if record.Status == membership.StatusActive {
|
|
count++
|
|
}
|
|
}
|
|
return count, nil
|
|
}
|