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 }