workshop/internal/models/workHistory.go
Dmitry Sirotkin 9677e0d7ab 4
2025-03-28 19:03:56 +03:00

44 lines
1.0 KiB
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"`
Vehicle Vehicle `json:"vehicle"`
Service Service `json:"service"`
EmployeeId int `json:"employee_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) GetHistoryByDateAndEmployeeId(start time.Time, finish time.Time, employeeId int) []*WorkHistory {
workHistorySlice := make([]*WorkHistory, 0)
err := GetDB().Table("work_histories").
Where("employee_id = ? and created_at <= ? and updated_at <= ?", employeeId, start, finish).
Preload("client").
Preload("vehicle").
Preload("service").
Find(&workHistorySlice).Error
if err != nil {
fmt.Println(err)
return nil
}
return workHistorySlice
}