homework

package
v0.0.0-...-0505374 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IdSheetArrayToPQ

func IdSheetArrayToPQ(ids []IdSheet) pq.Int64Array

func IdTravailArrayToPQ

func IdTravailArrayToPQ(ids []IdTravail) pq.Int64Array

func InsertManySheetTasks

func InsertManySheetTasks(tx *sql.Tx, items ...SheetTask) error

Insert the links SheetTask in the database. It is a no-op if 'items' is empty.

func InsertManyTravailExceptions

func InsertManyTravailExceptions(tx *sql.Tx, items ...TravailException) error

Insert the links TravailException in the database. It is a no-op if 'items' is empty.

func InsertSheetTask

func InsertSheetTask(db DB, item SheetTask) error

func InsertTravailException

func InsertTravailException(db DB, item TravailException) error

Types

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Prepare(query string) (*sql.Stmt, error)
}

DB groups transaction like objects, and is implemented by *sql.DB and *sql.Tx

type IdSheet

type IdSheet int64

func DeleteSheetsByAnonymouss

func DeleteSheetsByAnonymouss(tx DB, anonymouss_ ...IdTravail) ([]IdSheet, error)

func DeleteSheetsByIDs

func DeleteSheetsByIDs(tx DB, ids ...IdSheet) ([]IdSheet, error)

Deletes the Sheet in the database and returns the ids.

func DeleteSheetsByIdTeachers

func DeleteSheetsByIdTeachers(tx DB, idTeachers_ ...teacher.IdTeacher) ([]IdSheet, error)

func LoadMonoquestionSheet

func LoadMonoquestionSheet(db DB, idMono tasks.IdMonoquestion) (tasks.IdTask, IdSheet, error)

func LoadRandomMonoquestionSheet

func LoadRandomMonoquestionSheet(db DB, idMono tasks.IdRandomMonoquestion) (tasks.IdTask, IdSheet, error)

func ScanIdSheetArray

func ScanIdSheetArray(rs *sql.Rows) ([]IdSheet, error)

ScanIdSheetArray scans the result of a query returning a list of ID's.

type IdSheetSet

type IdSheetSet map[IdSheet]bool

func NewIdSheetSetFrom

func NewIdSheetSetFrom(ids []IdSheet) IdSheetSet

func (IdSheetSet) Add

func (s IdSheetSet) Add(id IdSheet)

func (IdSheetSet) Has

func (s IdSheetSet) Has(id IdSheet) bool

func (IdSheetSet) Keys

func (s IdSheetSet) Keys() []IdSheet

type IdTravail

type IdTravail int64

func DeleteTravailsByIDs

func DeleteTravailsByIDs(tx DB, ids ...IdTravail) ([]IdTravail, error)

Deletes the Travail in the database and returns the ids.

func DeleteTravailsByIdClassrooms

func DeleteTravailsByIdClassrooms(tx DB, idClassrooms_ ...teacher.IdClassroom) ([]IdTravail, error)

func DeleteTravailsByIdSheets

func DeleteTravailsByIdSheets(tx DB, idSheets_ ...IdSheet) ([]IdTravail, error)

func ScanIdTravailArray

func ScanIdTravailArray(rs *sql.Rows) ([]IdTravail, error)

ScanIdTravailArray scans the result of a query returning a list of ID's.

func (IdTravail) AsOptional

func (id IdTravail) AsOptional() OptionalIdTravail

type IdTravailSet

type IdTravailSet map[IdTravail]bool

func NewIdTravailSetFrom

func NewIdTravailSetFrom(ids []IdTravail) IdTravailSet

func (IdTravailSet) Add

func (s IdTravailSet) Add(id IdTravail)

func (IdTravailSet) Has

func (s IdTravailSet) Has(id IdTravail) bool

func (IdTravailSet) Keys

func (s IdTravailSet) Keys() []IdTravail

type OptionalIdTravail

type OptionalIdTravail struct {
	Valid bool
	ID    IdTravail
}

func (*OptionalIdTravail) Scan

func (s *OptionalIdTravail) Scan(src interface{}) error

func (OptionalIdTravail) Value

func (s OptionalIdTravail) Value() (driver.Value, error)

type Sheet

