package models import ( "time" "fmt" "github.com/jinzhu/gorm" u "gocommunity.ru/workshop/internal/utils" ) type WorkHistory struct { gorm.Model ClientId int `json:"client_id"` VehicleId int `json:"vehicle_id"` ServiceId int `json:"service_id"` IsFinished bool `json:"is_finished"` } func (workHistory *WorkHistory) CreateWorkHistory() map[string]interface{} { GetDB().Create(workHistory) resp := u.Message(true, "success") resp["workHistory"] = workHistory return resp } func (workHistory *WorkHistory) GetHistoryByDate(start time.Time, finish time.Time) []*WorkHistory { workHistorySlice := make([]*WorkHistory, 0) err := GetDB().Table("work_history").Where("created_at <= ? and updated_at <= ?", start, finish).Find(&workHistorySlice).Error if err != nil { fmt.Println(err) return nil } return workHistorySlice }