storage

package
v0.0.0-...-12587cc Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: GPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	None = iota
	A
	B
	C
	D
)

answers

View Source
const (
	// calculation
	Right   = 10
	Wrong   = 0
	Missing = 2
	// grading
	Full       = 240
	Insane     = 220
	Incredible = 200
	Good       = 160
	Ok         = 120
)

scores

View Source
const (
	Quest = iota
	About
	ToS
)

types

Variables

View Source
var ErrNoEffect = errors.New("no_effect_error")

ErrNoEffect is returned if a call to Put() has no effect

View Source
var ErrNoKey = errors.New("no_key_error")

ErrNoKey is returned if there was no key provided to identify the wanted user

Functions

func InitStorers

func InitStorers() (u UserStorer, d DocumentStorer, r RelationStorer, err error)

InitStorers initializes all three storers

func ResetDocuments

func ResetDocuments(dStorer *DocumentStorer, questsOnly bool) (err error)

ResetDocuments deletes all documents or, if questsOnly is true, only the documents of type quest

func ResetUsers

func ResetUsers(uStorer *UserStorer, rStorer *RelationStorer) (err error)

ResetUsers deletes all users and their session-cookies and puts the admin back afterwards.

Types

type Document

type Document struct {
	// Path to the .md file
	Path string
	// Grade this document is for
	Grade int
	// Day this document is for
	Day int
	// Solution of the document's question
	Solution int
	// Type of the document (Quest/About/ToS)
	Type int
}

Document represents a markdown-document.

type DocumentStorer

type DocumentStorer struct {
	Storer
	// Complete is true, when all required documents
	// are available
	Complete bool
}

DocumentStorer is a Storer. The extra type is needed by macaron for the identification of the storer.

func NewDocumentStorer

func NewDocumentStorer(name, user, password string, doLog bool) (DocumentStorer, error)

NewDocumentStorer generates a DocumentStorer. If doLog is true, it will create a log file "sql.log"

func (*DocumentStorer) Create

func (s *DocumentStorer) Create(document Document) error

Create creates a new entry

func (*DocumentStorer) Delete

func (s *DocumentStorer) Delete(keys map[string]interface{}) error

Delete deletes all entries defined by the provided keys

func (*DocumentStorer) Get

func (s *DocumentStorer) Get(keys map[string]interface{}) (Document, error)

Get returns one document defined by the provided keys

func (*DocumentStorer) GetAll

func (s *DocumentStorer) GetAll(keys map[string]interface{}) (documents []Document, err error)

GetAll returns a slice of documents defined by the provided keys

func (*DocumentStorer) Put

func (s *DocumentStorer) Put(document Document) error

Put modifies a entry. The document is identified by its grade, day and type values

func (*DocumentStorer) ResetDB

func (s *DocumentStorer) ResetDB() error

ResetDB deletes the document table

type Relation

type Relation struct {
	Teacher   string
	Student   string
	Confirmed bool
}

Relation is a connection between a user (type teacher) and a user (type student)

type RelationStorer

type RelationStorer struct {
	Storer
}

RelationStorer is a normal Storer. The extra type is needed by macaron for the identification of the storer

func NewRelationStorer

func NewRelationStorer(name, user, password string, doLog bool) (RelationStorer, error)

NewRelationStorer generates a RelationStorer. If doLog is true, it will create a log file "sql.log"

func (*RelationStorer) Create

func (s *RelationStorer) Create(relation Relation) error

Create creates a new entry

func (*RelationStorer) Delete

func (s *RelationStorer) Delete(keys map[string]interface{}) error

Delete deletes all entries defined by the provided keys

func (*RelationStorer) Get

func (s *RelationStorer) Get(keys map[string]interface{}) (Relation, error)

Get returns one relation defined by the provided keys

func (*RelationStorer) GetAll

func (s *RelationStorer) GetAll(keys map[string]interface{}) (relations []Relation, err error)

GetAll returns a slice of relations defined by the provided keys

func (*RelationStorer) Put

func (s *RelationStorer) Put(relation Relation) error

Put modifies a entry. The relation is identified by its teacher and student values

func (*RelationStorer) ResetDB

func (s *RelationStorer) ResetDB() error

ResetDB deletes the relation table

type Storer

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

Storer represents a pointer to a xorm.Engine

type User

type User struct {
	Email             string
	Hash              string
	Grade             uint
	Active            bool
	Confirmed         bool
	ConfirmationToken string
	Teacher           bool
	Days              []int
	Score             int
	IsAdmin           bool
	Lang              string
}

User is a person

type UserStorer

type UserStorer struct {
	Storer
}

UserStorer is a normal Storer. The extra type is needed by macaron for the identification of the storer

func NewUserStorer

func NewUserStorer(name, user, password string, doLog bool) (UserStorer, error)

NewUserStorer generates a UserStorer. If doLog is true, it will create a log file "sql.log"

func (*UserStorer) Create

func (s *UserStorer) Create(user User) error

Create creates a new entry

func (*UserStorer) Delete

func (s *UserStorer) Delete(keys map[string]interface{}) error

Delete deletes all entries defined by the provided keys

func (*UserStorer) Get

func (s *UserStorer) Get(keys map[string]interface{}) (User, error)

Get returns one user defined by the provided keys

func (*UserStorer) GetAll

func (s *UserStorer) GetAll(keys map[string]interface{}) (users []User, err error)

GetAll returns a slice of users defined by the provided keys

func (*UserStorer) Put

func (s *UserStorer) Put(user User) error

Put modifies a entry. The user is identified by its email value

func (*UserStorer) ResetDB

func (s *UserStorer) ResetDB() error

ResetDB deletes the user table

Jump to

Keyboard shortcuts

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