teacher

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

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package teacher provides the data structures related to teacher and student accounts.

Index

Constants

View Source
const DateLayout = "2006-01-02"

Variables

This section is empty.

Functions

func CleanupClassroomCodes

func CleanupClassroomCodes(db DB) error

CleanupClassroomCodes removes the expired codes.

func IdClassroomArrayToPQ

func IdClassroomArrayToPQ(ids []IdClassroom) pq.Int64Array

func IdStudentArrayToPQ

func IdStudentArrayToPQ(ids []IdStudent) pq.Int64Array

func IdTeacherArrayToPQ

func IdTeacherArrayToPQ(ids []IdTeacher) pq.Int64Array

func InsertClassroomCode

func InsertClassroomCode(db DB, item ClassroomCode) error

func InsertManyClassroomCodes

func InsertManyClassroomCodes(tx *sql.Tx, items ...ClassroomCode) error

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

Types

type Classroom

type Classroom struct {
	Id               IdClassroom `json:"id"`
	IdTeacher        IdTeacher   `json:"id_teacher" gomacro-sql-on-delete:"CASCADE"`
	Name             string      `json:"name"`
	MaxRankThreshold int         // for the last guilde, default to 40000
}

Classroom is one group of student controlled by a teacher gomacro:SQL ADD UNIQUE(Id, IdTeacher)

func DeleteClassroomById

func DeleteClassroomById(tx DB, id IdClassroom) (Classroom, error)

Deletes the Classroom and returns the item

func ScanClassroom

func ScanClassroom(row *sql.Row) (Classroom, error)

func SelectClassroom

func SelectClassroom(tx DB, id IdClassroom) (Classroom, error)

SelectClassroom returns the entry matching 'id'.

func SelectClassroomByIdAndIdTeacher

func SelectClassroomByIdAndIdTeacher(tx DB, id IdClassroom, idTeacher IdTeacher) (item Classroom, found bool, err error)

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

func (Classroom) Insert

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

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

func (Classroom) Update

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

Update Classroom in the database and returns the new version.

type ClassroomCode

type ClassroomCode struct {
	IdClassroom IdClassroom `gomacro-sql-on-delete:"CASCADE"`
	Code        string
	ExpiresAt   Time
}

ClassroomCode is a time limited, user friendly, code to access one class gomacro:SQL ADD UNIQUE(Code)

func ScanClassroomCode

func ScanClassroomCode(row *sql.Row) (ClassroomCode, error)

func SelectClassroomCodeByCode

func SelectClassroomCodeByCode(tx DB, code string) (item ClassroomCode, found bool, err error)

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

func (ClassroomCode) Delete

func (item ClassroomCode) Delete(tx DB) error

Delete the link ClassroomCode from the database. Only the foreign keys IdClassroom fields are used in 'item'.

type ClassroomCodes

type ClassroomCodes []ClassroomCode

func DeleteClassroomCodesByIdClassrooms

func DeleteClassroomCodesByIdClassrooms(tx DB, idClassrooms_ ...IdClassroom) (ClassroomCodes, error)

func ScanClassroomCodes

func ScanClassroomCodes(rs *sql.Rows) (ClassroomCodes, error)

func SelectAllClassroomCodes

func SelectAllClassroomCodes(db DB) (ClassroomCodes, error)

SelectAll returns all the items in the classroom_codes table.

func SelectClassroomCodesByIdClassrooms

func SelectClassroomCodesByIdClassrooms(tx DB, idClassrooms_ ...IdClassroom) (ClassroomCodes, error)

func (ClassroomCodes) ByIdClassroom

func (items ClassroomCodes) ByIdClassroom() map[IdClassroom]ClassroomCodes

ByIdClassroom returns a map with 'IdClassroom' as keys.

func (ClassroomCodes) Codes

func (ccs ClassroomCodes) Codes() map[string]bool

func (ClassroomCodes) IdClassrooms

func (items ClassroomCodes) IdClassrooms() []IdClassroom

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

type Classrooms

type Classrooms map[IdClassroom]Classroom

func ScanClassrooms

func ScanClassrooms(rs *sql.Rows) (Classrooms, error)

func SelectAllClassrooms

func SelectAllClassrooms(db DB) (Classrooms, error)

