You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
3.5 KiB
176 lines
3.5 KiB
// Code generated by go-swagger; DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
// This file was generated by the swagger tool.
|
|
// Editing this file might prove futile when you re-run the swagger generate command
|
|
|
|
import (
|
|
strfmt "github.com/go-openapi/strfmt"
|
|
|
|
"github.com/go-openapi/errors"
|
|
"github.com/go-openapi/swag"
|
|
"github.com/go-openapi/validate"
|
|
"github.com/go-xorm/xorm"
|
|
)
|
|
|
|
// Exam exam
|
|
// swagger:model Exam
|
|
|
|
type Exam struct {
|
|
|
|
// ID
|
|
ID int64 `json:"id,omitempty"`
|
|
|
|
// date
|
|
Date strfmt.Date `json:"date,omitempty"`
|
|
|
|
// The period of the day where the exam ends
|
|
// Maximum: 15
|
|
// Minimum: 1
|
|
EndPeriod int64 `json:"endPeriod,omitempty"`
|
|
|
|
// lesson
|
|
Lesson *Lesson `json:"lesson,omitempty" xorm:"-"`
|
|
// ID of the Lesson
|
|
LessonID int64 `json:"-" xorm:"INDEX"`
|
|
|
|
// The period of the day where the exam starts
|
|
// Maximum: 15
|
|
// Minimum: 1
|
|
StartPeriod int64 `json:"startPeriod,omitempty"`
|
|
}
|
|
|
|
/* polymorph Exam ID false */
|
|
|
|
/* polymorph Exam date false */
|
|
|
|
/* polymorph Exam endPeriod false */
|
|
|
|
/* polymorph Exam lesson false */
|
|
|
|
/* polymorph Exam startPeriod false */
|
|
|
|
func findExamsByCourse(e *xorm.Engine, course string) (exams []*Exam, err error) {
|
|
err = e.Join("INNER", "lesson", "lesson.id = exam.lesson_id and course = ?", course).Find(&exams)
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, exam := range exams {
|
|
exam.GetLesson()
|
|
}
|
|
return
|
|
}
|
|
|
|
func FindExamsByCourse(course string) ([]*Exam, error) {
|
|
return findExamsByCourse(x, course)
|
|
}
|
|
|
|
func (m *Exam) getLesson(e *xorm.Engine) (err error) {
|
|
if m.Lesson != nil {
|
|
return nil
|
|
}
|
|
m.Lesson, err = getLessonByID(e, m.LessonID)
|
|
return
|
|
}
|
|
|
|
// GetLesson returns the lesson of the exam
|
|
func (m *Exam) GetLesson() error {
|
|
return m.getLesson(x)
|
|
}
|
|
|
|
// Validate validates this exam
|
|
func (m *Exam) Validate(formats strfmt.Registry) error {
|
|
var res []error
|
|
|
|
if err := m.validateEndPeriod(formats); err != nil {
|
|
// prop
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateLesson(formats); err != nil {
|
|
// prop
|
|
res = append(res, err)
|
|
}
|
|
|
|
if err := m.validateStartPeriod(formats); err != nil {
|
|
// prop
|
|
res = append(res, err)
|
|
}
|
|
|
|
if len(res) > 0 {
|
|
return errors.CompositeValidationError(res...)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *Exam) validateEndPeriod(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.EndPeriod) { // not required
|
|
return nil
|
|
}
|
|
|
|
if err := validate.MinimumInt("endPeriod", "body", int64(m.EndPeriod), 1, false); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := validate.MaximumInt("endPeriod", "body", int64(m.EndPeriod), 15, false); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Exam) validateLesson(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.Lesson) { // not required
|
|
return nil
|
|
}
|
|
|
|
if m.Lesson != nil {
|
|
|
|
if err := m.Lesson.Validate(formats); err != nil {
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
return ve.ValidateName("lesson")
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *Exam) validateStartPeriod(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.StartPeriod) { // not required
|
|
return nil
|
|
}
|
|
|
|
if err := validate.MinimumInt("startPeriod", "body", int64(m.StartPeriod), 1, false); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := validate.MaximumInt("startPeriod", "body", int64(m.StartPeriod), 15, false); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MarshalBinary interface implementation
|
|
func (m *Exam) MarshalBinary() ([]byte, error) {
|
|
if m == nil {
|
|
return nil, nil
|
|
}
|
|
return swag.WriteJSON(m)
|
|
}
|
|
|
|
// UnmarshalBinary interface implementation
|
|
func (m *Exam) UnmarshalBinary(b []byte) error {
|
|
var res Exam
|
|
if err := swag.ReadJSON(b, &res); err != nil {
|
|
return err
|
|
}
|
|
*m = res
|
|
return nil
|
|
}
|
|
|