type Sheet struct {
	Id IdSheet

	Title string

	// IdTeacher is the creator of the [Sheet]
	IdTeacher teacher.IdTeacher `gomacro-sql-on-delete:"CASCADE"`

	Level string // tag to classify by expected level, ignored on anonymous sheets

	// Anonymous is not null when the sheet is only
	// link to one [Travail].
	// Anonymous [Sheet]s are deleted when the [Travail] is,
	// and are not shown in the favorites sheets panel.
	Anonymous OptionalIdTravail `gomacro-sql-on-delete:"CASCADE" gomacro-sql-foreign:"Travail"`

	Public bool // only true for admin account

	Matiere teacher.MatiereTag // tag to classify by expected topic, ignored on anonymous sheets
}

Sheet is a list of exercices. gomacro:SQL ADD FOREIGN KEY (Id, Anonymous) REFERENCES Travail(IdSheet, Id) ON DELETE CASCADE

func DeleteSheetById

func DeleteSheetById(tx DB, id IdSheet) (Sheet, error)

Deletes the Sheet and returns the item

func ScanSheet

func ScanSheet(row *sql.Row) (Sheet, error)

func SelectSheet

func SelectSheet(tx DB, id IdSheet) (Sheet, error)

SelectSheet returns the entry matching 'id'.

func (Sheet) Insert

func (item Sheet) Insert(tx DB) (out Sheet, err error)

Insert one Sheet in the database and returns the item with id filled.

func (Sheet) IsVisibleBy

func (qu Sheet) IsVisibleBy(userID teacher.IdTeacher) bool

IsVisibleBy returns `true` if the Sheet is public or owned by `userID`

func (Sheet) Update

func (item Sheet) Update(tx DB) (out Sheet, err error)

Update Sheet in the database and returns the new version.

type SheetTask

type SheetTask struct {
	IdSheet IdSheet `gomacro-sql-on-delete:"CASCADE"`
	Index   int     `json:"-"` // order in the list
	IdTask  tasks.IdTask
}

gomacro:SQL ADD PRIMARY KEY (IdSheet, Index) A task may only appear in one sheet gomacro:SQL ADD UNIQUE (IdTask)

func ScanSheetTask

func ScanSheetTask(row *sql.Row) (SheetTask, error)

func SelectSheetTaskByIdSheetAndIndex

func SelectSheetTaskByIdSheetAndIndex(tx DB, idSheet IdSheet, index int) (item SheetTask, found bool, err error)

SelectSheetTaskByIdSheetAndIndex return zero or one item, thanks to a UNIQUE SQL constraint.

func SelectSheetTaskByIdTask

func SelectSheetTaskByIdTask(tx DB, idTask tasks.IdTask) (item SheetTask, found bool, err error)

SelectSheetTaskByIdTask return zero or one item, thanks to a UNIQUE SQL constraint.

func (SheetTask) Delete

func (item SheetTask) Delete(tx DB) error

Delete the link SheetTask from the database. Only the foreign keys IdSheet, IdTask fields are used in 'item'.

type SheetTasks

type SheetTasks []SheetTask

func DeleteSheetTasksByIdSheets

func DeleteSheetTasksByIdSheets(tx DB, idSheets_ ...IdSheet) (SheetTasks, error)

func DeleteSheetTasksByIdTasks

func DeleteSheetTasksByIdTasks(tx DB, idTasks_ ...tasks.IdTask) (SheetTasks, error)

func ScanSheetTasks

func ScanSheetTasks(rs *sql.Rows) (SheetTasks, error)

func SelectAllSheetTasks

func SelectAllSheetTasks(db DB) (SheetTasks, error)

SelectAll returns all the items in the sheet_tasks table.

func SelectSheetTasksByIdSheets

func SelectSheetTasksByIdSheets(tx DB, idSheets_ ...IdSheet) (SheetTasks, error)

func SelectSheetTasksByIdTasks

func SelectSheetTasksByIdTasks(tx DB, idTasks_ ...tasks.IdTask) (SheetTasks, error)

func (SheetTasks) ByIdSheet

func (items SheetTasks) ByIdSheet() map[IdSheet]SheetTasks

ByIdSheet returns a map with 'IdSheet' as keys.

func (SheetTasks) ByIdTask

func (items SheetTasks) ByIdTask() map[tasks.IdTask]SheetTask

ByIdTask returns a map with 'IdTask' as keys.

func (SheetTasks) EnsureOrder

func (l SheetTasks) EnsureOrder()

EnsureOrder enforce the slice order indicated by `Index`

func (SheetTasks) IdSheets

func (items SheetTasks) IdSheets() []IdSheet

IdSheets returns the list of ids of IdSheet contained in this link table. They are not garanteed to be distinct.

func (SheetTasks) IdTasks

func (items SheetTasks) IdTasks() []tasks.IdTask