SelectAll returns all the items in the classrooms table.

func SelectClassrooms

func SelectClassrooms(tx DB, ids ...IdClassroom) (Classrooms, error)

SelectClassrooms returns the entry matching the given 'ids'.

func SelectClassroomsByIdTeachers

func SelectClassroomsByIdTeachers(tx DB, idTeachers_ ...IdTeacher) (Classrooms, error)

func (Classrooms) ByIdTeacher

func (items Classrooms) ByIdTeacher() map[IdTeacher]Classrooms

ByIdTeacher returns a map with 'IdTeacher' as keys.

func (Classrooms) IDs

func (m Classrooms) IDs() []IdClassroom

func (Classrooms) IdTeachers

func (items Classrooms) IdTeachers() []IdTeacher

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

type Client

type Client struct {
	Device string    // the name of the device
	Time   time.Time // when the client was connected
}

type Clients

type Clients []Client

func (*Clients) Scan

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

func (Clients) Value

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

type Contact

type Contact struct {
	Name string
	URL  string
}

func (*Contact) Scan

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

func (Contact) Value

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

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 Date

type Date time.Time

Date represents a day, without time zone consideration

func (Date) MarshalJSON

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

func (*Date) Scan

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

func (*Date) UnmarshalJSON

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

func (Date) Value

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

type IdClassroom

type IdClassroom int64

func DeleteClassroomsByIDs

func DeleteClassroomsByIDs(tx DB, ids ...IdClassroom) ([]IdClassroom, error)

Deletes the Classroom in the database and returns the ids.

func DeleteClassroomsByIdTeachers

func DeleteClassroomsByIdTeachers(tx DB, idTeachers_ ...IdTeacher) ([]IdClassroom, error)

func ScanIdClassroomArray

func ScanIdClassroomArray(rs *sql.Rows) ([]IdClassroom, error)

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

type IdClassroomSet

type IdClassroomSet map[IdClassroom]bool

func NewIdClassroomSetFrom

func NewIdClassroomSetFrom(ids []IdClassroom) IdClassroomSet

func (IdClassroomSet) Add

func (s IdClassroomSet) Add(id IdClassroom)

func (IdClassroomSet) Has

func (s IdClassroomSet) Has(id IdClassroom) bool

func (IdClassroomSet) Keys

func (s IdClassroomSet) Keys() []IdClassroom

type IdStudent

type IdStudent int64

func DeleteStudentsByIDs

func DeleteStudentsByIDs(tx DB, ids ...IdStudent) ([]IdStudent, error)

Deletes the Student in the database and returns the ids.

func DeleteStudentsByIdClassrooms

func DeleteStudentsByIdClassrooms(tx DB, idClassrooms_ ...IdClassroom) ([]IdStudent, error)

func ScanIdStudentArray

func ScanIdStudentArray(rs *sql.Rows) ([]IdStudent, error)

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

type IdStudentSet

type IdStudentSet map[IdStudent]bool

func NewIdStudentSetFrom

func NewIdStudentSetFrom(ids []IdStudent) IdStudentSet

func (IdStudentSet) Add

func (s IdStudentSet) Add(id IdStudent)

func (IdStudentSet) Has

func (s IdStudentSet) Has(id IdStudent) bool

func (IdStudentSet) Keys

func (s IdStudentSet) Keys() []IdStudent

type IdTeacher

type IdTeacher int64

func DeleteTeachersByIDs

func DeleteTeachersByIDs(tx DB, ids ...IdTeacher) ([]IdTeacher, error)

Deletes the Teacher in the database and returns the ids.

func ScanIdTeacherArray

func ScanIdTeacherArray(rs *sql.Rows) ([]IdTeacher, error)

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

type IdTeacherSet

type IdTeacherSet map[IdTeacher]bool

func NewIdTeacherSetFrom

func NewIdTeacherSetFrom(ids []IdTeacher) IdTeacherSet

func (IdTeacherSet) Add

func (s IdTeacherSet) Add(id IdTeacher)

func (IdTeacherSet) Has

func (s IdTeacherSet) Has(id IdTeacher) bool

func (IdTeacherSet) Keys

func (s IdTeacherSet) Keys() []IdTeacher

