teacher

package
v0.0.0-...-867d17b Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 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 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.

func InsertManyTeacherClassrooms

func InsertManyTeacherClassrooms(tx *sql.Tx, items ...TeacherClassroom) error

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

Types

type Classroom

type Classroom struct {
	Id               IdClassroom `json:"id"`
	Name             string      `json:"name"`
	MaxRankThreshold int         // for the last guilde, default to 40000
}

Classroom is one group of student controlled by one or many teachers

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 (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'.

func (ClassroomCode) Insert

func (item ClassroomCode) Insert(db DB) error

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 SelectClassroomsByIdTeacher

func SelectClassroomsByIdTeacher(db DB, id IdTeacher) (Classrooms, error)

SelectClassroomsByIdTeacher does NOT wrap the error.

func (Classrooms) IDs

func (m Classrooms) IDs() []IdClassroom

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 any) 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 any) error

func (Contact) Value

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

type DB

type DB interface {
	Exec(query string, args ...any) (sql.Result, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *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 NewDate

func NewDate(year int, month time.Month, day int) Date

func NewDateFrom

func NewDateFrom(ti time.Time) Date

func (Date) MarshalJSON

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

func (*Date) Scan

func (s *Date) Scan(src any) error

func (Date) Time

func (d Date) Time() time.Time

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 ScanIdClassroomArray

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

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

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 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 MatiereTag

type MatiereTag string

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

const (
	Autre          MatiereTag = "AUTRE"        // AUTRE
	Mathematiques  MatiereTag = "MATHS"        // MATHS
	Francais       MatiereTag = "FRANCAIS"     // FRANCAIS
	HistoireGeo    MatiereTag = "HISTOIRE-GEO" // HISTOIRE-GEO
	Espagnol       MatiereTag = "ESPAGNOL"     // ESPAGNOL
	Italien        MatiereTag = "ITALIEN"      // ITALIEN
	Allemand       MatiereTag = "ALLEMAND"     // ALLEMAND
	Anglais        MatiereTag = "ANGLAIS"      // ANGLAIS
	SES            MatiereTag = "SES"          // SES
	PhysiqueChimie MatiereTag = "PHYSIQUE"     // PHYSIQUE
	SVT            MatiereTag = "SVT"          // 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 TeacherClassroom

type TeacherClassroom struct {
	IdTeacher   IdTeacher
	IdClassroom IdClassroom
}

TeacherClassroom is a link table describing the owners of a classroom.

gomacro:SQL ADD UNIQUE(IdTeacher, IdClassroom)

func ScanTeacherClassroom

func ScanTeacherClassroom(row *sql.Row) (TeacherClassroom, error)

func SelectTeacherClassroomByIdTeacherAndIdClassroom

func SelectTeacherClassroomByIdTeacherAndIdClassroom(tx DB, idTeacher IdTeacher, idClassroom IdClassroom) (item TeacherClassroom, found bool, err error)

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

func (TeacherClassroom) Delete

func (item TeacherClassroom) Delete(tx DB) error

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

func (TeacherClassroom) Insert

func (item TeacherClassroom) Insert(db DB) error

type TeacherClassrooms

type TeacherClassrooms []TeacherClassroom

func DeleteTeacherClassroomsByIdClassrooms

func DeleteTeacherClassroomsByIdClassrooms(tx DB, idClassrooms_ ...IdClassroom) (TeacherClassrooms, error)

func DeleteTeacherClassroomsByIdTeachers

func DeleteTeacherClassroomsByIdTeachers(tx DB, idTeachers_ ...IdTeacher) (TeacherClassrooms, error)

func ScanTeacherClassrooms

func ScanTeacherClassrooms(rs *sql.Rows) (TeacherClassrooms, error)

func SelectAllTeacherClassrooms

func SelectAllTeacherClassrooms(db DB) (TeacherClassrooms, error)

SelectAll returns all the items in the teacher_classrooms table.

func SelectTeacherClassroomsByIdClassrooms

func SelectTeacherClassroomsByIdClassrooms(tx DB, idClassrooms_ ...IdClassroom) (TeacherClassrooms, error)

func SelectTeacherClassroomsByIdTeachers

func SelectTeacherClassroomsByIdTeachers(tx DB, idTeachers_ ...IdTeacher) (TeacherClassrooms, error)

func (TeacherClassrooms) ByIdClassroom

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

ByIdClassroom returns a map with 'IdClassroom' as keys.

func (TeacherClassrooms) ByIdTeacher

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

ByIdTeacher returns a map with 'IdTeacher' as keys.

func (TeacherClassrooms) IdClassrooms

func (items TeacherClassrooms) IdClassrooms() []IdClassroom

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

func (TeacherClassrooms) IdTeachers

func (items TeacherClassrooms) IdTeachers() []IdTeacher

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

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 any) 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