IdTasks returns the list of ids of IdTask contained in this link table. They are not garanteed to be distinct.

type Sheets

type Sheets map[IdSheet]Sheet

func ScanSheets

func ScanSheets(rs *sql.Rows) (Sheets, error)

func SelectAllSheets

func SelectAllSheets(db DB) (Sheets, error)

SelectAll returns all the items in the sheets table.

func SelectSheets

func SelectSheets(tx DB, ids ...IdSheet) (Sheets, error)

SelectSheets returns the entry matching the given 'ids'.

func SelectSheetsByAnonymouss

func SelectSheetsByAnonymouss(tx DB, anonymouss_ ...IdTravail) (Sheets, error)

func SelectSheetsByIdTeachers

func SelectSheetsByIdTeachers(tx DB, idTeachers_ ...teacher.IdTeacher) (Sheets, error)

func (Sheets) ByIdTeacher

func (items Sheets) ByIdTeacher() map[teacher.IdTeacher]Sheets

ByIdTeacher returns a map with 'IdTeacher' as keys.

func (Sheets) IDs

func (m Sheets) IDs() []IdSheet

func (Sheets) IdTeachers

func (items Sheets) IdTeachers() []teacher.IdTeacher

IdTeachers returns the list of ids of IdTeacher contained in this table. They are not garanteed to be distinct.

func (Sheets) RestrictVisible

func (qus Sheets) RestrictVisible(userID teacher.IdTeacher)

RestrictVisible remove the sheets not visible by `userID`

type Time

type Time time.Time

Time is an instant in a day.

func (Time) MarshalJSON

func (d Time) MarshalJSON() ([]byte, error)

func (*Time) Scan

func (s *Time) Scan(src interface{}) error

func (*Time) UnmarshalJSON

func (d *Time) UnmarshalJSON(data []byte) error

func (Time) Value

func (s Time) Value() (driver.Value, error)

type Travail

type Travail struct {
	Id          IdTravail
	IdClassroom teacher.IdClassroom `gomacro-sql-on-delete:"CASCADE"`
	IdSheet     IdSheet             `gomacro-sql-on-delete:"CASCADE"`

	// When 'true', the [Sheet] is evaluated, and may only
	// be done once.
	// Notation : a question gives point if it has been successfully completed (at least) once.
	// When 'false' the sheet is always available as free training.
	Noted bool

	// If [Noted] is true,
	// passed the Deadline, the sheet notations may not be modified anymore.
	// Else, this field is ignored
	Deadline Time

	// Pospone the access for students to this work
	ShowAfter Time
}

Travail associates a Sheet to a classroom, with an optional deadline gomacro:SQL ADD UNIQUE(Id, IdSheet)

func DeleteTravailById

func DeleteTravailById(tx DB, id IdTravail) (Travail, error)

Deletes the Travail and returns the item

func ScanTravail

func ScanTravail(row *sql.Row) (Travail, error)

func SelectTravail

func SelectTravail(tx DB, id IdTravail) (Travail, error)

SelectTravail returns the entry matching 'id'.

func SelectTravailByIdAndIdSheet

func SelectTravailByIdAndIdSheet(tx DB, id IdTravail, idSheet IdSheet) (item Travail, found bool, err error)

SelectTravailByIdAndIdSheet return zero or one item, thanks to a UNIQUE SQL constraint.

func (Travail) Insert

func (item Travail) Insert(tx DB) (out Travail, err error)

Insert one Travail in the database and returns the item with id filled.

func (Travail) Update

func (item Travail) Update(tx DB) (out Travail, err error)

Update Travail in the database and returns the new version.

type TravailException

type TravailException struct {
	IdStudent teacher.IdStudent `gomacro-sql-on-delete:"CASCADE"`
	IdTravail IdTravail         `gomacro-sql-on-delete:"CASCADE"`

	// [Deadline] is an optionnal deadline overriding the one
	// setup in the related [Travail].
	Deadline sql.NullTime

	// [IgnoreForMark] may be set to true to ignore this mark
	// when displaying the average.
	IgnoreForMark bool
}

TravailException is a link table storing per student settings for a Travail

gomacro:SQL ADD UNIQUE(IdStudent, IdTravail) gomacro:SQL _SELECT KEY(IdStudent, IdTravail)

func ScanTravailException

func ScanTravailException(row *sql.Row) (TravailException, error)

func SelectTravailExceptionByIdStudentAndIdTravail

