domain

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnonymousUser uint = 1
)

Variables

This section is empty.

Functions

func UserCachePrefix

func UserCachePrefix(userId uint) string

func ValidateEmail

func ValidateEmail(email string) error

func ValidatePassword

func ValidatePassword(password string) error

Types

type AlbumApp

type AlbumApp struct {
	Album []ProblemStatsApp `json:"album"`
}

type AllProblemsAdminApp

type AllProblemsAdminApp struct {
	Problems []ProblemAdminApp `json:"all_problems"`
}

type AllProblemsApp

type AllProblemsApp struct {
	Problems []ProblemSummaryApp `json:"all_problems"`
}

type AttemptResultApp

type AttemptResultApp struct {
	Result      string    `json:"result"`
	Deadline    time.Time `json:"deadline"`
	AttemptDate time.Time `json:"attempt_date"`
}

type AttemptResultForListApp

type AttemptResultForListApp struct {
	AttemptDate time.Time `json:"attempt_date"`
	Result      string    `json:"result"`
	GivenAnswer int       `json:"given_answer"`
}

type CacheKey

type CacheKey string
const (
	AllProblemsCacheKey     CacheKey      = "all_problems"
	CurrentProblemsCacheKey CacheKey      = "current_problems"
	NextProblemsCacheKey    CacheKey      = "next_problems"
	DefaultTimeToLive       time.Duration = 1 * time.Second
)

func ProblemCacheKey

func ProblemCacheKey(problemId uint) CacheKey

func ProblemViewableCacheKey

func ProblemViewableCacheKey(problemId uint) CacheKey

func UserAlbumCacheKey

func UserAlbumCacheKey(userId uint) CacheKey

type CurrentProblemsApp

type CurrentProblemsApp struct {
	CurrentProblems []ProblemApp `json:"current_problems"`
}

type EmailWrappedApp

type EmailWrappedApp struct {
	Email string `json:"email"`
}

type ExpandedUserProblemAttempt

type ExpandedUserProblemAttempt struct {
	Answer           int
	DateContestEnd   time.Time
	DateContestStart time.Time
	UserId           uint
	AttemptId        uint
	AttemptDate      time.Time
	ProblemId        uint
	UserAnswer       int
	IsCorrect        bool
	DuringContest    bool
}

type ExpandedUserProblemAttemptRepo

type ExpandedUserProblemAttemptRepo interface {
	GetByUserId(userId uint) []ExpandedUserProblemAttempt
	GetByUserIdAndProblemId(userId uint, problemId uint) []ExpandedUserProblemAttempt
	GetAllByProblem(problemId uint) []ExpandedUserProblemAttempt
}

type LoginApp

type LoginApp struct {
	UserName string `json:"user_name"`
	Password string `json:"password"`
}

Login

type LoginResponseApp

type LoginResponseApp struct {
	Token      string  `json:"token"`
	Expiration string  `json:"expiration"`
	User       UserApp `json:"user`
}

Response of the successful login

type NextProblemsApp

type NextProblemsApp struct {
	NextProblems []ProblemNextApp `json:"next_problems"`
}

type PasswordChangeApp

type PasswordChangeApp struct {
	NewPassword string `json:"new_password"`
	OldPassword string `json:"old_password"`
}

type Problem

type Problem struct {
	gorm.Model
	PoserId          uint
	OmaforosPostId   uint
	DateContestStart time.Time
	DateContestEnd   time.Time
	Statement        string `gorm:"type:longtext;"`
	Answer           int
	Annotations      string `gorm:"type:longtext;"`
	IsDraft          bool
	Hint             string `gorm:"type:longtext;"`
	OfficialSolution string `gorm:"type:longtext;"`
	Series           string
	NumberInSeries   uint
}

func (*Problem) IsContestFinished

func (problem *Problem) IsContestFinished() bool

func (*Problem) IsCurrentProblem

func (problem *Problem) IsCurrentProblem() bool

func (*Problem) IsViewable

func (problem *Problem) IsViewable() bool

type ProblemAdminApp

type ProblemAdminApp struct {
	ProblemId        uint      `json:"problem_id"`
	Statement        string    `json:"statement"`
	Answer           int       `json:"answer"`
	OmaforosPostId   uint      `json:"omaforos_post_id"`
	Annotations      string    `json:"annotations"`
	Hint             string    `json:"hint"`
	Series           string    `json:"series"`
	NumberInSeries   uint      `json:"number_in_series"`
	Tags             []string  `json:"tags"`
	OfficialSolution string    `json:"official_solution"`
	ReleaseDate      time.Time `json:"release_date"`
	Deadline         time.Time `json:"deadline"`
	IsDraft          bool      `json:"is_draft"`
}

func (*ProblemAdminApp) IsCurrentProblemAdminApp

func (problemAdminApp *ProblemAdminApp) IsCurrentProblemAdminApp() bool

func (ProblemAdminApp) Validate

