go-kimai/models/timesheet_collection.go

240 lines
5.2 KiB
Go
Raw Permalink Normal View History

2023-01-14 14:14:06 +00:00
// 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 (
"context"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// TimesheetCollection timesheet collection
//
// swagger:model TimesheetCollection
type TimesheetCollection struct {
// activity
Activity int64 `json:"activity,omitempty"`
// begin
// Required: true
// Format: date-time
Begin *strfmt.DateTime `json:"begin"`
// billable
// Required: true
Billable *bool `json:"billable"`
// description
Description string `json:"description,omitempty"`
// duration
Duration int64 `json:"duration,omitempty"`
// end
// Format: date-time
End strfmt.DateTime `json:"end,omitempty"`
// exported
// Required: true
Exported *bool `json:"exported"`
// id
ID int64 `json:"id,omitempty"`
// internal rate
InternalRate float32 `json:"internalRate,omitempty"`
// Meta fields
//
// All visible meta (custom) fields registered with this timesheet
MetaFields []*TimesheetMeta `json:"metaFields"`
// project
Project int64 `json:"project,omitempty"`
// rate
// Minimum: 0
Rate *float32 `json:"rate,omitempty"`
// tags
Tags []string `json:"tags"`
// user
User int64 `json:"user,omitempty"`
}
// Validate validates this timesheet collection
func (m *TimesheetCollection) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateBegin(formats); err != nil {
res = append(res, err)
}
if err := m.validateBillable(formats); err != nil {
res = append(res, err)
}
if err := m.validateEnd(formats); err != nil {
res = append(res, err)
}
if err := m.validateExported(formats); err != nil {
res = append(res, err)
}
if err := m.validateMetaFields(formats); err != nil {
res = append(res, err)
}
if err := m.validateRate(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *TimesheetCollection) validateBegin(formats strfmt.Registry) error {
if err := validate.Required("begin", "body", m.Begin); err != nil {
return err
}
if err := validate.FormatOf("begin", "body", "date-time", m.Begin.String(), formats); err != nil {
return err
}
return nil
}
func (m *TimesheetCollection) validateBillable(formats strfmt.Registry) error {
if err := validate.Required("billable", "body", m.Billable); err != nil {
return err
}
return nil
}
func (m *TimesheetCollection) validateEnd(formats strfmt.Registry) error {
if swag.IsZero(m.End) { // not required
return nil
}
if err := validate.FormatOf("end", "body", "date-time", m.End.String(), formats); err != nil {
return err
}
return nil
}
func (m *TimesheetCollection) validateExported(formats strfmt.Registry) error {
if err := validate.Required("exported", "body", m.Exported); err != nil {
return err
}
return nil
}
func (m *TimesheetCollection) validateMetaFields(formats strfmt.Registry) error {
if swag.IsZero(m.MetaFields) { // not required
return nil
}
for i := 0; i < len(m.MetaFields); i++ {
if swag.IsZero(m.MetaFields[i]) { // not required
continue
}
if m.MetaFields[i] != nil {
if err := m.MetaFields[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("metaFields" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("metaFields" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *TimesheetCollection) validateRate(formats strfmt.Registry) error {
if swag.IsZero(m.Rate) { // not required
return nil
}
if err := validate.Minimum("rate", "body", float64(*m.Rate), 0, false); err != nil {
return err
}
return nil
}
// ContextValidate validate this timesheet collection based on the context it is used
func (m *TimesheetCollection) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateMetaFields(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *TimesheetCollection) contextValidateMetaFields(ctx context.Context, formats strfmt.Registry) error {
for i := 0; i < len(m.MetaFields); i++ {
if m.MetaFields[i] != nil {
if err := m.MetaFields[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("metaFields" + "." + strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("metaFields" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *TimesheetCollection) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *TimesheetCollection) UnmarshalBinary(b []byte) error {
var res TimesheetCollection
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}