Organizer ist der Backend-Server der Organizer-App.
Organizer/models/replacement_lesson.go

232 lines
5.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-xorm/builder"
"github.com/go-xorm/xorm"
"time"
)
// ReplacementLesson replacement lesson
// swagger:model ReplacementLesson
type ReplacementLesson struct {
// ID
ID int64 `json:"id,omitempty" xorm:"pk autoincr"`
// date
Date strfmt.Date `json:"date,omitempty" xorm:"-"`
DateUnix int64 `json:"-"`
// lesson
Lesson *Lesson `json:"lesson,omitempty" xorm:"-"`
LessonID int64 `json:"-" xorm:"INDEX"`
// replacement lesson
ReplacementLesson *Lesson `json:"replacementLesson,omitempty" xorm:"-"`
ReplacementLessonID int64 `json:"-" xorm:"INDEX"`
}
// AfterSet is invoked from XORM after setting the value of a field of this object.
func (m *ReplacementLesson) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "date_unix":
m.Date = strfmt.Date(time.Unix(m.DateUnix, 0).Local())
}
}
// BerforeUpdate will be invoked by XORM before updating a record
// representing this object.
func (m *ReplacementLesson) BeforeUpdate() {
m.DateUnix = time.Time(m.Date).Unix()
}
// BeforeInsert will be invoked by XORM before inserting a record
// representing this object.
func (m *ReplacementLesson) BeforeInsert() {
m.DateUnix = time.Time(m.Date).Unix()
}
/* polymorph ReplacementLesson ID false */
/* polymorph ReplacementLesson date false */
/* polymorph ReplacementLesson lesson false */
/* polymorph ReplacementLesson replacementLesson false */
type FindReplacementLessonsOptions struct {
StartDate time.Time
EndDate time.Time
Date time.Time
Course string
}
func GetReplacementLessonByID(id int64) (*ReplacementLesson, error) {
return getReplacementLessonByID(x, id)
}
func getReplacementLessonByID(e *xorm.Engine, id int64) (*ReplacementLesson, error) {
rle := new(ReplacementLesson)
if ok, err := e.Id(id).Get(rle); err != nil || !ok {
return nil, err
}
if err := rle.GetLesson(); err != nil {
return nil, err
}
if err := rle.GetReplacementLesson(); err != nil {
return nil, err
}
return rle, nil
}
func (opts *FindReplacementLessonsOptions) ToCond() builder.Cond {
cond := builder.NewCond()
if !opts.Date.IsZero() {
cond = cond.And(builder.Eq{"date_unix": opts.Date.Unix()})
} else {
if !opts.StartDate.IsZero() {
cond = cond.And(builder.Gte{"date_unix": opts.StartDate.Unix()})
}
if !opts.EndDate.IsZero() {
cond = cond.And(builder.Lte{"date_unix": opts.EndDate.Unix()})
}
}
return cond
}
func findReplacementLessons(e *xorm.Engine, options *FindReplacementLessonsOptions) (lessons []*ReplacementLesson, err error) {
if options.Course != "" {
err = e.Join("INNER", "lesson", "lesson.id = replacement_lesson.lesson_id and lesson.course = ?", options.Course).Where(options.ToCond()).Find(&lessons)
} else {
err = e.Where(options.ToCond()).Find(&lessons)
}
if err != nil {
return
}
for _, lesson := range lessons {
if err = lesson.GetLesson(); err != nil {
return
}
if err = lesson.GetReplacementLesson(); err != nil {
return
}
}
return
}
func FindReplacementLessons(options *FindReplacementLessonsOptions) ([]*ReplacementLesson, error) {
return findReplacementLessons(x, options)
}
func (m *ReplacementLesson) 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 replacement lesson
func (m *ReplacementLesson) GetLesson() error {
return m.getLesson(x)
}
func (m *ReplacementLesson) getReplacementLesson(e *xorm.Engine) (err error) {
if m.ReplacementLesson != nil {
return nil
}
m.ReplacementLesson, err = getLessonByID(e, m.ReplacementLessonID)
return
}
// GetLesson returns the replacement lesson of the replacement lesson
func (m *ReplacementLesson) GetReplacementLesson() error {
return m.getReplacementLesson(x)
}
// Validate validates this replacement lesson
func (m *ReplacementLesson) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateLesson(formats); err != nil {
// prop
res = append(res, err)
}
if err := m.validateReplacementLesson(formats); err != nil {
// prop
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *ReplacementLesson) 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 *ReplacementLesson) validateReplacementLesson(formats strfmt.Registry) error {
if swag.IsZero(m.ReplacementLesson) { // not required
return nil
}
if m.ReplacementLesson != nil {
if err := m.ReplacementLesson.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("replacementLesson")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *ReplacementLesson) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *ReplacementLesson) UnmarshalBinary(b []byte) error {
var res ReplacementLesson
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}