Files
Completed/internal/db/models.go
T
SansanandClaude Sonnet 5 384c4a7217 Restrict platform-list edits to admins
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>
2026-10-03 11:39:21 +02:00

51 lines
939 B
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
package db
import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
type Game struct {
ID uuid.UUID
UserID uuid.UUID
PlatformID uuid.UUID
Name string
Score int32
ReleaseDate pgtype.Date
Finished pgtype.Date
UpdatedAt pgtype.Timestamptz
DeletedAt pgtype.Timestamptz
ChangeSeq int64
}
type Platform struct {
ID uuid.UUID
Name string
UpdatedAt pgtype.Timestamptz
DeletedAt pgtype.Timestamptz
ChangeSeq int64
}
type Session struct {
TokenHash []byte
UserID uuid.UUID
CreatedAt pgtype.Timestamptz
ExpiresAt pgtype.Timestamptz
LastSeenAt pgtype.Timestamptz
}
type User struct {
ID uuid.UUID
Email string
PasswordHash string
Name string
Bio pgtype.Text
IsAdmin bool
CreatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
}