func (newProblem ProblemAdminApp) Validate() error

type ProblemAdminStatsApp

type ProblemAdminStatsApp struct {
	ProblemId                uint     `json:"problem_id"`
	Attempts                 uint     `json:"attempts"`
	SolvedCount              uint     `json:"solved"`
	SolvedDistinctCount      int      `json:"solved_distinct"`
	SolvedDuringContestCount uint     `json:"solved_during_contest"`
	IsCurrentProblem         bool     `json:"is_current_problem"`
	Series                   string   `json:"series"`
	NumberInSeries           uint     `json:"number_in_series"`
	Tags                     []string `json:"tags"`
}

type ProblemApp

type ProblemApp struct {
	ProblemId      uint      `json:"problem_id"`
	Statement      string    `json:"statement"`
	OmaforosPostId uint      `json:"omaforos_post_id"`
	Series         string    `json:"series"`
	NumberInSeries uint      `json:"number_in_series"`
	Tags           []string  `json:"tags"`
	ReleaseDate    time.Time `json:"release_date"`
	Deadline       time.Time `json:"deadline"`
}

type ProblemAttemptApp

type ProblemAttemptApp struct {
	ProblemId uint `json:"problem_id"`
	Answer    int  `json:"answer"`
}

type ProblemAttemptsByUserApp

type ProblemAttemptsByUserApp struct {
	ProblemId           uint                      `json:"problem_id"`
	Attempts            uint                      `json:"attempts"`
	IsCurrentProblem    bool                      `json:"is_current_problem"`
	Solved              bool                      `json:"solved"`
	SolvedDuringContest bool                      `json:"solved_during_contest"`
	DateSolved          time.Time                 `json:"date_solved"`
	Deadline            time.Time                 `json:"deadline"`
	AttemptList         []AttemptResultForListApp `json:"attempt_list"`
}

type ProblemNextApp

type ProblemNextApp struct {
	ProblemId      uint      `json:"problem_id"`
	ReleaseDate    time.Time `json:"release_date"`
	Deadline       time.Time `json:"deadline"`
	Series         string    `json:"series"`
	NumberInSeries uint      `json:"number_in_series"`
}

type ProblemRepo

type ProblemRepo interface {
	GetById(problemId uint) *Problem
	Create(problem *Problem) error
	Update(problem *Problem) error     // updates a specific row, problem must have ID setted
	Delete(problemId uint) error       // deletes a problem by Id
	GetCurrentProblems() []Problem     // devuelve los problemas que se pueden ver y cuyo deadline es futuro (sin drafts)
	GetNextProblems() []Problem        // devuelve los problemas que todavia no se pueden ver (sin drafts)
	GetAllProblems() []Problem         // devuelve los problemas que ya se pueden ver (sin  drafts)
	GetAllProblemsForAdmin() []Problem // devuelve todos los problemas incluyendo drafts y problemas que aun no son publicos
	GetNextNumberInSeries(series string) uint
}

el numero dentro de la serie lo maneja automaticamente este repo un problema que no es draft no puede volver a ser draft

type ProblemStatsApp

type ProblemStatsApp struct {
	ProblemId           uint      `json:"problem_id"`
	Attempts            uint      `json:"attempts"`
	Solved              bool      `json:"solved"`
	SolvedDuringContest bool      `json:"solved_during_contest"`
	IsCurrentProblem    bool      `json:"is_current_problem"`
	DateSolved          time.Time `json:"date_solved"`
	Series              string    `json:"series"`
	NumberInSeries      uint      `json:"number_in_series"`
	Tags                []string  `json:"tags"`
}

type ProblemSummaryApp

type ProblemSummaryApp struct {
	ProblemId      uint     `json:"problem_id"`
	Series         string   `json:"series"`
	NumberInSeries uint     `json:"number_in_series"`
	Tags           []string `json:"tags"`
}

type ProblemTag

type ProblemTag struct {
	gorm.Model
	ProblemId uint
	Tag       string
}

type ProblemTagRepo

type ProblemTagRepo interface {
	Create(problemTag *ProblemTag) error
	CreateByProblemIdAndTags(problemId uint, tags []string) error
	DeleteAllTagsByProblemId(problemId uint) error
	GetByProblemId(problemId uint) []ProblemTag
	GetAllTags() []ProblemTag // todas, incluyendo tags de drafts y problemas privados
}

type ProblemsApp

type ProblemsApp struct {
	Problems []ProblemSummaryApp `json:"problems"`
}

type RefreshResponseApp

type RefreshResponseApp struct {
	Token      string `json:"token"`
	Expiration string `json:"expiration"`
}

Response of the successful refresh

type RegistrationApp

