service

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

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

Go to latest
Published: Sep 6, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SystemStudentLoginID = "system-student"
	TatoebaWorkbookName  = "tatoeba"
	OrganizationName     = "cocotola"
	UserRfFunc           userS.RepositoryFactoryFunc
	RfFunc               RepositoryFactoryFunc
)
View Source
var (
	ErrQuotaExceeded              = errors.New("quota exceeded")
	QuotaUnitPersitance QuotaUnit = "persitance"
	QuotaUnitMonth      QuotaUnit = "month"
	QuotaUnitDay        QuotaUnit = "day"
	QuotaNameSize       QuotaName = "Size"
	QuotaNameUpdate     QuotaName = "Update"
)
View Source
var ErrAudioNotFound = errors.New("audio not found")
View Source
var ErrProblemAlreadyExists = errors.New("problem already exists")
View Source
var ErrProblemNotFound = errors.New("problem not found")
View Source
var ErrProblemOtherError = errors.New("problem other error")
View Source
var ErrStudyResultNotFound = errors.New("StudyResult not found")
View Source
var ErrWorkbookAlreadyExists = errors.New("workbook already exists")
View Source
var ErrWorkbookNotFound = errors.New("workbook not found")
View Source
var ErrWorkbookPermissionDenied = errors.New("permission denied")

Functions

func GetSystemSpaceID

func GetSystemSpaceID() userD.SpaceID

func GetSystemStudentID

func GetSystemStudentID() userD.AppUserID

func GetTatoebaWorkbookID

func GetTatoebaWorkbookID() domain.WorkbookID

func InitAppProperties

func InitAppProperties(systemSpaceID userD.SpaceID, systemStudentID userD.AppUserID, tatoebaWorkbookID domain.WorkbookID)

func SetSystemSpaceID

func SetSystemSpaceID(propertiesSystemSpaceID userD.SpaceID)

func SetSystemStudentID

func SetSystemStudentID(propertiesSystemStudentID userD.AppUserID)

func SetTatoebaWorkbookID

func SetTatoebaWorkbookID(propertiesTatoebaWorkbookID domain.WorkbookID)

Types

type Added

type Added int

type Audio

type Audio interface {
	GetAudioModel() domain.AudioModel
}

func NewAudio

func NewAudio(audioModel domain.AudioModel) (Audio, error)

type GuestStudent

type GuestStudent interface {
	domain.StudentModel

	GetDefaultSpace(ctx context.Context) (userS.Space, error)

	FindWorkbooksFromPublicSpace(ctx context.Context, condition WorkbookSearchCondition) (WorkbookSearchResult, error)
}

type Problem

type Problem interface {
	domain.ProblemModel
	ProblemFeature
}

func NewProblem

func NewProblem(synthesizerClient SynthesizerClient, problemModel domain.ProblemModel) (Problem, error)

type ProblemAddParameter

type ProblemAddParameter interface {
	GetWorkbookID() domain.WorkbookID
	GetNumber() int
	GetProperties() map[string]string
}

func NewProblemAddParameter

func NewProblemAddParameter(workbookID domain.WorkbookID, number int, properties map[string]string) (ProblemAddParameter, error)

type ProblemAddParameterIterator

type ProblemAddParameterIterator interface {
	Next() (ProblemAddParameter, error)
}

type ProblemAddProcessor

type ProblemAddProcessor interface {
	AddProblem(ctx context.Context, repo RepositoryFactory, operator domain.StudentModel, workbookModel domain.WorkbookModel, param ProblemAddParameter) ([]domain.ProblemID, error)
}

type ProblemFeature

type ProblemFeature interface {
}

type ProblemIDsCondition

type ProblemIDsCondition interface {
	GetWorkbookID() domain.WorkbookID
	GetIDs() []domain.ProblemID
}

func NewProblemIDsCondition

func NewProblemIDsCondition(workbookID domain.WorkbookID, ids []domain.ProblemID) (ProblemIDsCondition, error)

type ProblemImportProcessor

type ProblemImportProcessor interface {
	CreateCSVReader(ctx context.Context, workbookID domain.WorkbookID, reader io.Reader) (ProblemAddParameterIterator, error)
}

type ProblemQuotaProcessor

type ProblemQuotaProcessor interface {
	GetUnitForSizeQuota() QuotaUnit

	GetLimitForSizeQuota() int

	GetUnitForUpdateQuota() QuotaUnit

	GetLimitForUpdateQuota() int
}

type ProblemRemoveProcessor

