app

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2022 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Cfg configs.Config

	Store sessions.Store
	// contains filtered or unexported fields
}

func New

func New(
	cfg configs.Config,
	logger *logger.Logger,
	repo Repository,
	store sessions.Store,
) (*App, error)

func (*App) AuthenticateGothUser

func (a *App) AuthenticateGothUser(ctx context.Context, gu *goth.User) (*domain.User, error)

AuthenticateGothUser creates new user or returns existsing one. It relies on goth authetication to verify user has access to that profile and thus doesn't check password.

func (*App) CreateChallengeFromArgs

func (a *App) CreateChallengeFromArgs(ctx context.Context, args domain.CreateChallengeArgs, strict bool) (*domain.Challenge, error)

func (*App) CreateOrUpdateUserSession

func (a *App) CreateOrUpdateUserSession(req *http.Request, user *domain.User, withOAuth bool, setActiveStatus bool) (*domain.UserSession, error)

func (*App) CreatePrediction

func (a *App) CreatePrediction(ctx context.Context, pred *domain.Prediction) (*domain.Prediction, error)

func (*App) CreateUser

func (a *App) CreateUser(ctx context.Context, u *domain.User) (*domain.User, error)

func (*App) CreateUserFromGoth

func (a *App) CreateUserFromGoth(ctx context.Context, gu *goth.User) (*domain.User, error)

func (*App) CreateUserSession

func (a *App) CreateUserSession(req *http.Request, user *domain.User) (*domain.UserSession, error)

func (*App) FilterChallenges

func (a *App) FilterChallenges(ctx context.Context, args *domain.FilterChallengesArgs) ([]*domain.Challenge, int, error)

func (*App) FilterUserChallenges

func (a *App) FilterUserChallenges(ctx context.Context, args *domain.FilterChallengesArgs) ([]*domain.Challenge, int, error)

func (*App) GetChallengeByContent

func (a *App) GetChallengeByContent(ctx context.Context, content string) (*domain.Challenge, error)

func (*App) GetChallengeByID

func (a *App) GetChallengeByID(ctx context.Context, id uuid.UUID, userID uuid.UUID) (*domain.Challenge, error)

func (*App) GetChallengesByAuthor added in v0.0.3

func (a *App) GetChallengesByAuthor(ctx context.Context, authorID uuid.UUID, limit, offset int) ([]*domain.Challenge, int, error)

func (*App) GetClosingChallenges

func (a *App) GetClosingChallenges(ctx context.Context) ([]*domain.Challenge, error)

func (*App) GetPredictionByUserAndChallenge

func (a *App) GetPredictionByUserAndChallenge(ctx context.Context, userID, challengeID uuid.UUID) (*domain.Prediction, error)

func (*App) GetRandomFalseChallenges

func (a *App) GetRandomFalseChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)

func (*App) GetRandomFinishedChallenges

func (a *App) GetRandomFinishedChallenges(ctx context.Context) ([]*domain.Challenge, error)

func (*App) GetRandomOngoingChallenges

func (a *App) GetRandomOngoingChallenges(ctx context.Context, userID uuid.UUID, limit int) ([]*domain.Challenge, error)

func (*App) GetRandomPendingChallenges

func (a *App) GetRandomPendingChallenges(ctx context.Context) ([]*domain.Challenge, error)

func (*App) GetRandomTrueChallenges

func (a *App) GetRandomTrueChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)

func (*App) GetSystemSummary

func (a *App) GetSystemSummary(ctx context.Context) (*domain.SystemSymmary, error)

func (*App) GetUserByEmail

func (a *App) GetUserByEmail(ctx context.Context, email string) (*domain.User, error)

func (*App) GetUserBySession

func (a *App) GetUserBySession(req *http.Request) (*domain.User, error)

func (*App) GetUserSummary

func (a *App) GetUserSummary(ctx context.Context, userID uuid.UUID) (*domain.UserSummary, error)

