Address PR review: graceful shutdown, Role/NewUser, drop SQLite.
This commit is contained in:
+17
-2
@@ -8,15 +8,30 @@ import (
|
||||
// ErrLastAdmin is returned when demoting the only remaining admin.
|
||||
var ErrLastAdmin = errors.New("cannot demote the last admin")
|
||||
|
||||
// Role is a user privilege level stored in users.role.
|
||||
type Role string
|
||||
|
||||
const (
|
||||
RoleUser Role = "user"
|
||||
RoleAdmin Role = "admin"
|
||||
)
|
||||
|
||||
// NewUser is the input for CreateUser.
|
||||
type NewUser struct {
|
||||
Username string
|
||||
PasswordHash string
|
||||
Role Role
|
||||
}
|
||||
|
||||
// DB is the persistence API used by the web layer.
|
||||
// Named DB to avoid colliding with scs.Store.
|
||||
type DB interface {
|
||||
CreateUser(ctx context.Context, username, passwordHash string, asAdmin bool) (*User, error)
|
||||
CreateUser(ctx context.Context, user NewUser) (*User, error)
|
||||
UserByID(ctx context.Context, id string) (*User, error)
|
||||
UserByUsername(ctx context.Context, username string) (*User, error)
|
||||
CountAdmins(ctx context.Context) (int, error)
|
||||
ListUsers(ctx context.Context) ([]User, error)
|
||||
SetRole(ctx context.Context, userID, role string) error
|
||||
SetRole(ctx context.Context, userID string, role Role) error
|
||||
CreateQuestion(ctx context.Context, authorID, title, body, city string) (*RankedQuestion, error)
|
||||
ListHunt(ctx context.Context, huntDate, viewerID string) ([]RankedQuestion, error)
|
||||
GetQuestion(ctx context.Context, id, viewerID string) (*RankedQuestion, error)
|
||||
|
||||
Reference in New Issue
Block a user