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

37 lines
668 B
Go

package models
import (
"fmt"
"github.com/jinzhu/gorm"
u "gocommunity.ru/workshop/internal/utils"
)
type Service struct {
gorm.Model
WorkHistoryId int `json:"work_history_id"`
Price int32 `json:"price"`
Name string `json:"name"`
Description string `json:"description"`
}
func (service *Service) CreateService() map[string]interface{} {
GetDB().Create(service)
resp := u.Message(true, "success")
resp["service"] = service
return resp
}
func GetServices() []*Service {
servicesSlice := make([]*Service, 0)
err := GetDB().Table("services").Find(&servicesSlice).Error
if err != nil {
fmt.Println(err)
return nil
}
return servicesSlice
}