postgres

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BCryptCost = 10
)

Variables

This section is empty.

Functions

func Connect

func Connect(user string, password string, addr string, tlsConfig *tls.Config) *pg.DB

func InitTables

func InitTables(db *pg.DB) error

Types

type Area

type Area struct {
	Id           string `pg:"type:uuid"`
	CurriculumId string `pg:"type:uuid,on_delete:CASCADE"`
	Curriculum   Curriculum
	Name         string
	Subjects     []Subject `pg:"fk:area_id"`
}

type AuthStore

type AuthStore struct {
	DB *pg.DB
}

func (AuthStore) DeleteSession

func (a AuthStore) DeleteSession(token string) error

func (AuthStore) DoPasswordReset

func (a AuthStore) DoPasswordReset(userId string, newPassword string, token string) error

func (AuthStore) GetPasswordResetToken

func (a AuthStore) GetPasswordResetToken(token string) (*auth.PasswordResetToken, error)

func (AuthStore) GetSession

func (a AuthStore) GetSession(token string) (*auth.Session, error)

func (AuthStore) GetUserByEmail

func (a AuthStore) GetUserByEmail(email string) (*auth.User, error)

func (AuthStore) NewPasswordResetToken

func (a AuthStore) NewPasswordResetToken(userId string) (*auth.PasswordResetToken, error)

func (AuthStore) NewSession

func (a AuthStore) NewSession(userId string) (*auth.Session, error)

func (AuthStore) NewUser

func (a AuthStore) NewUser(email string, password string, name string, inviteCode string) (*auth.User, error)

func (AuthStore) ResolveInviteCode

func (a AuthStore) ResolveInviteCode(inviteCodeId string) (*auth.School, error)

type Class

type Class struct {
	Id       string `pg:"type:uuid"`
	SchoolId string `pg:"type:uuid,on_delete:CASCADE"`
	School   School
	Name     string
	// Only use the time of day and timezone (WIB 8.30AM).
	// Ignore other data
	StartTime time.Time `pg:",notnull"`
	EndTime   time.Time `pg:",notnull"`
	Weekdays  []Weekday
	Students  []Student `pg:"many2many:student_to_class,joinFK:class_id"`
}

type ClassStore

type ClassStore struct {
	DB *pg.DB
}

func (ClassStore) CheckPermission

func (s ClassStore) CheckPermission(userId string, classId string) (bool, error)

func (ClassStore) DeleteClass

func (s ClassStore) DeleteClass(id string) (int, error)

func (ClassStore) GetClass

func (s ClassStore) GetClass(id string) (*class.Class, error)

func (ClassStore) UpdateClass

func (s ClassStore) UpdateClass(id string, name string, weekdays []time.Weekday, startTime time.Time, endTime time.Time) (int, error)

type Curriculum

type Curriculum struct {
	Id      string `pg:"type:uuid"`
	Name    string
	Areas   []Area `pg:"fk:curriculum_id"`
	Schools []School
}

type CurriculumStore

type CurriculumStore struct {
	*pg.DB
}

func (CurriculumStore) CheckAreaPermissions

func (s CurriculumStore) CheckAreaPermissions(areaId string, userId string) (bool, error)

func (CurriculumStore) CheckCurriculumPermission

func (s CurriculumStore) CheckCurriculumPermission(curriculumId string, userId string) (bool, error)

func (CurriculumStore) CheckMaterialPermission

func (s CurriculumStore) CheckMaterialPermission(materialId string, userId string) (bool, error)

func (CurriculumStore) CheckSubjectPermissions

func (s CurriculumStore) CheckSubjectPermissions(subjectId string, userId string) (bool, error)

updateSubject manually replace existing data with new ones completely. Without destroying its relationship with existing data.

func (CurriculumStore) DeleteArea

func (s CurriculumStore) DeleteArea(id string) error

func (CurriculumStore) DeleteSubject

func (s CurriculumStore) DeleteSubject(id string) error

func (CurriculumStore) GetArea

func (s CurriculumStore) GetArea(areaId string) (*Area, error)

func (CurriculumStore) GetAreaSubjects

func (s CurriculumStore) GetAreaSubjects(areaId string) ([]Subject, error)

func (CurriculumStore) GetMaterial

func (s CurriculumStore) GetMaterial(materialId string) (*Material, error)

func (CurriculumStore) GetSubject

func (s CurriculumStore) GetSubject(id string) (*Subject, error)

func (CurriculumStore) GetSubjectMaterials

func (s CurriculumStore) GetSubjectMaterials(subjectId string) ([]Material, error)

func (CurriculumStore) NewArea

func (s CurriculumStore) NewArea(name string, curriculumId string) (string, error)

func (CurriculumStore) NewMaterial

func (s CurriculumStore) NewMaterial(name string, subjectId string) (*Material, error)

func (CurriculumStore) NewSubject

