34 lines
1.5 KiB
Go
34 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
// ErrLastAdmin is returned when demoting the only remaining admin.
|
|
var ErrLastAdmin = errors.New("cannot demote the last admin")
|
|
|
|
// 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)
|
|
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
|
|
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)
|
|
Vote(ctx context.Context, userID, questionID string, value int) error
|
|
GetAnswer(ctx context.Context, questionID string) (*Answer, error)
|
|
UpsertAnswer(ctx context.Context, questionID, authorID, body string) error
|
|
HideQuestion(ctx context.Context, id string) error
|
|
UpdateProfile(ctx context.Context, userID, state, avatarURL string) error
|
|
ListQuestionsByAuthor(ctx context.Context, authorID string) ([]RankedQuestion, error)
|
|
ListQuestionsAnsweredBy(ctx context.Context, adminID string) ([]RankedQuestion, error)
|
|
}
|
|
|
|
// Compile-time check: *Store implements DB.
|
|
var _ DB = (*Store)(nil)
|