func SelectTravailExceptionByIdStudentAndIdTravail(tx DB, idStudent teacher.IdStudent, idTravail IdTravail) (item TravailException, found bool, err error)

SelectTravailExceptionByIdStudentAndIdTravail return zero or one item, thanks to a UNIQUE SQL constraint.

func (TravailException) Delete

func (item TravailException) Delete(tx DB) error

Delete the link TravailException from the database. Only the foreign keys IdStudent, IdTravail fields are used in 'item'.

type TravailExceptions

type TravailExceptions []TravailException

func DeleteTravailExceptionsByIdStudentAndIdTravail

func DeleteTravailExceptionsByIdStudentAndIdTravail(tx DB, idStudent teacher.IdStudent, idTravail IdTravail) (item TravailExceptions, err error)

DeleteTravailExceptionsByIdStudentAndIdTravail deletes the item matching the given fields, returning the deleted items.

func DeleteTravailExceptionsByIdStudents

func DeleteTravailExceptionsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (TravailExceptions, error)

func DeleteTravailExceptionsByIdTravails

func DeleteTravailExceptionsByIdTravails(tx DB, idTravails_ ...IdTravail) (TravailExceptions, error)

func ScanTravailExceptions

func ScanTravailExceptions(rs *sql.Rows) (TravailExceptions, error)

func SelectAllTravailExceptions

func SelectAllTravailExceptions(db DB) (TravailExceptions, error)

SelectAll returns all the items in the travail_exceptions table.

func SelectTravailExceptionsByIdStudentAndIdTravail

func SelectTravailExceptionsByIdStudentAndIdTravail(tx DB, idStudent teacher.IdStudent, idTravail IdTravail) (item TravailExceptions, err error)

SelectTravailExceptionsByIdStudentAndIdTravail selects the items matching the given fields.

func SelectTravailExceptionsByIdStudents

func SelectTravailExceptionsByIdStudents(tx DB, idStudents_ ...teacher.IdStudent) (TravailExceptions, error)

func SelectTravailExceptionsByIdTravails

func SelectTravailExceptionsByIdTravails(tx DB, idTravails_ ...IdTravail) (TravailExceptions, error)

func (TravailExceptions) ByIdStudent

func (items TravailExceptions) ByIdStudent() map[teacher.IdStudent]TravailExceptions

ByIdStudent returns a map with 'IdStudent' as keys.

func (TravailExceptions) ByIdTravail

func (items TravailExceptions) ByIdTravail() map[IdTravail]TravailExceptions

ByIdTravail returns a map with 'IdTravail' as keys.

func (TravailExceptions) IdStudents

func (items TravailExceptions) IdStudents() []teacher.IdStudent

IdStudents returns the list of ids of IdStudent contained in this link table. They are not garanteed to be distinct.

func (TravailExceptions) IdTravails

func (items TravailExceptions) IdTravails() []IdTravail

IdTravails returns the list of ids of IdTravail contained in this link table. They are not garanteed to be distinct.

type Travails

type Travails map[IdTravail]Travail

func ScanTravails

func ScanTravails(rs *sql.Rows) (Travails, error)

func SelectAllTravails

func SelectAllTravails(db DB) (Travails, error)

SelectAll returns all the items in the travails table.

func SelectTravails

func SelectTravails(tx DB, ids ...IdTravail) (Travails, error)

SelectTravails returns the entry matching the given 'ids'.

func SelectTravailsByIdClassrooms

func SelectTravailsByIdClassrooms(tx DB, idClassrooms_ ...teacher.IdClassroom) (Travails, error)

func SelectTravailsByIdSheets

func SelectTravailsByIdSheets(tx DB, idSheets_ ...IdSheet) (Travails, error)

func (Travails) ByIdClassroom

func (items Travails) ByIdClassroom() map[teacher.IdClassroom]Travails

ByIdClassroom returns a map with 'IdClassroom' as keys.

func (Travails) ByIdSheet

func (items Travails) ByIdSheet() map[IdSheet]Travails

ByIdSheet returns a map with 'IdSheet' as keys.

func (Travails) IDs

func (m Travails) IDs() []IdTravail

func (Travails) IdClassrooms

func (items Travails) IdClassrooms() []teacher.IdClassroom

IdClassrooms returns the list of ids of IdClassroom contained in this table. They are not garanteed to be distinct.

func (Travails) IdSheets

func (items Travails) IdSheets() []IdSheet

IdSheets returns the list of ids of IdSheet contained in this table. They are not garanteed to be distinct.

Jump to

Keyboard shortcuts

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