workshop/internal/models/employee.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

46 lines
954 B
Go

package models
import (
//"fmt"
"github.com/jinzhu/gorm"
u "gocommunity.ru/workshop/internal/utils"
)
type Employee struct {
gorm.Model
Vehicles []Vehicle `gorm:"many2many:vehilce_employee;"`
Name string `json:"name"`
Specialization string `json:"specialization"`
Capacity int32 `json:"capacity"`
}
func (employee *Employee) ValidateEmployee() (map[string]interface{}, bool) {
if employee.Name == "" {
return u.Message(false, "cannot be empty!"), false
}
if employee.Specialization == "" {
return u.Message(false, "cannot be empty!"), false
}
if employee.Capacity <= 0 {
return u.Message(false, " < 0"), false
}
return u.Message(true, "success"), true
}
func (employee *Employee) CreateEmployee() map[string]interface{} {
if response, ok := employee.ValidateEmployee(); !ok {
return response
}
GetDB().Create(employee)
resp := u.Message(true, "success")
resp["employee"] = employee
return resp
}