47 lines
941 B
Go
47 lines
941 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitlab.guxuan.icu/jinshan_community/internal/config"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/app/api"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/app/schema"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type App struct {
|
|
DB *gorm.DB
|
|
AppAPI *api.App
|
|
}
|
|
|
|
func (a *App) AutoMigrate(ctx context.Context) error {
|
|
return a.DB.AutoMigrate(new(schema.App))
|
|
}
|
|
|
|
func (a *App) Init(ctx context.Context) error {
|
|
if config.C.Storage.DB.AutoMigrate {
|
|
if err := a.AutoMigrate(ctx); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *App) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup) error {
|
|
app := v1.Group("apps")
|
|
{
|
|
app.GET("", a.AppAPI.Query)
|
|
app.GET(":id", a.AppAPI.Get)
|
|
app.POST("", a.AppAPI.Create)
|
|
app.PUT(":id", a.AppAPI.Update)
|
|
app.DELETE(":id", a.AppAPI.Delete)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *App) Release(ctx context.Context) error {
|
|
return nil
|
|
}
|