57 lines
1.5 KiB
Go

package autocontrol
import (
"context"
"ifms/internal/config"
"ifms/internal/mods/autocontrol/api"
"ifms/internal/mods/autocontrol/schema"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type AutoControl struct {
DB *gorm.DB
DeviceRunLogAPI *api.DeviceRunLog
DeviceControlLogAPI *api.DeviceControlLog
}
func (a *AutoControl) AutoMigrate(ctx context.Context) error {
return a.DB.AutoMigrate(new(schema.DeviceRunLog), new(schema.DeviceControlLog))
}
func (a *AutoControl) Init(ctx context.Context) error {
if config.C.Storage.DB.AutoMigrate {
if err := a.AutoMigrate(ctx); err != nil {
return err
}
}
return nil
}
func (a *AutoControl) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup) error {
v1 = v1.Group("autocontrol")
deviceRunLog := v1.Group("device-run-logs")
{
deviceRunLog.GET("", a.DeviceRunLogAPI.Query)
deviceRunLog.GET(":id", a.DeviceRunLogAPI.Get)
deviceRunLog.POST("", a.DeviceRunLogAPI.Create)
// deviceRunLog.PUT(":id", a.DeviceRunLogAPI.Update)
// deviceRunLog.DELETE(":id", a.DeviceRunLogAPI.Delete)
}
deviceControlLog := v1.Group("device-control-logs")
{
deviceControlLog.GET("", a.DeviceControlLogAPI.Query)
deviceControlLog.GET(":id", a.DeviceControlLogAPI.Get)
deviceControlLog.POST("", a.DeviceControlLogAPI.Create)
// deviceControlLog.PUT(":id", a.DeviceControlLogAPI.Update)
// deviceControlLog.DELETE(":id", a.DeviceControlLogAPI.Delete)
}
return nil
}
func (a *AutoControl) Release(ctx context.Context) error {
return nil
}