Organizer ist der Backend-Server der Organizer-App.
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.
Organizer/models/lesson.go

235 lines
4.8 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"
)
// Lesson lesson
// swagger:model Lesson
type Lesson struct {
// DB-ID
ID int64 `json:"-" xorm:"pk autoincr"`
// An additional information like 'Every 14 days only'
AdditionalInformation string `json:"additionalInformation,omitempty"`
// Class or Course
Course string `json:"course,omitempty" xorm:"INDEX"`
// The period of the day where the lesson is
// Maximum: 15
// Minimum: 1
Period int64 `json:"period,omitempty"`
// room
Room string `json:"room,omitempty"`
// subject
Subject *Subject `json:"subject,omitempty" xorm:"-"`
// subject's abbreviation
SubjectAbbreviation string `json:"-" xorm:"INDEX"`
// teacher
Teacher *Teacher `json:"teacher,omitempty" xorm:"-"`
// teacher's identifier
TeacherIdentifier string `json:"-" xorm:"INDEX"`
// weekday
// Maximum: 7
// Minimum: 0
Weekday int64 `json:"weekday,omitempty"`
PartOfTimetable bool `json:"-"`
}
/* polymorph Lesson additionalInformation false */
/* polymorph Lesson course false */
/* polymorph Lesson period false */
/* polymorph Lesson room false */
/* polymorph Lesson subject false */
/* polymorph Lesson teacher false */
/* polymorph Lesson weekday false */
func findLessonsByCourse(e *xorm.Engine, course string) (exams []*Lesson, err error) {
err = e.Where("course = ? AND part_of_timetable = 1", course).Find(&exams)
return
}
func FindLessonsByCourse(course string) ([]*Lesson, error) {
return findLessonsByCourse(x, course)
}
func getLessonByID(e *xorm.Engine, id int64) (*Lesson, error) {
lesson := new(Lesson)
_, err := e.Id(id).Get(lesson)
if err == nil && lesson != nil {
if err = lesson.getTeacher(e); err != nil {
return nil, err
}
if err = lesson.getSubject(e); err != nil {
return nil, err
}
return lesson, nil
}
return nil, err
}
func (m *Lesson) getTeacher(e *xorm.Engine) (err error) {
if m.Teacher != nil {
return nil
}
m.Teacher, err = getTeacherByIdentifier(e, m.TeacherIdentifier)
return
}
func (m *Lesson) GetTeacher() error {
return m.getTeacher(x)
}
func (m *Lesson) getSubject(e *xorm.Engine) (err error) {
if m.Subject != nil {
return nil
}
m.Subject, err = getSubjectByAbbreviation(e, m.SubjectAbbreviation)
return
}
func (m *Lesson) GetSubject() error {
return m.getSubject(x)
}
// Validate validates this lesson
func (m *Lesson) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validatePeriod(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateSubject(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateTeacher(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateWeekday(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Lesson) validatePeriod(formats strfmt.Registry) error {
if swag.IsZero(m.Period) { // not required
return nil
}
if err := validate.MinimumInt("period", "body", int64(m.Period), 1, false); err != nil {
return err
}
if err := validate.MaximumInt("period", "body", int64(m.Period), 15, false); err != nil {
return err
}
return nil
}
func (m *Lesson) validateSubject(formats strfmt.Registry) error {
if swag.IsZero(m.Subject) { // not required
return nil
}
if m.Subject != nil {
if err := m.Subject.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("subject")
}
return err
}
}
return nil
}
func (m *Lesson) validateTeacher(formats strfmt.Registry) error {
if swag.IsZero(m.Teacher) { // not required
return nil
}
if m.Teacher != nil {
if err := m.Teacher.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("teacher")
}
return err
}
}
return nil
}
func (m *Lesson) validateWeekday(formats strfmt.Registry) error {
if swag.IsZero(m.Weekday) { // not required
return nil
}
if err := validate.MinimumInt("weekday", "body", int64(m.Weekday), 0, false); err != nil {
return err
}
if err := validate.MaximumInt("weekday", "body", int64(m.Weekday), 7, false); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *Lesson) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Lesson) UnmarshalBinary(b []byte) error {
var res Lesson
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}