Anyone authenticated can still read the shared platform list, but only an
admin may add, rename or delete from it.
- users.is_admin boolean, defaulting to false. The very first account ever
registered becomes an admin automatically (CreateUser's INSERT uses
NOT EXISTS (SELECT 1 FROM users) for is_admin), so there's always at
least one without manual setup; promoting anyone beyond that is a manual
UPDATE for now (documented in the migration's comment on the column).
- GetSessionAndUser, GetUserByEmail and GetUserByID now also select
is_admin, and it flows through to model.User (and so to
/api/auth/{register,login,me}'s response) and to the auth middleware's
authedUser.
- New requireAdminMiddleware + addAdminAuth, layered on top of the existing
auth middleware. Wired onto create/update/delete-platform; list/get stay
on plain addAuth, since reading the list only requires being logged in.
Verified end to end: the first registered user comes back is_admin:true,
the second false; the non-admin gets 403 on create/update/delete-platform
but 200 on list; the admin can do all of it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
42 lines
1.9 KiB
Go
42 lines
1.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Querier interface {
|
|
CreateGame(ctx context.Context, arg CreateGameParams) (CreateGameRow, error)
|
|
CreatePlatform(ctx context.Context, name string) (CreatePlatformRow, error)
|
|
CreateSession(ctx context.Context, arg CreateSessionParams) error
|
|
// The first account ever registered becomes an admin automatically; see
|
|
// the is_admin column's comment in db/migrations for why and the race this
|
|
// accepts. Everyone after that registers as a non-admin.
|
|
CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error)
|
|
DeleteGame(ctx context.Context, arg DeleteGameParams) (int64, error)
|
|
// Soft delete, so the FK on game.platform_id is never touched and never
|
|
// blocks this on its own; the NOT EXISTS guard is what stops a platform
|
|
// that still has active games - from any user, since the list is shared -
|
|
// from being deleted. Call GetPlatform first to tell "not found" apart from
|
|
// "blocked by games" when this affects 0 rows.
|
|
DeletePlatform(ctx context.Context, id uuid.UUID) (int64, error)
|
|
DeleteSession(ctx context.Context, tokenHash []byte) error
|
|
GetGame(ctx context.Context, arg GetGameParams) (GetGameRow, error)
|
|
GetPlatform(ctx context.Context, id uuid.UUID) (GetPlatformRow, error)
|
|
GetSessionAndUser(ctx context.Context, tokenHash []byte) (GetSessionAndUserRow, error)
|
|
GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error)
|
|
GetUserByID(ctx context.Context, id uuid.UUID) (GetUserByIDRow, error)
|
|
ListGames(ctx context.Context, userID uuid.UUID) ([]ListGamesRow, error)
|
|
ListPlatforms(ctx context.Context) ([]ListPlatformsRow, error)
|
|
TouchSession(ctx context.Context, tokenHash []byte) error
|
|
UpdateGame(ctx context.Context, arg UpdateGameParams) (UpdateGameRow, error)
|
|
UpdatePlatform(ctx context.Context, arg UpdatePlatformParams) (UpdatePlatformRow, error)
|
|
}
|
|
|
|
var _ Querier = (*Queries)(nil)
|