type RegistrationApp struct {
	UserName   string `json:"user_name"`
	Password   string `json:"password"`
	Name       string `json:"name"`
	LastName   string `json:"last_name"`
	BirthDate  string `json:"birth_date"`
	Email      string `json:"email"`
	Gender     string `json:"gender"`
	IsStudent  bool   `json:"is_student"`
	IsTeacher  bool   `json:"is_teacher"`
	SchoolYear uint   `json:"school_year"`
	Country    string `json:"country"`
	Province   string `json:"province"`
	Department string `json:"department"`
	Location   string `json:"location"`
	School     string `json:"school"`
}

func (RegistrationApp) Validate

func (registration RegistrationApp) Validate() error

func (RegistrationApp) ValidateWithoutPassword

func (registration RegistrationApp) ValidateWithoutPassword() error

validaciones para put de user profile

type School

type School struct {
	gorm.Model
	Name       string
	Province   string
	Department string
	Location   string
}

type SchoolApp

type SchoolApp struct {
	Name       string `json:"name"`
	Province   string `json:"province"`
	Department string `json:"department"`
	Location   string `json:"location"`
}

type SchoolRepo

type SchoolRepo interface {
	GetSchools(searchText string, province string, department string) []School
	Create(school *School) error
}

type SchoolsApp

type SchoolsApp struct {
	Problems []SchoolApp `json:"schools"`
}

type TeleOMACache

type TeleOMACache interface {
	Get(key CacheKey) interface{}
	SetWithTTL(key CacheKey, value interface{}, timeToLive time.Duration)
	SetWithExpiration(key CacheKey, value interface{}, expirationDate time.Time)
	Delete(key CacheKey)
	Clear() int // clears everything
	GetUserAlbum(userId uint) interface{}
	ClearUserCache(userId uint) int //clears the user's cache
}

type UpdateProfileApp

type UpdateProfileApp struct {
	UserName   string `json:"user_name"`
	Name       string `json:"name"`
	LastName   string `json:"last_name"`
	BirthDate  string `json:"birth_date"`
	Email      string `json:"email"`
	Gender     string `json:"gender"`
	IsStudent  bool   `json:"is_student"`
	IsTeacher  bool   `json:"is_teacher"`
	SchoolYear uint   `json:"school_year"`
	Country    string `json:"country"`
	Province   string `json:"province"`
	Department string `json:"department"`
	Location   string `json:"location"`
	School     string `json:"school"`
}

everything but password

type User

type User struct {
	gorm.Model
	// campos de registro de usuario
	UserName       string `gorm:"unique;size:20"`
	HashedPassword string
	Email          string `gorm:"unique;"`
	Name           string
	LastName       string
	BirthDate      time.Time
	Gender         string
	Country        string
	Province       string
	Department     string
	Location       string
	School         string
	IsStudent      bool
	IsTeacher      bool
	SchoolYear     uint
	// campos que se llenan de otra forma
	RegistrationDate time.Time
	LastActiveDate   time.Time
	IsAdmin          bool
}

Si agregamos algun campo a este struct hay que tener mucho cuidado de no pisarlo con null en el endpoint de Update user!

type UserAction

type UserAction struct {
	gorm.Model
	UserId      uint
	Date        time.Time
	StatusCode  int
	Method      string
	Resource    string
	Description string
}

type UserActionRepo

type UserActionRepo interface {
	GetByID(ID uint) *UserAction
	GetActionsByUserID(userID uint) []UserAction
	GetAll() []UserAction
	Create(user *UserAction) error
}

type UserApp

type UserApp struct {
	UserID           uint      `json:"user_id"`
	UserName         string    `json:"user_name"`
	Email            string    `json:"email"`
	Name             string    `json:"name"`
	LastName         string    `json:"last_name"`
	BirthDate        time.Time `json:"birth_date"`
	Gender           string    `json:"gender"`
	IsStudent        bool      `json:"is_student"`
	IsTeacher        bool      `json:"is_teacher"`
	SchoolYear       uint      `json:"school_year"`
	Country          string    `json:"country"`
	Province         string    `json:"province"`
	Department       string    `json:"department"`
	Location         string    `json:"location"`
	School           string    `json:"school"`
	RegistrationDate time.Time `json:"registration_date"`
	IsAdmin          bool      `json:"is_admin"`
}

type UserIdWrappedApp

type UserIdWrappedApp struct {
	UserId uint `json:"user_id"`
}

type UserProblemAttempt

type UserProblemAttempt struct {
	gorm.Model
	UserId     uint
	ProblemId  uint
	Date       time.Time
	UserAnswer int
}

type UserProblemAttemptRepo

type UserProblemAttemptRepo interface {
	Create(userProblemAttempt *UserProblemAttempt) error
	GetByProblemIdAndUserId(problemId uint, userId uint) []UserProblemAttempt
}

type UserRepo

type UserRepo interface {
	GetByID(ID uint) *User
	GetByUserName(userName string) *User
	GetByEmail(email string) *User
	GetAll() []User
	Create(user *User) error
	Update(user *User) error // updates a specific row, user must have ID setted. Pisa lo que haya!
	Delete(userId uint) error
}

Jump to

Keyboard shortcuts

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