models

package
v0.0.0-...-8d7c3bf Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteTask

func DeleteTask(id string) error

DeleteTask from db

func InjectSQLSchemas

func InjectSQLSchemas() error

InjectSQLSchemas injects sql schemas in db

func IsAPIKeyCorrect

func IsAPIKeyCorrect(token string) bool

IsAPIKeyCorrect checks if the API key is registered

func UpdateTask

func UpdateTask(task Task) error

UpdateTask in DB

func UpdateUser

func UpdateUser(update *UpdateUserReq) error

Update user in DB

Types

type APIKey

type APIKey struct {
	Token string
	Label string
	// contains filtered or unexported fields
}

APIKey struct

func (*APIKey) Insert

func (a *APIKey) Insert() error

Insert inserts API key in DB

type Class

type Class struct {
	Promotion nulltype.NullInt64  `json:"promotion" db:"promotion"`
	Semester  nulltype.NullString `json:"semester" db:"semester"`
	Region    nulltype.NullString `json:"region" db:"region"`
	Class     nulltype.NullString `json:"class" db:"class"`
}

Class struct

func GetClasses

func GetClasses() ([]Class, error)

GetClasses fetches distinct classes from users in DB

type Filters

type Filters struct {
	StartDate time.Time `json:"start_date" form:"start_date"`
	EndDate   time.Time `json:"end_date" form:"end_date"`

	Completed  *bool       `json:"completed" form:"completed"`
	Visibility *Visibility `json:"visibility" form:"visibility"`
	Subject    *string     `json:"subject" form:"subject"`
}

Filters struct

func (*Filters) Validate

func (f *Filters) Validate() error

Validate filters

type Members

type Members []string

Members string

func (Members) Includes

func (m Members) Includes(s string) bool

Includes checks if s is included in slice

func (Members) MarshalJSON

func (m Members) MarshalJSON() ([]byte, error)

MarshalJSON interface method

func (*Members) Scan

func (m *Members) Scan(src interface{}) error

Scan Members

func (Members) String

func (m Members) String() string

String method

func (*Members) UnmarshalJSON

func (m *Members) UnmarshalJSON(b []byte) error

UnmarshalJSON interface method

func (Members) Value

func (m Members) Value() (driver.Value, error)

Value of members

type Task

type Task struct {

	// Meta
	ShortID string `json:"short_id" db:"short_id"`

	Visibility Visibility `json:"visibility" db:"visibility"`
	// Promotion
	Promotion nulltype.NullInt64  `json:"promotion" db:"promotion"`
	Semester  nulltype.NullString `json:"semester" db:"semester"`

	// Class
	Class  nulltype.NullString `json:"class" db:"class"`
	Region nulltype.NullString `json:"region" db:"region"`

	// Students
	Members Members `json:"members" db:"members"`

	// Body
	Title   string    `json:"title" db:"title"`
	Subject string    `json:"subject" db:"subject"`
	Content string    `json:"content" db:"content"`
	DueDate time.Time `json:"due_date" db:"due_date"`

	Completed   bool       `json:"completed" db:"completed"`
	CompletedAt *time.Time `json:"completed_at" db:"completed_at"`

	Deleted bool `json:"-" db:"deleted"`

	// Meta
	CreatedByLogin string `json:"created_by_login" db:"created_by_login"`
	CreatedBy      string `json:"created_by" db:"created_by"`
	UpdatedByLogin string `json:"updated_by_login" db:"updated_by_login"`
	UpdatedBy      string `json:"updated_by" db:"updated_by"`
	// contains filtered or unexported fields
}

Task truct

func GetAllTasks

func GetAllTasks(start, end time.Time) ([]Task, error)

GetAllTasks returns list of tasks in some timeframe for all promotions

func GetTasksRange

func GetTasksRange(user User, filters Filters) ([]Task, error)

GetTasksRange returns list of tasks in a time for a specific class promotion

func GetTeacherTasksRange

func GetTeacherTasksRange(start, end time.Time) ([]Task, error)

GetTeacherTasksRange returns list of tasks in a time range (for teachers)

func GetUserTask

func GetUserTask(id, login string) (*Task, error)

GetUserTask by shortID

func (*Task) Insert

func (t *Task) Insert() error

Insert task in DB

func (*Task) Mark

func (t *Task) Mark(login string) error

Mark task as done by user

func (Task) PrepareUpdate

func (t Task) PrepareUpdate(def Task, user User) Task

PrepareUpdate prepares new update data

func (*Task) Unmark

func (t *Task) Unmark(login string) error

Unmark task by user

func (*Task) Validate

func (t *Task) Validate() error

Validate task data

type UpdateUserReq

type UpdateUserReq struct {
	Promotion int                 `db:"promotion"`
	Class     nulltype.NullString `db:"class"`
	Region    nulltype.NullString `db:"region"`
	Semester  nulltype.NullString `db:"semester"`
	Login     string              `db:"login"`
}

type User

type User struct {
	Login     string              `json:"login" db:"login"`
	Name      string              `json:"name" db:"name"`
	Promotion nulltype.NullInt64  `json:"promotion" db:"promotion"`
	Class     nulltype.NullString `json:"class" db:"class"`
	Region    nulltype.NullString `json:"region" db:"region"`
	Semester  nulltype.NullString `json:"semester" db:"semester"`
	Email     string              `json:"email" db:"email"`
	Teacher   bool                `json:"teacher" db:"teacher"`
	// contains filtered or unexported fields
}

User struct

func GetUser

func GetUser(login string) (*User, error)

GetUser retrives user by login

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail retrives user by email

func GetUsers

func GetUsers() ([]*User, error)

GetUser retrives user by login

func PrepareUser

func PrepareUser(email string) (User, error)

PrepareUser data

func SearchUser

func SearchUser(query string) ([]User, error)

SearchUser returns slice of users

func (User) CanDeleteTask

func (u User) CanDeleteTask(task Task) bool

CanDeleteTask checks if an user can delete a task

func (User) CanEditTask

func (u User) CanEditTask(task Task) bool

CanEditTask checks if an user can edit a task

func (User) CanViewTask

func (u User) CanViewTask(task Task) bool

CanViewTask checks if an user can view a task

func (*User) Insert

func (u *User) Insert() error

Insert user in DB

type Visibility

type Visibility string

Visibility enum

const (
	// SelfVisibility only the author of task can access it
	SelfVisibility Visibility = "self"
	// PromotionVisibility only the promotion of the author of the task can access it
	PromotionVisibility Visibility = "promotion"
	// ClassVisibility only the class of the author of the task can access it
	ClassVisibility Visibility = "class"
	// StudentsVisibility only selected students can access it
	StudentsVisibility Visibility = "students"
)

Jump to

Keyboard shortcuts

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