func (s CurriculumStore) NewSubject(name string, areaId string, materials []Material) (*Subject, error)

func (CurriculumStore) ReplaceSubject

func (s CurriculumStore) ReplaceSubject(newSubject Subject) error

func (CurriculumStore) UpdateArea

func (s CurriculumStore) UpdateArea(areaId string, name string) error

func (CurriculumStore) UpdateMaterial

func (s CurriculumStore) UpdateMaterial(material *Material, order *int) error

type EmptyCurriculumError

type EmptyCurriculumError struct{}

func (EmptyCurriculumError) Error

func (e EmptyCurriculumError) Error() string

type Gender added in v1.0.3

type Gender int
const (
	NotSet Gender = iota
	Male
	Female
)

type Guardian added in v1.0.3

type Guardian struct {
	Id       string `pg:"type:uuid"`
	Name     string `pg:",notnull"`
	Email    string
	Phone    string
	Note     string
	SchoolId string `pg:"type:uuid"`
	School   School
	Children []Student `pg:"many2many:guardian_to_student,joinFK:guardian_id"`
}

type GuardianRelationship added in v1.0.3

type GuardianRelationship int
const (
	Others GuardianRelationship = iota
	Mother
	Father
)

type GuardianStore added in v1.0.3

type GuardianStore struct {
	*pg.DB
}

func (GuardianStore) CheckPermission added in v1.0.3

func (s GuardianStore) CheckPermission(userId string, guardianId string) (bool, error)

func (GuardianStore) DeleteGuardian added in v1.0.3

func (s GuardianStore) DeleteGuardian(id string) (int, error)

func (GuardianStore) GetGuardian added in v1.0.3

func (s GuardianStore) GetGuardian(id string) (*guardian.Guardian, error)

func (GuardianStore) UpdateGuardian added in v1.0.3

func (s GuardianStore) UpdateGuardian(guardian guardian.Guardian) (int, error)

type GuardianToStudent added in v1.0.3

type GuardianToStudent struct {
	StudentId    string `pg:"type:uuid,on_delete:CASCADE"`
	Student      Student
	GuardianId   string `pg:"type:uuid,on_delete:CASCADE"`
	Guardian     Guardian
	Relationship GuardianRelationship `pg:"type:int"`
}

type Material

type Material struct {
	Id        string `pg:"type:uuid"`
	SubjectId string `pg:"type:uuid,on_delete:CASCADE"`
	Subject   Subject
	Name      string
	Order     int `pg:",use_zero"`
}

type Observation

type Observation struct {
	Id          string `json:"id" pg:",type:uuid"`
	StudentId   string `pg:",type:uuid,on_delete:CASCADE"`
	Student     *Student
	ShortDesc   string    `json:"shortDesc"`
	LongDesc    string    `json:"longDesc"`
	CategoryId  string    `json:"categoryId"`
	CreatedDate time.Time `json:"createdDate"`
	EventTime   *time.Time
	CreatorId   string `pg:",type:uuid,on_delete:SET NULL"`
	Creator     *User
}

type ObservationStore

type ObservationStore struct {
	*pg.DB
}

func (ObservationStore) CheckPermissions

func (s ObservationStore) CheckPermissions(observationId string, userId string) (bool, error)

func (ObservationStore) DeleteObservation

func (o ObservationStore) DeleteObservation(observationId string) error

func (ObservationStore) GetObservation

func (o ObservationStore) GetObservation(id string) (*Observation, error)

func (ObservationStore) UpdateObservation

func (o ObservationStore) UpdateObservation(observationId string, shortDesc string, longDesc string, categoryId string) (*Observation, error)

type PasswordResetToken

type PasswordResetToken struct {
	Token     string    `pg:",pk,type:uuid"`
	CreatedAt time.Time `pg:",notnull"`
	ExpiredAt time.Time `pg:",notnull"`
	UserId    string    `pg:",type:uuid,on_delete:CASCADE,notnull"`
	User      User
}

type School

type School struct {
	Id           string `json:"id" pg:",type:uuid"`
	Name         string `json:"name"`
	InviteCode   string `json:"inviteCode"`
	Users        []User `pg:"many2many:user_to_schools,joinFK:user_id"`
	CurriculumId string `pg:",type:uuid,on_delete:SET NULL"`
	Curriculum   Curriculum
	Guardian     []Guardian
}

type SchoolStore

type SchoolStore struct {
	*pg.DB
}

func (SchoolStore) DeleteCurriculum

func (s SchoolStore) DeleteCurriculum(schoolId string) error

func (SchoolStore) GetCurriculum

func (s SchoolStore) GetCurriculum(schoolId string) (*Curriculum, error)

func (SchoolStore) GetCurriculumAreas

func (s SchoolStore) GetCurriculumAreas(schoolId string) ([]Area, error)

func (SchoolStore) GetGuardians added in v1.0.3

