Documentation ¶
Overview ¶
Package model implementiert die structs, die in die Datenbank abgebildet werden.
a couple of predefined data for development time
Index ¶
- Constants
- Variables
- func CanMail() bool
- func ClearTestDb(db *gorm.DB)
- func ConnectDb() *gorm.DB
- func Db() *gorm.DB
- func Encrypt(pw string) string
- func GetMailer() (string, string)
- func InitProdDb(db *gorm.DB) *gorm.DB
- func InitTestDb(db *gorm.DB) *gorm.DB
- func SetMailer(maccount, mpw string)
- func Setup(cfgfile string)
- type Applicant
- type ApplicantData
- type ExamReference
- type Lang
- type Model
- type Oblast
- type User
Constants ¶
const Base = "src/github.com/geobe/gostip"
the relative location of project files
const NQESTION = 10
of questions that could appear in one test ¶
const U_ALL int = U_ANY + U_ENROL + U_POFF + U_UADMIN + U_FULLADMIN
const U_ANY int = 1
const U_ENROL int = 2
const U_FULLADMIN int = 128
const U_POFF int = 4
const U_UADMIN int = 8
Variables ¶
var InitialLanguages = map[Lang]string{ NONE: "_none", DE: "_de", EN: "_en", RU: "_ru", KG: "_kg", OTHER: "_other", }
var InitialOblasts = []Oblast{
{Name: "_bishkek"},
{Name: "_osh_city"},
{Name: "_batken"},
{Name: "_chuy"},
{Name: "_jalalabad"},
{Name: "_naryn"},
{Name: "_osh"},
{Name: "_talas"},
{Name: "_yssykköl"},
{Name: "_foreign"},
}
Functions ¶
func InitProdDb ¶
create some test applicants in a developpment db
func InitTestDb ¶
create some test applicants in a developpment db
Types ¶
type Applicant ¶
type Applicant struct { ID int `gorm:"primary_key"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` Data ApplicantData // `gorm:"ForeignKey:DataID"` }
an applicant for a place at university
func (*Applicant) BeforeUpdate ¶
to maintain a full history of changes of applicant data, old data are kept in the db using gorms 'DeletedAt' mechanism and a new record with updated data is saved to db. Tracebility is ensured by recording the identity of the user who initiated the update. concurrent conflicting updates are detected by comparing changed_at field.
type ApplicantData ¶
type ApplicantData struct { Model ApplicantID int Number uint `gorm:"AUTO_INCREMENT" form:"applid"` LastName string `form:"lastname"` FirstName string `form:"firstname"` FathersName string `form:"fathersname"` LastNameTx string `form:"lastnametx"` FirstNameTx string `form:"firstnametx"` FathersNameTx string `form:"fathersnametx"` Phone string `form:"phone"` Email string `form:"email"` Home string `form:"home"` School string `form:"school"` SchoolOk bool `form:"schoolok"` Oblast Oblast // Belongs To Association OblastID uint `form:"district"` OblastOk bool `form:"districtok"` OrtSum int16 `form:"ort"` OrtMath int16 `form:"ortmath"` OrtPhys int16 `form:"ortphys"` OrtOk bool `form:"ortok"` Results [NQESTION]int `gorm:"-" form:"result#"` // marks multiplied by 10 Resultsave string LanguageResult int `form:"languageresult"` Language Lang `form:"language"` EnrolledAt time.Time `form:"enrolledat"` CancelledAt time.Time `form:"cancelledat"` }
all data of an applicant are stored in a separate structure in order to maintain a full history of changes to these sensitive data form: tags are used to identify html form fields and request parameters
func (*ApplicantData) AfterFind ¶
func (appdata *ApplicantData) AfterFind() (err error)
after loading struct fields from db, exam result values are converted back into an array of int
func (*ApplicantData) BeforeSave ¶
func (appdata *ApplicantData) BeforeSave() (err error)
to easily store grant exam results in db with gorm, an array of (transient) integer result values is converted to a string before saving to db transcription fields are regenerated from original fields with every update
type ExamReference ¶
the exam tasks and maximal results in a specific year's test. Results array records the maximal points achievable in a question. Zero values denote nonexisting questions
func (*ExamReference) AfterFind ¶
func (exref *ExamReference) AfterFind() (err error)
after loading struct fields from db, exam reference values are converted back into an array of int
func (*ExamReference) BeforeSave ¶
func (exref *ExamReference) BeforeSave() (err error)
to easily store grant exam reference values in db with gorm, an array of (transient) integer result values is converted to a string before saving to db. To maintain a short history of changes of exam reference values, tracebility is supported by recording timestamp and login of each user who initiated the update and last updaters id.
func (*ExamReference) QuestionsCount ¶
func (exref *ExamReference) QuestionsCount() int
get the number of available results
type Model ¶
type Model struct { // standard gorrm fields ID uint `gorm:"primary_key"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` // additional fields to make all changes to the // database accountable UpdatedBy string Updater uint DeletedBy string Deleter uint }
Model contains all fields for data management and accountability of changes for sensible data
type User ¶
func InitialValues ¶
make some initial users available for testing and bootstrap