domain

package
v0.0.0-...-9b60b69 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnexpectedError = 0
	UnAuthorized    = 1
	InvalidArgument = 2
	NotFound        = 3
)
View Source
const (
	Cache = 1
	Api   = 2
)

Variables

This section is empty.

Functions

func Errorf

func Errorf(code ErrorCode, format string, a ...interface{}) error

Types

type AccessToken

type AccessToken struct {
	Sub string

	Login       string
	Name        string
	Picture     string
	Provenance  TokenProvenance
	OpaqueToken string
}

type AccessTokenCaller

type AccessTokenCaller interface {
	Get(ctx context.Context, token string) (*AccessToken, error)
}

type AuthRepository

type AuthRepository interface {
	CacheToken(token *AccessToken) error
	FindTokenByTokenStr(tokenStr string) (*AccessToken, error)
}

type AuthService

type AuthService struct {
	// contains filtered or unexported fields
}

func NewAuthService

func NewAuthService(authRepository AuthRepository, userRepository UserRepository, c AccessTokenCaller) AuthService

func (*AuthService) Login

func (s *AuthService) Login(ctx context.Context, accessToken string) (*User, error)

func (*AuthService) ValidateTokenAndGetUser

func (s *AuthService) ValidateTokenAndGetUser(ctx context.Context, accessToken string) (*User, error)

type Class

type Class struct {
	Id uuid.UUID

	Name string
}

type ClassRepository

type ClassRepository interface {
	FindAll(ctx context.Context, limit uint16, offset uint16) ([]*Class, error)
	CountAll(ctx context.Context) (uint32, error)
	CreateOrReplace(ctx context.Context, class *Class) error
	Delete(ctx context.Context, classId uuid.UUID) error
	ExistsById(ctx context.Context, classId uuid.UUID) bool
	CreateQuizClassVisibility(ctx context.Context, quizSha1 string, classId uuid.UUID) error
	DeleteQuizClassVisibility(ctx context.Context, quizSha1 string, classId uuid.UUID) error
}

type ClassService

type ClassService struct {
	// contains filtered or unexported fields
}

func NewClassService

func NewClassService(classRepository ClassRepository) ClassService

func (*ClassService) Create

func (s *ClassService) Create(ctx context.Context, name string) error

func (*ClassService) CreateQuizClassVisibility

func (s *ClassService) CreateQuizClassVisibility(ctx context.Context, quizSha1 string, classId uuid.UUID) error

func (*ClassService) Delete

func (s *ClassService) Delete(ctx context.Context, id uuid.UUID) error

func (*ClassService) DeleteQuizClassVisibility

func (s *ClassService) DeleteQuizClassVisibility(ctx context.Context, quizSha1 string, classId uuid.UUID) error

func (*ClassService) FindAllClasses

func (s *ClassService) FindAllClasses(ctx context.Context, limit uint16, offset uint16) ([]*Class, uint32, error)

func (*ClassService) Update

func (s *ClassService) Update(ctx context.Context, class *Class) error

type CodeError

type CodeError struct {
	// contains filtered or unexported fields
}

func (*CodeError) Code

func (e *CodeError) Code() ErrorCode

func (*CodeError) Error

func (e *CodeError) Error() string

type ErrorCode

type ErrorCode int8

func GetCodeFromError

func GetCodeFromError(err error) (ErrorCode, bool)

type HealthRepository

type HealthRepository interface {
	Ping(ctx context.Context) bool
}

type HealthService

type HealthService struct {
	// contains filtered or unexported fields
}

func NewHealthService

func NewHealthService(healthRepository HealthRepository) HealthService

func (*HealthService) PingDB

func (s *HealthService) PingDB(ctx context.Context) bool

type MaintenanceRepository

type MaintenanceRepository interface {
	Dump() (string, error)
}

type MaintenanceService

type MaintenanceService struct {
	// contains filtered or unexported fields
}

func (*MaintenanceService) Dump

func (s *MaintenanceService) Dump() (string, error)

type Quiz

type Quiz struct {
	Sha1 string

	Filename  string
	Name      string
	Version   int
	CreatedAt string
	Active    bool
	Duration  int
	Questions map[string]QuizQuestion
	Classes   map[uuid.UUID]string
}

func (*Quiz) GetQuestions

func (q *Quiz) GetQuestions() map[string]QuizQuestion

func (*Quiz) GetSha1NameAndDuration

func (q *Quiz) GetSha1NameAndDuration() (string, string, int)

type QuizInfos

type QuizInfos interface {
	GetSha1NameAndDuration() (string, string, int)
	GetQuestions() map[string]QuizQuestion
}

type QuizQuestion

type QuizQuestion struct {
	Sha1 string

	Content      string
	Code         string
	CodeLanguage string
	Position     int
	Answers      map[string]QuizQuestionAnswer
}

type QuizQuestionAnswer

type QuizQuestionAnswer struct {
	Sha1 string

	Content string
	Checked bool
	Valid   bool
}

type QuizRepository

type QuizRepository interface {
	FindFullBySha1(ctx context.Context, sha1 string, userId string) (*Quiz, error)
	FindLatestVersionByFilename(ctx context.Context, filename string) (*Quiz, error)
	FindAllActive(ctx context.Context, userId string, limit uint16, offset uint16) ([]*Quiz, error)
	CountAllActive(ctx context.Context, userId string) (uint32, error)
	Create(ctx context.Context, quiz *Quiz) error
	ActivateOnlyVersion(ctx context.Context, filename string, version int) error

	FindAllSessions(ctx context.Context, quizActive bool, userId string, limit uint16, offset uint16) ([]*Session, error)
	CountAllSessions(ctx context.Context, quizActive bool, userId string) (uint32, error)
	StartSession(ctx context.Context, userId string, quizSha1 string) (uuid.UUID, error)
	AddSessionAnswer(ctx context.Context, sessionUuid uuid.UUID, questionSha1 string, answerSha1 string, checked bool) error

	FindAllQuizSessions(ctx context.Context, userId string, classId string, limit uint16, offset uint16) ([]*QuizSession, error)
	FindQuizSessionByUuid(ctx context.Context, sessionUuid uuid.UUID) (*QuizSessionDetail, error)
}

