workshop/internal/models/workHistory.go
Dmitry Sirotkin a33947b5a6
Some checks failed
Deploy to Server (Docker) / deploy (push) Failing after 1m2s
1 2
2025-03-27 20:53:29 +03:00

38 lines
861 B
Go

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
}