func (*App) LiveSessionID

func (a *App) LiveSessionID(req *http.Request) (string, error)

func (*App) LogoutUser

func (a *App) LogoutUser(ctx context.Context) error

func (*App) ResetSession added in v0.0.3

func (a *App) ResetSession(res http.ResponseWriter, req *http.Request) error

func (*App) SetChallengeOutcome

func (a *App) SetChallengeOutcome(ctx context.Context, id uuid.UUID, outcome bool, proofs []*domain.Proof) error

func (*App) UpdateChallengeByID

func (a *App) UpdateChallengeByID(ctx context.Context, id uuid.UUID, args *domain.CreateChallengeArgs) (*domain.Challenge, error)

func (*App) UpdateSystemSummaryJob

func (a *App) UpdateSystemSummaryJob()

func (*App) ValidateUserPassword

func (a *App) ValidateUserPassword(ctx context.Context, u *domain.User) (bool, error)

type Repository

type Repository interface {
	// challenge
	CreateChallenge(context.Context, *domain.Challenge) (*domain.Challenge, error)
	UpdateChallengeByID(context.Context, *domain.Challenge) (*domain.Challenge, error)
	SetChallengeOutcome(ctx context.Context, id uuid.UUID, outcome bool, proofs []*domain.Proof) error
	CreateOrUpdateChallengeByContent(context.Context, *domain.Challenge) (*domain.Challenge, error)
	GetChallengeByContent(context.Context, string) (*domain.Challenge, error)
	GetChallengeByID(ctx context.Context, id uuid.UUID, userID uuid.UUID) (*domain.Challenge, error)
	GetRandomFinishedChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)
	GetRandomOngoingChallenges(ctx context.Context, limit int, userID uuid.UUID) ([]*domain.Challenge, error)
	GetClosingChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)
	GetRandomPendingChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)
	FilterUserChallenges(ctx context.Context, args *domain.FilterChallengesArgs) ([]*domain.Challenge, int, error)
	FilterChallenges(context.Context, *domain.FilterChallengesArgs) ([]*domain.Challenge, int, error)
	GetRandomTrueChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)
	GetRandomFalseChallenges(ctx context.Context, limit int) ([]*domain.Challenge, error)
	GetChallengesByAuthor(ctx context.Context, authorID uuid.UUID, limit, offset int) ([]*domain.Challenge, int, error)

	// user
	IfEmailRegistered(context.Context, string) (bool, error)
	GetUserByEmail(context.Context, string) (*domain.User, error)
	GetUserByID(context.Context, uuid.UUID) (*domain.User, error)
	CreateUser(context.Context, *domain.User) (*domain.User, error)
	GetUserSummary(ctx context.Context, userID uuid.UUID) (*domain.UserSummary, error)

	// user session
	IfSessionRegistered(context.Context, *domain.UserSession) (bool, error)
	CreateUserSession(context.Context, *domain.UserSession) (*domain.UserSession, error)
	CreateOrUpdateUserSession(context.Context, *domain.UserSession) (*domain.UserSession, error)
	UpdateUserSessionLastActivityBySID(context.Context, string) error
	GetUserBySession(context.Context, *domain.UserSession) (*domain.User, error)

	// badge
	CreateOrUpdateBadgeByType(context.Context, *domain.Badge) (*domain.Badge, error)

	// prediction
	CreatePrediction(context.Context, *domain.Prediction) (*domain.Prediction, error)
	GetPredictionByUserAndChallenge(ctx context.Context, userID, challengeID uuid.UUID) (*domain.Prediction, error)

	// for system summary
	GetChallengeCount(ctx context.Context) (int, error)
	GetOngoingChallengeCount(ctx context.Context) (int, error)
	GetFinishedChallengeCount(ctx context.Context) (int, error)
	GetUserCount(ctx context.Context) (int, error)
	GetPredictionCount(ctx context.Context) (int, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL