db

package
v0.0.0-...-a57e12b Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2017 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Overview

Package db provides us with everything database related. Connection creation, model representation and other things.

Index

Constants

View Source
const (
	// This category counter assings each part
	// of a module description an integer identifier
	// to map feedback to those individual parts
	// of the description.
	CATEGORY_HEADER = iota
	CATEGORY_LEARNING_OUTCOMES
	CATEGORY_TEACHING_CONTENTS
	CATEGORY_COURSES
	CATEGORY_WORKING_EFFORT
	CATEGORY_INSTRUCTIVE_FORM
	CATEGORY_REQUIREMENTS
	CATEGORY_EXAMINATION
	CATEGORY_NUMBER_TERMS
	CATEGORY_PARTICIPANT_LIMITATION
	CATEGORY_REGISTRATION_FORMALITIES
	CATEGORY_SCRIPT
	CATEGORY_LITERATURE
	CATEGORY_MISCELLANEOUS
)
View Source
const (
	// Privileges have to be kept monotonic.
	// That means, a user with a lower integer
	// privilege value will also have all privileges
	// numerically greater than that value.
	// CAUTION: Changes here will need to be reflected
	// to other places, e.g. template and handler
	// functions of admin's users site.
	PRIVILEGE_ADMIN = iota
	PRIVILEGE_REVIEWER

	// Status groups as increasing integer.
	// CAUTION: Changes here will need to be reflected
	// to other places, e.g. template and handler
	// functions of admin's users site and initial user.
	STATUS_GROUP_PROF = iota
	STATUS_GROUP_WIMI
	STATUS_GROUP_STUDI
	STATUS_GROUP_OTHER
)

Variables

This section is empty.

Functions

func CategoriesByName

func CategoriesByName() map[string]int

CategoriesByName returns a map of all categories queryable by name of category.

func InitDB

func InitDB() *gorm.DB

InitDB connects to the database specified by the .env file. It returns the correctly configured connector.

func SetUpTables

func SetUpTables(db *gorm.DB)

CreateTables sets up the connected database correctly by first deleting all considered tables and afterwards setting new ones up correctly.

func TransferCourses

func TransferCourses(db *gorm.DB, modulesDBPath string)

TransferCourses connects to the provided SQLite database containing the courses as the main parts of all modules and transfers them into the main database.

func TransferExamElements

func TransferExamElements(db *gorm.DB, modulesDBPath string)

TransferExamElement connects to the provided SQLite database that holds exam element information for Portfolio exams and transfers it into the main database.

func TransferModuleCourses

func TransferModuleCourses(db *gorm.DB, modulesDBPath string)

TransferModuleCourses connects to the provided SQLite database containing the links between courses and modules and transfers them into the main database.

func TransferModules

func TransferModules(db *gorm.DB, modulesDBPath string)

TransferModules connects to the provided SQLite database containing the modules and exports them into the services's main database.

func TransferPersons

func TransferPersons(db *gorm.DB, modulesDBPath string)

TransferPersons connects to the provided SQLite database containing the persons involved in the faculty's modules and exports them into the services's main database.

func TransferWorkingEfforts

func TransferWorkingEfforts(db *gorm.DB, modulesDBPath string)

TransferWorkingEffort connects to the provided SQLite database containing information about working effort and transfers it into the main database.

Types

type Course

type Course struct {
	ID                  int    `gorm:"primary_key"`
	Title               string `gorm:"not null"`
	CourseType          sql.NullString
	CourseID            sql.NullString
	CreditHours         sql.NullInt64
	Annotation          sql.NullString
	Content             sql.NullString
	CourseURL           sql.NullString
	DetailedDescription sql.NullString
	Requirements        sql.NullString
	Audience            sql.NullString
	Comment             sql.NullString
	CourseAssessment    sql.NullString
	Literature          sql.NullString
	TeachingContents    sql.NullString
	Cycle               sql.NullString
}

type ExamElement

type ExamElement struct {
	ID          int    `gorm:"primary_key"`
	ModuleID    int    `gorm:"index;not null"`
	Description string `gorm:"not null"`
	Points      int    `gorm:"not null"`
}

type Feedback

type Feedback struct {
	ID       int    `gorm:"primary_key"`
	ModuleID int    `gorm:"index;not null"`
	UserID   string `gorm:"index;not null"`
	Category int    `gorm:"not null"`
	Comment  string `gorm:"not null"`
}

type Module

type Module struct {
	ID                          int            `gorm:"primary_key"`
	ModuleID                    int            `gorm:"not null"`
	Version                     int            `gorm:"not null"`
	Title                       sql.NullString `gorm:"index"`
	TitleEnglish                sql.NullString `gorm:"index"`
	ECTS                        int            `gorm:"not null"`
	Effective                   *time.Time
	Validity                    string `gorm:"not null"`
	Lang                        string `gorm:"not null"`
	MailAddress                 sql.NullString
	Website                     sql.NullString
	AdministrationOffice        sql.NullString
	URL                         string `gorm:"not null;unique"`
	LearningOutcomes            sql.NullString
	LearningOutcomesHTML        template.HTML `gorm:"-"`
	LearningOutcomesEnglish     sql.NullString
	LearningOutcomesEnglishHTML template.HTML `gorm:"-"`
	TeachingContents            sql.NullString
	TeachingContentsHTML        template.HTML `gorm:"-"`
	TeachingContentsEnglish     sql.NullString
	TeachingContentsEnglishHTML template.HTML `gorm:"-"`
	Courses                     []Course      `gorm:"many2many:module_courses;"`
	WorkingEfforts              []WorkingEffort
	WorkingEffortsHTML          []WorkingEffortTemplate `gorm:"-"`
	InstructiveForm             string                  `gorm:"not null"`
	InstructiveFormHTML         template.HTML           `gorm:"-"`
	OptionalRequirements        string                  `gorm:"not null"`
	OptionalRequirementsHTML    template.HTML           `gorm:"-"`
	MandatoryRequirements       sql.NullString
	MandatoryRequirementsHTML   template.HTML `gorm:"-"`
	Graded                      bool          `gorm:"not null"`
	TypeOfExamination           string        `gorm:"not null"`
	ExaminationDescription      sql.NullString
	ExaminationDescriptionHTML  template.HTML `gorm:"-"`
	ExamElements                []ExamElement
	NumberOfTerms               int `gorm:"not null"`
	ParticipantLimitation       sql.NullInt64
	RegistrationFormalities     sql.NullString
	RegistrationFormalitiesHTML template.HTML `gorm:"-"`
	Script                      bool          `gorm:"not null"`
	ScriptElectronic            bool          `gorm:"not null"`
	Literature                  string        `gorm:"not null"`
	LiteratureHTML              template.HTML `gorm:"-"`
	Miscellaneous               sql.NullString
	MiscellaneousHTML           template.HTML `gorm:"-"`
	ReferencePersonID           sql.NullInt64
	ReferencePerson             Person `gorm:"ForeignKey:ReferencePersonID;AssociationForeignKey:Refer;"`
	ResponsiblePersonID         sql.NullInt64
	ResponsiblePerson           Person `gorm:"ForeignKey:ResponsiblePersonID;AssociationForeignKey:Refer;"`
}
type PasswordLink struct {
	ID          string    `gorm:"primary_key"`
	UserID      string    `gorm:"index;not null"`
	User        User      `gorm:"ForeignKey:UserID;AssociationForeignKey:Refer;"`
	SecretToken string    `gorm:"not null;unique"`
	Expires     time.Time `gorm:"not null"`
}

type Person

type Person struct {
	ID        int    `gorm:"primary_key"`
	FirstName string `gorm:"index;not null"`
	LastName  string `gorm:"index;not null"`
}

type SQLiteCourse

type SQLiteCourse struct {
	ID                  int            `gorm:"column:id"`
	Title               string         `gorm:"column:title"`
	CourseType          sql.NullString `gorm:"column:courseType"`
	CourseID            sql.NullString `gorm:"column:courseID"`
	CreditHours         sql.NullInt64  `gorm:"column:creditHours"`
	Annotation          sql.NullString `gorm:"column:annotation"`
	Content             sql.NullString `gorm:"column:content"`
	CourseURL           sql.NullString `gorm:"column:courseURL"`
	DetailedDescription sql.NullString `gorm:"column:detailedDescription"`
	Requirements        sql.NullString `gorm:"column:requirements"`
	Audience            sql.NullString `gorm:"column:audience"`
	Comment             sql.NullString `gorm:"column:comment"`
	CourseAssessment    sql.NullString `gorm:"column:courseAssessment"`
	Literature          sql.NullString `gorm:"column:literature"`
	TeachingContents    sql.NullString `gorm:"column:teachingContents"`
	Cycle               sql.NullString `gorm:"column:cycle"`
}

func (*SQLiteCourse) TableName

func (sqliteCourse *SQLiteCourse) TableName() string

func (SQLiteCourse) ToCourse

func (sqliteCourse SQLiteCourse) ToCourse() Course

type SQLiteExamElement

type SQLiteExamElement struct {
	ID          int    `gorm:"column:id"`
	ModuleID    int    `gorm:"column:module_id"`
	Description string `gorm:"column:description"`
	Points      int    `gorm:"column:points"`
}

func (*SQLiteExamElement) TableName

func (sqliteExamElement *SQLiteExamElement) TableName() string

func (SQLiteExamElement) ToExamElement

func (sqliteExamElement SQLiteExamElement) ToExamElement() ExamElement

type SQLiteModule

type SQLiteModule struct {
	ID                      int            `gorm:"column:id"`
	Title                   sql.NullString `gorm:"column:title"`
	TitleEnglish            sql.NullString `gorm:"column:titleEnglish"`
	ECTS                    int            `gorm:"column:ects"`
	ModuleID                int            `gorm:"column:moduleID"`
	Version                 int            `gorm:"column:version"`
	Effective               *time.Time     `gorm:"column:effective"`
	Validity                string         `gorm:"column:validity"`
	Lang                    string         `gorm:"column:lang"`
	MailAddress             sql.NullString `gorm:"column:mailAddress"`
	Website                 sql.NullString `gorm:"column:website"`
	AdministrationOffice    sql.NullString `gorm:"column:administrationOffice"`
	LearningOutcomes        sql.NullString `gorm:"column:learningOutcomes"`
	LearningOutcomesEnglish sql.NullString `gorm:"column:learningOutcomesEnglish"`
	TeachingContents        sql.NullString `gorm:"column:teachingContents"`
	TeachingContentsEnglish sql.NullString `gorm:"column:teachingContentsEnglish"`
	URL                     string         `gorm:"column:url"`
	InstructiveForm         string         `gorm:"column:instructiveForm"`
	OptionalRequirements    string         `gorm:"column:optionalRequirements"`
	MandatoryRequirements   sql.NullString `gorm:"column:mandatoryRequirements"`
	Graded                  bool           `gorm:"column:graded"`
	TypeOfExamination       string         `gorm:"column:typeOfExamination"`
	ExaminationDescription  sql.NullString `gorm:"column:examinationDescription"`
	NumberOfTerms           int            `gorm:"column:numberOfTerms"`
	ParticipantLimitation   sql.NullInt64  `gorm:"column:participantLimitation"`
	Miscellaneous           sql.NullString `gorm:"column:miscellaneous"`
	Script                  bool           `gorm:"column:script"`
	ScriptElectronic        bool           `gorm:"column:scriptElectronic"`
	Literature              string         `gorm:"column:literature"`
	ReferencePersonID       sql.NullInt64  `gorm:"column:referencePerson_id"`
	ReferencePerson         Person         `gorm:"ForeignKey:ReferencePersonID;AssociationForeignKey:Refer;"`
	ResponsiblePersonID     sql.NullInt64  `gorm:"column:responsiblePerson_id"`
	ResponsiblePerson       Person         `gorm:"ForeignKey:ResponsiblePersonID;AssociationForeignKey:Refer;"`
	RegistrationFormalities sql.NullString `gorm:"column:registrationFormalities"`
}

