128 lines
4.3 KiB
Go
128 lines
4.3 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitlab.guxuan.icu/jinshan_community/internal/config"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/common/api"
|
|
"gitlab.guxuan.icu/jinshan_community/internal/mods/common/schema"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Common struct {
|
|
DB *gorm.DB
|
|
BannerAPI *api.Banner
|
|
NoticeAPI *api.Notice
|
|
WorkOrderAPI *api.WorkOrder
|
|
WorkOrderTypeAPI *api.WorkOrderType
|
|
SurroundingServiceAPI *api.SurroundingService
|
|
SurroundingServiceTypeAPI *api.SurroundingServiceType
|
|
WebSiteAPI *api.WebSite
|
|
HelpAPI *api.Help
|
|
MettingRoomAPI *api.MettingRoom
|
|
MettingRoomOrderAPI *api.MettingRoomOrder
|
|
}
|
|
|
|
func (a *Common) AutoMigrate(ctx context.Context) error {
|
|
return a.DB.AutoMigrate(new(schema.Banner), new(schema.Notice), new(schema.WorkOrder), new(schema.WorkOrderType), new(schema.SurroundingService), new(schema.SurroundingServiceType), new(schema.WebSite), new(schema.Help), new(schema.MettingRoom), new(schema.MettingRoomOrder))
|
|
}
|
|
|
|
func (a *Common) Init(ctx context.Context) error {
|
|
if config.C.Storage.DB.AutoMigrate {
|
|
if err := a.AutoMigrate(ctx); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *Common) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup) error {
|
|
banner := v1.Group("banners")
|
|
{
|
|
banner.GET("", a.BannerAPI.Query)
|
|
banner.GET(":id", a.BannerAPI.Get)
|
|
banner.POST("", a.BannerAPI.Create)
|
|
banner.PUT(":id", a.BannerAPI.Update)
|
|
banner.DELETE(":id", a.BannerAPI.Delete)
|
|
}
|
|
notice := v1.Group("notices")
|
|
{
|
|
notice.GET("", a.NoticeAPI.Query)
|
|
notice.GET(":id", a.NoticeAPI.Get)
|
|
notice.POST("", a.NoticeAPI.Create)
|
|
notice.PUT(":id", a.NoticeAPI.Update)
|
|
notice.DELETE(":id", a.NoticeAPI.Delete)
|
|
}
|
|
workOrder := v1.Group("work-orders")
|
|
{
|
|
workOrder.GET("", a.WorkOrderAPI.Query)
|
|
workOrder.GET(":id", a.WorkOrderAPI.Get)
|
|
workOrder.POST("", a.WorkOrderAPI.Create)
|
|
workOrder.PUT(":id", a.WorkOrderAPI.Update)
|
|
workOrder.DELETE(":id", a.WorkOrderAPI.Delete)
|
|
}
|
|
workOrderType := v1.Group("work-order-types")
|
|
{
|
|
workOrderType.GET("", a.WorkOrderTypeAPI.Query)
|
|
workOrderType.GET(":id", a.WorkOrderTypeAPI.Get)
|
|
workOrderType.POST("", a.WorkOrderTypeAPI.Create)
|
|
workOrderType.PUT(":id", a.WorkOrderTypeAPI.Update)
|
|
workOrderType.DELETE(":id", a.WorkOrderTypeAPI.Delete)
|
|
}
|
|
surroundingService := v1.Group("surrounding-services")
|
|
{
|
|
surroundingService.GET("", a.SurroundingServiceAPI.Query)
|
|
surroundingService.GET(":id", a.SurroundingServiceAPI.Get)
|
|
surroundingService.POST("", a.SurroundingServiceAPI.Create)
|
|
surroundingService.PUT(":id", a.SurroundingServiceAPI.Update)
|
|
surroundingService.DELETE(":id", a.SurroundingServiceAPI.Delete)
|
|
}
|
|
surroundingServiceType := v1.Group("surrounding-service-types")
|
|
{
|
|
surroundingServiceType.GET("", a.SurroundingServiceTypeAPI.Query)
|
|
surroundingServiceType.GET(":id", a.SurroundingServiceTypeAPI.Get)
|
|
surroundingServiceType.POST("", a.SurroundingServiceTypeAPI.Create)
|
|
surroundingServiceType.PUT(":id", a.SurroundingServiceTypeAPI.Update)
|
|
surroundingServiceType.DELETE(":id", a.SurroundingServiceTypeAPI.Delete)
|
|
}
|
|
webSite := v1.Group("web-sites")
|
|
{
|
|
webSite.GET("", a.WebSiteAPI.Query)
|
|
webSite.GET(":id", a.WebSiteAPI.Get)
|
|
webSite.POST("", a.WebSiteAPI.Create)
|
|
webSite.PUT(":id", a.WebSiteAPI.Update)
|
|
webSite.DELETE(":id", a.WebSiteAPI.Delete)
|
|
}
|
|
help := v1.Group("helps")
|
|
{
|
|
help.GET("", a.HelpAPI.Query)
|
|
help.GET(":id", a.HelpAPI.Get)
|
|
help.POST("", a.HelpAPI.Create)
|
|
help.PUT(":id", a.HelpAPI.Update)
|
|
help.DELETE(":id", a.HelpAPI.Delete)
|
|
}
|
|
mettingRoom := v1.Group("metting-rooms")
|
|
{
|
|
mettingRoom.GET("", a.MettingRoomAPI.Query)
|
|
mettingRoom.GET(":id", a.MettingRoomAPI.Get)
|
|
mettingRoom.POST("", a.MettingRoomAPI.Create)
|
|
mettingRoom.PUT(":id", a.MettingRoomAPI.Update)
|
|
mettingRoom.DELETE(":id", a.MettingRoomAPI.Delete)
|
|
}
|
|
mettingRoomOrder := v1.Group("metting-room-orders")
|
|
{
|
|
mettingRoomOrder.GET("", a.MettingRoomOrderAPI.Query)
|
|
mettingRoomOrder.GET(":id", a.MettingRoomOrderAPI.Get)
|
|
mettingRoomOrder.POST("", a.MettingRoomOrderAPI.Create)
|
|
mettingRoomOrder.PUT(":id", a.MettingRoomOrderAPI.Update)
|
|
mettingRoomOrder.DELETE(":id", a.MettingRoomOrderAPI.Delete)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *Common) Release(ctx context.Context) error {
|
|
return nil
|
|
}
|