logic

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PermissionAccountsSelfRead     = gorbac.NewStdPermission("accounts.self.read")
	PermissionAccountsSelfWrite    = gorbac.NewStdPermission("accounts.self.write")
	PermissionAccountsAllRead      = gorbac.NewStdPermission("accounts.all.read")
	PermissionAccountsAllWrite     = gorbac.NewStdPermission("accounts.all.write")
	PermissionProblemsSelfRead     = gorbac.NewStdPermission("problems.self.read")
	PermissionProblemsSelfWrite    = gorbac.NewStdPermission("problems.self.write")
	PermissionProblemsAllRead      = gorbac.NewStdPermission("problems.all.read")
	PermissionProblemsAllWrite     = gorbac.NewStdPermission("problems.all.write")
	PermissionTestCasesSelfRead    = gorbac.NewStdPermission("test_cases.self.read")
	PermissionTestCasesSelfWrite   = gorbac.NewStdPermission("test_cases.self.write")
	PermissionTestCasesAllRead     = gorbac.NewStdPermission("test_cases.all.read")
	PermissionTestCasesAllWrite    = gorbac.NewStdPermission("test_cases.all.write")
	PermissionSubmissionsSelfRead  = gorbac.NewStdPermission("submissions.self.read")
	PermissionSubmissionsSelfWrite = gorbac.NewStdPermission("submissions.self.write")
	PermissionSubmissionsAllRead   = gorbac.NewStdPermission("submissions.all.read")
	PermissionSubmissionsAllWrite  = gorbac.NewStdPermission("submissions.all.write")
	PermissionSettingsWrite        = gorbac.NewStdPermission("settings.write")
)

Functions

This section is empty.

Types

type Account

type Account interface {
	CreateFirstAccounts(ctx context.Context) error
	CreateAccount(ctx context.Context, in *rpc.CreateAccountRequest, token string) (*rpc.CreateAccountResponse, error)
	GetAccountList(ctx context.Context, in *rpc.GetAccountListRequest, token string) (*rpc.GetAccountListResponse, error)
	GetAccount(ctx context.Context, in *rpc.GetAccountRequest, token string) (*rpc.GetAccountResponse, error)
	UpdateAccount(ctx context.Context, in *rpc.UpdateAccountRequest, token string) (*rpc.UpdateAccountResponse, error)
	CreateSession(ctx context.Context, in *rpc.CreateSessionRequest) (*rpc.CreateSessionResponse, string, time.Time, error)
	GetSession(ctx context.Context, token string) (*rpc.GetSessionResponse, error)
	DeleteSession(ctx context.Context, token string) error
	IsAccountNameTaken(ctx context.Context, accountName string) (bool, error)
	WithDB(db *gorm.DB) Account
}

func NewAccount

func NewAccount(
	hash Hash,
	token Token,
	role Role,
	setting Setting,
	accountDataAccessor db.AccountDataAccessor,
	accountPasswordDataAccessor db.AccountPasswordDataAccessor,
	db *gorm.DB,
	logger *zap.Logger,
	logicConfig configs.Logic,
	appArguments utils.Arguments,
) Account

type Compile

type Compile interface {
	Compile(ctx context.Context, content string) (CompileOutput, error)
}

func NewCompile

func NewCompile(
	dockerClient *client.Client,
	logger *zap.Logger,
	language string,
	compileConfig *configs.Compile,
	appArguments utils.Arguments,
) (Compile, error)

type CompileOutput

type CompileOutput struct {
	ProgramFilePath string
	ReturnCode      int64
	StdOut          string
	StdErr          string
}

type Hash

type Hash interface {
	Hash(ctx context.Context, data string) (string, error)
	IsHashEqual(ctx context.Context, data string, hashed string) (bool, error)
}

func NewHash

func NewHash(
	hashConfig configs.Hash,
	logger *zap.Logger,
) Hash

type Judge

type Judge interface {
	JudgeSubmission(ctx context.Context, problem *db.Problem, language string, content string) (db.SubmissionResult, error)
	ScheduleJudgeLocalSubmission(id uint64)
	JudgeDistributedFirstSubmittedSubmission(ctx context.Context) error
}

func NewJudge