type MatiereTag

type MatiereTag string

MatiereTag are special tags to indicate the topic of a question/exercice

const (
	Autre          MatiereTag = "AUTRE"
	Mathematiques  MatiereTag = "MATHS"
	Francais       MatiereTag = "FRANCAIS"
	HistoireGeo    MatiereTag = "HISTOIRE-GEO"
	Espagnol       MatiereTag = "ESPAGNOL"
	Italien        MatiereTag = "ITALIEN"
	Allemand       MatiereTag = "ALLEMAND"
	Anglais        MatiereTag = "ANGLAIS"
	SES            MatiereTag = "SES"
	PhysiqueChimie MatiereTag = "PHYSIQUE"
	SVT            MatiereTag = "SVT"
)

type Student

type Student struct {
	Id       IdStudent
	Name     string
	Surname  string
	Birthday Date

	IdClassroom IdClassroom `json:"id_classroom" gomacro-sql-on-delete:"CASCADE"`

	Clients Clients
}

Student is a student profile, always attached to a classroom.

func DeleteStudentById

func DeleteStudentById(tx DB, id IdStudent) (Student, error)

Deletes the Student and returns the item

func ScanStudent

func ScanStudent(row *sql.Row) (Student, error)

func SelectStudent

func SelectStudent(tx DB, id IdStudent) (Student, error)

SelectStudent returns the entry matching 'id'.

func (Student) Insert

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

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

func (Student) Update

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

Update Student in the database and returns the new version.

type Students

type Students map[IdStudent]Student

func ScanStudents

func ScanStudents(rs *sql.Rows) (Students, error)

func SelectAllStudents

func SelectAllStudents(db DB) (Students, error)

SelectAll returns all the items in the students table.

func SelectStudents

func SelectStudents(tx DB, ids ...IdStudent) (Students, error)

SelectStudents returns the entry matching the given 'ids'.

func SelectStudentsByIdClassrooms

func SelectStudentsByIdClassrooms(tx DB, idClassrooms_ ...IdClassroom) (Students, error)

func (Students) ByIdClassroom

func (items Students) ByIdClassroom() map[IdClassroom]Students

ByIdClassroom returns a map with 'IdClassroom' as keys.

func (Students) IDs

func (m Students) IDs() []IdStudent

func (Students) IdClassrooms

func (items Students) IdClassrooms() []IdClassroom

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

type Teacher

type Teacher struct {
	Id                  IdTeacher `json:"id"`
	Mail                string    `json:"mail"`
	PasswordCrypted     []byte    `json:"password_crypted"`      // crypted
	IsAdmin             bool      `json:"is_admin"`              // almost always false
	HasSimplifiedEditor bool      `json:"has_simplified_editor"` // true will hide maths widgets in editor
	Contact             Contact   `json:"contact"`               // if empty, [Mail] is used
	FavoriteMatiere     MatiereTag
}

Teacher stores the data associated to one teacher account gomacro:SQL ADD UNIQUE(Mail)

func DeleteTeacherById

func DeleteTeacherById(tx DB, id IdTeacher) (Teacher, error)

Deletes the Teacher and returns the item

func ScanTeacher

func ScanTeacher(row *sql.Row) (Teacher, error)

func SelectTeacher

func SelectTeacher(tx DB, id IdTeacher) (Teacher, error)

SelectTeacher returns the entry matching 'id'.

func SelectTeacherByMail

func SelectTeacherByMail(tx DB, mail string) (item Teacher, found bool, err error)

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

func (Teacher) Insert

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

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

func (Teacher) Update

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

Update Teacher in the database and returns the new version.

type Teachers

type Teachers map[IdTeacher]Teacher

func ScanTeachers

func ScanTeachers(rs *sql.Rows) (Teachers, error)

func SelectAllTeachers

func SelectAllTeachers(db DB) (Teachers, error)

SelectAll returns all the items in the teachers table.

func SelectTeachers

func SelectTeachers(tx DB, ids ...IdTeacher) (Teachers, error)

SelectTeachers returns the entry matching the given 'ids'.

func (Teachers) IDs

func (m Teachers) IDs() []IdTeacher

type Time

type Time time.Time

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)

Jump to

Keyboard shortcuts

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