func (*SQLiteModule) TableName

func (sqliteModule *SQLiteModule) TableName() string

func (SQLiteModule) ToModule

func (sqliteModule SQLiteModule) ToModule(db *gorm.DB) Module

type SQLiteModuleCourses

type SQLiteModuleCourses struct {
	ID       int `gorm:"column:id"`
	ModuleID int `gorm:"column:mtsmodule_id"`
	CourseID int `gorm:"column:course_id"`
}

func (*SQLiteModuleCourses) TableName

func (sqliteModuleCourses *SQLiteModuleCourses) TableName() string

type SQLitePerson

type SQLitePerson struct {
	ID        int    `gorm:"column:id"`
	FirstName string `gorm:"column:firstname"`
	LastName  string `gorm:"column:lastname"`
}

func (*SQLitePerson) TableName

func (sqlitePerson *SQLitePerson) TableName() string

func (SQLitePerson) ToPerson

func (sqlitePerson SQLitePerson) ToPerson() Person

type SQLiteWorkingEffort

type SQLiteWorkingEffort struct {
	ID          int           `gorm:"column:id"`
	ModuleID    sql.NullInt64 `gorm:"column:module_id"`
	CourseID    sql.NullInt64 `gorm:"column:course_id"`
	Description string        `gorm:"column:description"`
	Category    string        `gorm:"column:category"`
	Multiplier  float32       `gorm:"column:multiplier"`
	Hours       float32       `gorm:"column:hours"`
	Total       float32       `gorm:"column:total"`
}

func (*SQLiteWorkingEffort) TableName

func (sqliteWorkingEffort *SQLiteWorkingEffort) TableName() string

func (SQLiteWorkingEffort) ToWorkingEffort

func (sqliteWorkingEffort SQLiteWorkingEffort) ToWorkingEffort() WorkingEffort

type User

type User struct {
	ID           string `gorm:"primary_key"`
	FirstName    string `gorm:"not null"`
	LastName     string `gorm:"not null"`
	Mail         string `gorm:"index;not null;unique"`
	MailVerified bool   `gorm:"not null"`
	PasswordHash string `gorm:"not null;unique"`
	StatusGroup  int    `gorm:"not null"`
	Privileges   int    `gorm:"not null"`
	Enabled      bool   `gorm:"not null"`
}

type WorkingEffort

type WorkingEffort struct {
	ID          int           `gorm:"primary_key"`
	ModuleID    sql.NullInt64 `gorm:"index"`
	CourseID    sql.NullInt64 `gorm:"index"`
	Description string        `gorm:"not null"`
	Category    string        `gorm:"index;not null"`
	Multiplier  float32       `gorm:"not null"`
	Hours       float32       `gorm:"not null"`
	Total       float32       `gorm:"not null"`
}

type WorkingEffortEfforts

type WorkingEffortEfforts struct {
	Description string
	Multiplier  float32
	Hours       float32
	Total       float32
}

WorkingEffortEfforts is a sub type for more fittingly handle working efforts in HTML templates.

type WorkingEffortTemplate

type WorkingEffortTemplate struct {
	Category    string
	Efforts     []WorkingEffortEfforts
	CourseTotal float32
}

WorkingEffortTemplate represents the most useful structure of working effort information for use in HTML templates.

func WorkingEffortsConvert

func WorkingEffortsConvert(workingEfforts []WorkingEffort) []WorkingEffortTemplate

(*WorkingEffort).Convert transfers the working effort elements from the database representation to another one better suited to be used in HTML templates.

Jump to

Keyboard shortcuts

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