func (s SchoolStore) GetGuardians(schoolId string) ([]Guardian, error)

func (SchoolStore) GetSchool

func (s SchoolStore) GetSchool(schoolId string) (*School, error)

func (SchoolStore) GetSchoolClasses

func (s SchoolStore) GetSchoolClasses(schoolId string) ([]Class, error)

func (SchoolStore) GetStudents

func (s SchoolStore) GetStudents(schoolId string) ([]Student, error)

func (SchoolStore) NewClass

func (s SchoolStore) NewClass(id string, name string, weekdays []time.Weekday, startTime time.Time, endTime time.Time) error

func (SchoolStore) NewDefaultCurriculum

func (s SchoolStore) NewDefaultCurriculum(schoolId string) error

func (SchoolStore) NewGuardian added in v1.0.3

func (s SchoolStore) NewGuardian(schoolId string, name string, email string, phone string, note string) (Guardian, error)

func (SchoolStore) NewSchool

func (s SchoolStore) NewSchool(schoolName string, userId string) (*School, error)

func (SchoolStore) NewStudent

func (s SchoolStore) NewStudent(student Student, classes []string, guardians map[string]int) error

func (SchoolStore) RefreshInviteCode

func (s SchoolStore) RefreshInviteCode(schoolId string) (*School, error)

type Session

type Session struct {
	Token  string `pg:",pk" pg:",type:uuid"`
	UserId string
}

type Student

type Student struct {
	Id          string `json:"id" pg:",type:uuid"`
	Name        string `json:"name"`
	SchoolId    string `pg:"type:uuid,on_delete:CASCADE"`
	School      School
	DateOfBirth *time.Time
	Classes     []Class `pg:"many2many:student_to_class,joinFK:student_id"`
	Gender      Gender  `pg:"type:int"`
	DateOfEntry *time.Time
	Note        string
	CustomId    string
	Active      bool
	ProfilePic  string
	Guardians   []Guardian `pg:"many2many:guardian_to_student,joinFK:student_id"`
}

type StudentMaterialProgress

type StudentMaterialProgress struct {
	MaterialId string `pg:",pk,type:uuid,on_delete:CASCADE"`
	Material   Material
	StudentId  string `pg:",pk,type:uuid,on_delete:CASCADE"`
	Student    Student
	Stage      int
	UpdatedAt  time.Time
}

type StudentStore

type StudentStore struct {
	*pg.DB
}

func (StudentStore) CheckPermissions

func (s StudentStore) CheckPermissions(studentId string, userId string) (bool, error)

func (StudentStore) Delete

func (s StudentStore) Delete(studentId string) error

func (StudentStore) Get

func (s StudentStore) Get(studentId string) (*Student, error)

func (StudentStore) GetObservations

func (s StudentStore) GetObservations(studentId string) ([]Observation, error)

func (StudentStore) GetProgress

func (s StudentStore) GetProgress(studentId string) ([]StudentMaterialProgress, error)

func (StudentStore) InsertObservation

func (s StudentStore) InsertObservation(
	studentId string,
	creatorId string,
	longDesc string,
	shortDesc string,
	category string,
	eventTime *time.Time,
) (*Observation, error)

func (StudentStore) Update

func (s StudentStore) Update(student *Student) error

func (StudentStore) UpdateProgress

func (s StudentStore) UpdateProgress(progress StudentMaterialProgress) (pg.Result, error)

type StudentToClass added in v1.0.3

type StudentToClass struct {
	StudentId string `pg:"type:uuid,on_delete:CASCADE"`
	Student   Student
	ClassId   string `pg:"type:uuid,on_delete:CASCADE"`
	Class     Class
}

type Subject

type Subject struct {
	Id        string `pg:"type:uuid"`
	AreaId    string `pg:"type:uuid,on_delete:CASCADE"`
	Area      Area
	Name      string
	Materials []Material `pg:"fk:subject_id"`
	Order     int        `pg:",use_zero"`
}

type User

type User struct {
	Id       string `json:"id" pg:",type:uuid"`
	Email    string `pg:",unique"`
	Name     string
	Password []byte
	Schools  []School `pg:"many2many:user_to_schools,joinFK:school_id"`
}

type UserStore

type UserStore struct {
	*pg.DB
}

func (UserStore) GetSchools

func (u UserStore) GetSchools(userId string) ([]user.UserSchool, error)

func (UserStore) GetUser

func (u UserStore) GetUser(userId string) (*user.User, error)

type UserToSchool

type UserToSchool struct {
	SchoolId string `pg:",type:uuid"`
	School   School
	UserId   string `pg:",type:uuid"`
	User     User
}

type Weekday

type Weekday struct {
	ClassId string       `pg:",pk,type:uuid,on_delete:CASCADE"`
	Day     time.Weekday `pg:",pk,use_zero"`
	Class   Class
}

Jump to

Keyboard shortcuts

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