func NewJudge(
	problemDataAccessor db.ProblemDataAccessor,
	submissionDataAccessor db.SubmissionDataAccessor,
	testCaseDataAccessor db.TestCaseDataAccessor,
	problemTestCaseHashDataAccessor db.ProblemTestCaseHashDataAccessor,
	dockerClient *client.Client,
	db *gorm.DB,
	apiClient rpcclient.APIClient,
	logger *zap.Logger,
	logicConfig configs.Logic,
	appArguments utils.Arguments,
) (Judge, error)

type Problem

type Problem interface {
	CreateProblem(ctx context.Context, in *rpc.CreateProblemRequest, token string) (*rpc.CreateProblemResponse, error)
	GetProblemSnippetList(
		ctx context.Context,
		in *rpc.GetProblemSnippetListRequest,
		token string,
	) (*rpc.GetProblemSnippetListResponse, error)
	GetProblem(ctx context.Context, in *rpc.GetProblemRequest, token string) (*rpc.GetProblemResponse, error)
	UpdateProblem(ctx context.Context, in *rpc.UpdateProblemRequest, token string) (*rpc.UpdateProblemResponse, error)
	DeleteProblem(ctx context.Context, in *rpc.DeleteProblemRequest, token string) error
	GetAccountProblemSnippetList(
		ctx context.Context,
		in *rpc.GetAccountProblemSnippetListRequest,
		token string,
	) (*rpc.GetAccountProblemSnippetListResponse, error)
	SyncProblemList(ctx context.Context) error
	WithDB(db *gorm.DB) Problem
}

func NewProblem

func NewProblem(
	token Token,
	role Role,
	testCase TestCase,
	setting Setting,
	accountDataAccessor db.AccountDataAccessor,
	problemDataAccessor db.ProblemDataAccessor,
	problemExampleDataAccessor db.ProblemExampleDataAccessor,
	problemTestCaseHashDataAccessor db.ProblemTestCaseHashDataAccessor,
	testCaseDataAccessor db.TestCaseDataAccessor,
	submissionDataAccessor db.SubmissionDataAccessor,
	logger *zap.Logger,
	db *gorm.DB,
	apiClient rpcclient.APIClient,
	logicConfig configs.Logic,
) Problem

type Role

type Role interface {
	AccountHasPermission(ctx context.Context, accountRole string, permissions ...gorbac.Permission) (bool, error)
}

func NewRole

func NewRole(logger *zap.Logger) Role

type RunOutput

type RunOutput struct {
	ReturnCode          int64
	TimeLimitExceeded   bool
	MemoryLimitExceeded bool
	StdOut              string
	StdErr              string
}

type Setting added in v1.2.0

type Setting interface {
	GetSetting(ctx context.Context) (*rpc.Setting, error)
	UpdateSetting(ctx context.Context, in *rpc.UpdateSettingRequest, token string) (*rpc.UpdateSettingResponse, error)
	WithDB(db *gorm.DB) Setting
}

func NewSetting added in v1.2.0

func NewSetting(
	token Token,
	role Role,
	settingDataAccessor db.SettingDataAccessor,
	settingCache cache.Setting,
	db *gorm.DB,
	logger *zap.Logger,
) Setting

type Submission

type Submission interface {
	CreateSubmission(
		ctx context.Context,
		in *rpc.CreateSubmissionRequest,
		token string,
	) (*rpc.CreateSubmissionResponse, error)
	UpdateSubmission(
		ctx context.Context,
		in *rpc.UpdateSubmissionRequest,
		token string,
	) (*rpc.UpdateSubmissionResponse, error)
	GetSubmissionSnippetList(
		ctx context.Context,
		in *rpc.GetSubmissionSnippetListRequest,
		token string,
	) (*rpc.GetSubmissionSnippetListResponse, error)
	GetSubmission(ctx context.Context, in *rpc.GetSubmissionRequest, token string) (*rpc.GetSubmissionResponse, error)
	DeleteSubmission(ctx context.Context, in *rpc.DeleteSubmissionRequest, token string) error
	GetAccountSubmissionSnippetList(
		ctx context.Context,
		in *rpc.GetAccountSubmissionSnippetListRequest,
		token string,
	) (*rpc.GetAccountSubmissionSnippetListResponse, error)
	GetProblemSubmissionSnippetList(
		ctx context.Context,
		in *rpc.GetProblemSubmissionSnippetListRequest,
		token string,
	) (*rpc.GetProblemSubmissionSnippetListResponse, error)
	GetAccountProblemSubmissionSnippetList(
		ctx context.Context,
		in *rpc.GetAccountProblemSubmissionSnippetListRequest,
		token string,
	) (*rpc.GetAccountProblemSubmissionSnippetListResponse, error)
	GetAndUpdateFirstSubmittedSubmissionToExecuting(
		ctx context.Context,
		token string,
	) (*rpc.GetAndUpdateFirstSubmittedSubmissionToExecutingResponse, error)
	ScheduleSubmittedExecutingSubmissionToJudge(ctx context.Context) error
	UpdateExecutingSubmissionUpdatedBeforeThresholdToSubmitted(ctx context.Context) error
}