type ProblemRemoveProcessor interface {
	RemoveProblem(ctx context.Context, repo RepositoryFactory, operator domain.StudentModel, id ProblemSelectParameter2) error
}

type ProblemRepository

type ProblemRepository interface {
	// FindProblems searches for problems based on search condition
	FindProblems(ctx context.Context, operator domain.StudentModel, param ProblemSearchCondition) (ProblemSearchResult, error)

	FindAllProblems(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID) (ProblemSearchResult, error)

	FindProblemsByProblemIDs(ctx context.Context, operator domain.StudentModel, param ProblemIDsCondition) (ProblemSearchResult, error)

	FindProblemsByCustomCondition(ctx context.Context, operator domain.StudentModel, condition interface{}) ([]domain.ProblemModel, error)

	FindProblemByID(ctx context.Context, operator domain.StudentModel, id ProblemSelectParameter1) (Problem, error)

	FindProblemIDs(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID) ([]domain.ProblemID, error)

	// AddProblem register a new problem
	AddProblem(ctx context.Context, operator domain.StudentModel, param ProblemAddParameter) (domain.ProblemID, error)

	UpdateProblem(ctx context.Context, operator domain.StudentModel, id ProblemSelectParameter2, param ProblemUpdateParameter) error

	RemoveProblem(ctx context.Context, operator domain.StudentModel, id ProblemSelectParameter2) error

	CountProblems(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID) (int, error)
}

type ProblemSearchCondition

type ProblemSearchCondition interface {
	GetWorkbookID() domain.WorkbookID
	GetPageNo() int
	GetPageSize() int
	GetKeyword() string
}

func NewProblemSearchCondition

func NewProblemSearchCondition(workbookID domain.WorkbookID, pageNo, pageSize int, keyword string) (ProblemSearchCondition, error)

type ProblemSearchResult

type ProblemSearchResult interface {
	GetTotalCount() int
	GetResults() []domain.ProblemModel
}

func NewProblemSearchResult

func NewProblemSearchResult(totalCount int, results []domain.ProblemModel) (ProblemSearchResult, error)

type ProblemSelectParameter1

type ProblemSelectParameter1 interface {
	GetWorkbookID() domain.WorkbookID
	GetProblemID() domain.ProblemID
}

func NewProblemSelectParameter1

func NewProblemSelectParameter1(WorkbookID domain.WorkbookID, problemID domain.ProblemID) (ProblemSelectParameter1, error)

type ProblemSelectParameter2

type ProblemSelectParameter2 interface {
	GetWorkbookID() domain.WorkbookID
	GetProblemID() domain.ProblemID
	GetVersion() int
}

func NewProblemSelectParameter2

func NewProblemSelectParameter2(WorkbookID domain.WorkbookID, problemID domain.ProblemID, version int) (ProblemSelectParameter2, error)

type ProblemTypeRepository

type ProblemTypeRepository interface {
	FindAllProblemTypes(ctx context.Context) ([]domain.ProblemType, error)
}

type ProblemUpdateParameter

type ProblemUpdateParameter interface {
	GetNumber() int
	GetProperties() map[string]string
	GetStringProperty(name string) (string, error)
	GetIntProperty(name string) (int, error)
}

func NewProblemUpdateParameter

func NewProblemUpdateParameter(number int, properties map[string]string) (ProblemUpdateParameter, error)

type ProblemUpdateProcessor

type ProblemUpdateProcessor interface {
	UpdateProblem(ctx context.Context, repo RepositoryFactory, operator domain.StudentModel, workbookModel domain.WorkbookModel, id ProblemSelectParameter2, param ProblemUpdateParameter) (Added, Updated, error)
}

type ProblemWithResults

type ProblemWithResults interface {
	domain.ProblemModel
	GetResults() []bool
	GetLevel() int
}

func NewProblemWithResults

func NewProblemWithResults(problem domain.ProblemModel, results []bool, level int) ProblemWithResults

type ProcessorFactory

type ProcessorFactory interface {
	NewProblemAddProcessor(processorType string) (ProblemAddProcessor, error)

	NewProblemUpdateProcessor(processorType string) (ProblemUpdateProcessor, error)

	NewProblemRemoveProcessor(processorType string) (ProblemRemoveProcessor, error)

	NewProblemImportProcessor(processorType string) (ProblemImportProcessor, error)

	NewProblemQuotaProcessor(processorType string) (ProblemQuotaProcessor, error)
}

func NewProcessorFactory