type QuizService

type QuizService struct {
	// contains filtered or unexported fields
}

func NewQuizService

func NewQuizService(r QuizRepository) QuizService

func (*QuizService) AddSessionAnswer

func (s *QuizService) AddSessionAnswer(ctx context.Context, sessionUuid uuid.UUID, userId string, questionSha1 string, answerSha1 string, checked bool) error

func (*QuizService) FindAllActive

func (s *QuizService) FindAllActive(ctx context.Context, userId string, limit uint16, offset uint16) ([]*Quiz, uint32, error)

func (*QuizService) FindAllQuizSessions

func (s *QuizService) FindAllQuizSessions(ctx context.Context, userId string, classId string, limit uint16, offset uint16) ([]*QuizSession, uint32, error)

func (*QuizService) FindAllSessions

func (s *QuizService) FindAllSessions(ctx context.Context, quizActive bool, userId string, limit uint16, offset uint16) ([]*Session, uint32, error)

func (*QuizService) FindFullBySha1

func (s *QuizService) FindFullBySha1(ctx context.Context, sha1 string, userId string) (*Quiz, error)

func (*QuizService) FindQuizSessionByUuid

func (s *QuizService) FindQuizSessionByUuid(ctx context.Context, sessionUuid uuid.UUID) (*QuizSessionDetail, error)

func (*QuizService) Parse

func (s *QuizService) Parse(filename string, content string) (*Quiz, error)

Parse parse the content of a quiz file

func (*QuizService) SaveQuiz

func (s *QuizService) SaveQuiz(ctx context.Context, quiz *Quiz) (*SyncStats, error)

func (*QuizService) ScanGitRepo

func (s *QuizService) ScanGitRepo() ([]*Quiz, error)

func (*QuizService) StartSession

func (s *QuizService) StartSession(ctx context.Context, userId string, quizSha1 string) (uuid.UUID, error)

func (*QuizService) Sync

func (s *QuizService) Sync(ctx context.Context) error

type QuizSession

type QuizSession struct {
	QuizSha1 string

	Name         string
	Duration     int
	Filename     string
	Version      int
	CreatedAt    string
	UserSessions []*UserSession
}

type QuizSessionDetail

type QuizSessionDetail struct {
	SessionId uuid.UUID

	UserId       string
	RemainingSec int
	Result       *SessionResult
	QuizSha1     string
	Name         string
	QuizDuration int
	Questions    map[string]QuizQuestion
}

func (*QuizSessionDetail) GetQuestions

func (qd *QuizSessionDetail) GetQuestions() map[string]QuizQuestion

func (*QuizSessionDetail) GetSha1NameAndDuration

func (qd *QuizSessionDetail) GetSha1NameAndDuration() (string, string, int)

type Role

type Role int8
const (
	NoRole  Role = 0
	Admin   Role = 1
	Teacher Role = 2
	Student Role = 3
	Machine Role = 4
)

func (Role) CanAccess

func (role Role) CanAccess(other Role) bool

type Session

type Session struct {
	Id uuid.UUID

	QuizSha1     string
	QuizName     string
	QuizActive   bool
	UserId       string
	UserName     string
	RemainingSec int
	Result       *SessionResult
}

type SessionResult

type SessionResult struct {
	GoodAnswer  int
	TotalAnswer int
}

type SyncStats

type SyncStats struct {
	Created int
	Updated int
}

type TokenProvenance

type TokenProvenance int8

type User

type User struct {
	Id string

	Login   string
	Name    string
	Picture string
	Active  bool
	Role    Role
	Class   *Class
}

type UserRepository

type UserRepository interface {
	FindActiveUserById(ctx context.Context, id string) (*User, error)
	FindUserById(ctx context.Context, id string) (*User, error)
	FindAllUser(ctx context.Context) ([]*User, error)
	CreateOrReplaceUser(ctx context.Context, user *User) error
	UpdateUserActive(ctx context.Context, id string, active bool) error
	UpdateUserRole(ctx context.Context, userId string, role Role) error
	UpdateUserInfo(ctx context.Context, user *User) error
	AssignUserToClass(ctx context.Context, userId string, classId uuid.UUID) error
}

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

func NewUserService

func NewUserService(userRepository UserRepository) UserService

func (*UserService) ActivateUser

func (s *UserService) ActivateUser(ctx context.Context, id string) error

func (*UserService) AssignUserToClass

func (s *UserService) AssignUserToClass(ctx context.Context, userId string, classId uuid.UUID) error

func (*UserService) DeactivateUser

func (s *UserService) DeactivateUser(ctx context.Context, id string) error

func (*UserService) FindAllUser

func (s *UserService) FindAllUser(ctx context.Context) ([]*User, error)

func (*UserService) FindUserById

func (s *UserService) FindUserById(ctx context.Context, id string) (*User, error)

func (*UserService) UpdateUserRole

func (s *UserService) UpdateUserRole(ctx context.Context, userId string, role Role) error

type UserSession

type UserSession struct {
	SessionId uuid.UUID
	UserId    string

	UserName     string
	Picture      string
	ClassName    string
	RemainingSec int
	Result       *SessionResult
}

Jump to

Keyboard shortcuts

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