func NewSubmission

func NewSubmission(
	token Token,
	role Role,
	judge Judge,
	setting Setting,
	accountDataAccessor db.AccountDataAccessor,
	problemDataAccessor db.ProblemDataAccessor,
	submissionDataAccessor db.SubmissionDataAccessor,
	db *gorm.DB,
	logger *zap.Logger,
	appArguments utils.Arguments,
	logicConfig configs.Logic,
) (Submission, error)

type TestCase

type TestCase interface {
	CalculateProblemTestCaseHash(ctx context.Context, problemID uint64) (string, error)
	UpsertProblemTestCaseHash(ctx context.Context, problemID uint64) error
	CreateTestCase(ctx context.Context, in *rpc.CreateTestCaseRequest, token string) (*rpc.CreateTestCaseResponse, error)
	CreateTestCaseList(ctx context.Context, in *rpc.CreateTestCaseListRequest, token string) error
	GetProblemTestCaseSnippetList(
		ctx context.Context,
		in *rpc.GetProblemTestCaseSnippetListRequest,
		token string,
	) (*rpc.GetProblemTestCaseSnippetListResponse, error)
	GetTestCase(ctx context.Context, in *rpc.GetTestCaseRequest, token string) (*rpc.GetTestCaseResponse, error)
	UpdateTestCase(ctx context.Context, in *rpc.UpdateTestCaseRequest, token string) (*rpc.UpdateTestCaseResponse, error)
	DeleteTestCase(ctx context.Context, in *rpc.DeleteTestCaseRequest, token string) error
	SyncProblemTestCaseList(ctx context.Context, problemUUID string) error
	WithDB(db *gorm.DB) TestCase
}

func NewTestCase

func NewTestCase(
	token Token,
	role Role,
	setting Setting,
	problemDataAccessor db.ProblemDataAccessor,
	testCaseDataAccessor db.TestCaseDataAccessor,
	problemTestCaseHashDataAccessor db.ProblemTestCaseHashDataAccessor,
	db *gorm.DB,
	apiClient rpcclient.APIClient,
	logger *zap.Logger,
	logicConfig configs.Logic,
) TestCase

type TestCaseRun

type TestCaseRun interface {
	Run(
		ctx context.Context,
		programFilePath string,
		input string,
		timeLimitInMillisecond uint64,
		memoryLimitInByte uint64,
	) (RunOutput, error)
}

func NewTestCaseRun

func NewTestCaseRun(
	dockerClient *client.Client,
	logger *zap.Logger,
	language string,
	testCaseRunConfig configs.TestCaseRun,
	appArguments utils.Arguments,
) (TestCaseRun, error)

type Token

type Token interface {
	GetToken(ctx context.Context, accountID uint64) (string, time.Time, error)
	GetAccountIDAndExpireTime(ctx context.Context, token string) (uint64, time.Time, error)
	GetAccount(ctx context.Context, token string) (*db.Account, error)
	WithDB(db *gorm.DB) Token
}

func NewToken

func NewToken(
	accountDataAccessor db.AccountDataAccessor,
	tokenPublicKeyDataAccessor db.TokenPublicKeyDataAccessor,
	tokenPublicKeyCache cache.TokenPublicKey,
	tokenConfig configs.Token,
	logger *zap.Logger,
) (Token, error)

Jump to

Keyboard shortcuts

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