func NewProcessorFactory(addProcessors map[string]ProblemAddProcessor, updateProcessors map[string]ProblemUpdateProcessor, removeProcessors map[string]ProblemRemoveProcessor, importProcessors map[string]ProblemImportProcessor, quotaProcessors map[string]ProblemQuotaProcessor) ProcessorFactory

type QuotaName

type QuotaName string

type QuotaUnit

type QuotaUnit string

type Recordbook

type Recordbook interface {
	GetStudent() Student

	GetWorkbookID() domain.WorkbookID

	GetResults(ctx context.Context) (map[domain.ProblemID]domain.StudyRecord, error)

	GetResultsSortedLevel(ctx context.Context) ([]domain.StudyRecordWithProblemID, error)

	SetResult(ctx context.Context, problemType string, problemID domain.ProblemID, result, memorized bool) error
}

func NewRecordbook

func NewRecordbook(rf RepositoryFactory, student Student, workbookID domain.WorkbookID, studyType string) (Recordbook, error)

type RecordbookRepository

type RecordbookRepository interface {
	FindStudyRecords(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID, studyType string) (map[domain.ProblemID]domain.StudyRecord, error)

	SetResult(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID, studyType string, problemType string, problemID domain.ProblemID, studyResult, memorized bool) error

	CountMemorizedProblem(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID) (map[string]int, error)
}

type RecordbookSummary

type RecordbookSummary interface {
	GetCompletionRate(ctx context.Context) (map[string]int, error)
}

func NewRecordbookSummary

func NewRecordbookSummary(rf RepositoryFactory, student Student, workbookID domain.WorkbookID) (RecordbookSummary, error)

type RepositoryFactory

type RepositoryFactory interface {
	NewWorkbookRepository(ctx context.Context) (WorkbookRepository, error)

	NewProblemRepository(ctx context.Context, problemType string) (ProblemRepository, error)

	NewProblemTypeRepository(ctx context.Context) ProblemTypeRepository

	NewStudyTypeRepository(ctx context.Context) StudyTypeRepository

	NewRecordbookRepository(ctx context.Context) RecordbookRepository

	NewUserQuotaRepository(ctx context.Context) UserQuotaRepository
}

type RepositoryFactoryFunc

type RepositoryFactoryFunc func(ctx context.Context, db *gorm.DB) (RepositoryFactory, error)

type Student

type Student interface {
	domain.StudentModel

	GetDefaultSpace(ctx context.Context) (userS.Space, error)
	GetPersonalSpace(ctx context.Context) (userS.Space, error)

	FindWorkbooksFromPersonalSpace(ctx context.Context, condition WorkbookSearchCondition) (WorkbookSearchResult, error)

	FindWorkbookByID(ctx context.Context, id domain.WorkbookID) (Workbook, error)

	FindWorkbookByName(ctx context.Context, name string) (Workbook, error)

	AddWorkbookToPersonalSpace(ctx context.Context, parameter WorkbookAddParameter) (domain.WorkbookID, error)

	UpdateWorkbook(ctx context.Context, workbookID domain.WorkbookID, version int, parameter WorkbookUpdateParameter) error

	RemoveWorkbook(ctx context.Context, id domain.WorkbookID, version int) error

	CheckQuota(ctx context.Context, problemType string, name QuotaName) error

	IncrementQuotaUsage(ctx context.Context, problemType string, name QuotaName, value int) error

	DecrementQuotaUsage(ctx context.Context, problemType string, name QuotaName, value int) error

	FindRecordbook(ctx context.Context, workbookID domain.WorkbookID, studyType string) (Recordbook, error)

	FindRecordbookSummary(ctx context.Context, workbookID domain.WorkbookID) (RecordbookSummary, error)
}

func NewStudent

func NewStudent(pf ProcessorFactory, rf RepositoryFactory, userRf userS.RepositoryFactory, studentModel domain.StudentModel) (Student, error)

type StudyTypeRepository

type StudyTypeRepository interface {
	FindAllStudyTypes(ctx context.Context) ([]domain.StudyType, error)
}

type SynthesizerClient

type SynthesizerClient interface {
	Synthesize(ctx context.Context, lang2 domain.Lang2, text string) (Audio, error)

	FindAudioByAudioID(ctx context.Context, audioID domain.AudioID) (Audio, error)
}

type SystemStudent

type SystemStudent interface {
	userD.AppUserModel

	FindWorkbookFromSystemSpace(ctx context.Context, name string) (Workbook, error)

	AddWorkbookToSystemSpace(ctx context.Context, parameter WorkbookAddParameter) (domain.WorkbookID, error)
}

func NewSystemStudent

func NewSystemStudent(rf RepositoryFactory, appUser userD.AppUserModel) (SystemStudent, error)

type Updated

type Updated int

type UserQuotaRepository

type UserQuotaRepository interface {
	IsExceeded(ctx context.Context, operator domain.StudentModel, name string, unit QuotaUnit, limit int) (bool, error)

	Increment(ctx context.Context, operator domain.StudentModel, name string, unit QuotaUnit, limit int, count int) (bool, error)
}

type Workbook

type Workbook interface {
	domain.WorkbookModel

	// FindProblems searches for problems based on search condition
	FindProblems(ctx context.Context, operator domain.StudentModel, param ProblemSearchCondition) (ProblemSearchResult, error)

	FindAllProblems(ctx context.Context, operator domain.StudentModel) (ProblemSearchResult, error)

	FindProblemsByProblemIDs(ctx context.Context, operator domain.StudentModel, param ProblemIDsCondition) (ProblemSearchResult, error)

	FindProblemIDs(ctx context.Context, operator domain.StudentModel) ([]domain.ProblemID, error)

	// FindProblems searches for problem based on a problem ID
	FindProblemByID(ctx context.Context, operator domain.StudentModel, problemID domain.ProblemID) (Problem, error)

	AddProblem(ctx context.Context, operator domain.StudentModel, param ProblemAddParameter) ([]domain.ProblemID, error)

	UpdateProblem(ctx context.Context, operator domain.StudentModel, id ProblemSelectParameter2, param ProblemUpdateParameter) (Added, Updated, error)

	RemoveProblem(ctx context.Context, operator domain.StudentModel, id ProblemSelectParameter2) error

	UpdateWorkbook(ctx context.Context, operator domain.StudentModel, version int, parameter WorkbookUpdateParameter) error

	RemoveWorkbook(ctx context.Context, operator domain.StudentModel, version int) error

	CountProblems(ctx context.Context, operator domain.StudentModel) (int, error)
}

func NewWorkbook

func NewWorkbook(rf RepositoryFactory, pf ProcessorFactory, workbookModel domain.WorkbookModel) (Workbook, error)

type WorkbookAddParameter

type WorkbookAddParameter interface {
	GetProblemType() string
	GetName() string
	GetLang2() domain.Lang2
	GetQuestionText() string
	GetProperties() map[string]string
}

func NewWorkbookAddParameter

func NewWorkbookAddParameter(problemType string, name string, lang2 domain.Lang2, questionText string, properties map[string]string) (WorkbookAddParameter, error)

type WorkbookRepository

type WorkbookRepository interface {
	FindPersonalWorkbooks(ctx context.Context, operator domain.StudentModel, param WorkbookSearchCondition) (WorkbookSearchResult, error)

	FindWorkbookByID(ctx context.Context, operator domain.StudentModel, id domain.WorkbookID) (Workbook, error)

	FindWorkbookByName(ctx context.Context, operator userD.AppUserModel, spaceID userD.SpaceID, name string) (Workbook, error)

	AddWorkbook(ctx context.Context, operator userD.AppUserModel, spaceID userD.SpaceID, param WorkbookAddParameter) (domain.WorkbookID, error)

	UpdateWorkbook(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID, version int, param WorkbookUpdateParameter) error

	RemoveWorkbook(ctx context.Context, operator domain.StudentModel, workbookID domain.WorkbookID, version int) error
}

type WorkbookSearchCondition

type WorkbookSearchCondition interface {
	GetPageNo() int
	GetPageSize() int
	GetSpaceIDs() []userD.SpaceID
}

func NewWorkbookSearchCondition

func NewWorkbookSearchCondition(pageNo, pageSize int, spaceIDs []userD.SpaceID) (WorkbookSearchCondition, error)

type WorkbookSearchResult

type WorkbookSearchResult interface {
	GetTotalCount() int
	GetResults() []domain.WorkbookModel
}

func NewWorkbookSearchResult

func NewWorkbookSearchResult(totalCount int, results []domain.WorkbookModel) (WorkbookSearchResult, error)

type WorkbookUpdateParameter

type WorkbookUpdateParameter interface {
	GetName() string
	GetQuestionText() string
}

func NewWorkbookUpdateParameter

func NewWorkbookUpdateParameter(name, questionText string) (WorkbookUpdateParameter, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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