table_controller.go 8.1 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/command"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"

	filecommand "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command"
	fileservice "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service"
)

type TableController struct {
	beego.BaseController
}

func (controller *TableController) CreateTable() {
	tableService := service.NewTableService(nil)
	createTableCommand := &command.CreateTableCommand{}
	controller.Unmarshal(createTableCommand)
	data, err := tableService.CreateTable(createTableCommand)
	controller.Response(data, err)
}

func (controller *TableController) UpdateTable() {
	tableService := service.NewTableService(nil)
	updateTableCommand := &command.UpdateTableCommand{}
	controller.Unmarshal(updateTableCommand)
	tableId, _ := controller.GetInt(":tableId")
	updateTableCommand.TableId = tableId
	data, err := tableService.UpdateTable(updateTableCommand)
	controller.Response(data, err)
}

func (controller *TableController) GetTable() {
	tableService := service.NewTableService(nil)
	getTableQuery := &query.GetTableQuery{}
	tableId, _ := controller.GetInt(":tableId")
	getTableQuery.TableId = tableId
	data, err := tableService.GetTable(getTableQuery)
	controller.Response(data, err)
}

func (controller *TableController) PrepareTable() {
	tableService := service.NewTableService(nil)
	getTableQuery := &query.GetTableQuery{}
	tableId, _ := controller.GetInt("tableId")
	getTableQuery.TableId = tableId
	data, err := tableService.PrepareSubTable(getTableQuery)
	controller.Response(data, err)
}

func (controller *TableController) RemoveTable() {
	tableService := service.NewTableService(nil)
	removeTableCommand := &command.RemoveTableCommand{}
	controller.Unmarshal(removeTableCommand)
	tableId, _ := controller.GetInt(":tableId")
	removeTableCommand.TableId = tableId
	data, err := tableService.RemoveTable(ParseContext(controller.BaseController), removeTableCommand)
	controller.Response(data, err)
}

func (controller *TableController) ListTable() {
	tableService := service.NewTableService(nil)
	listTableQuery := &query.ListTableQuery{}
	offset, _ := controller.GetInt("offset")
	listTableQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listTableQuery.Limit = limit
	data, err := tableService.ListTable(listTableQuery)
	controller.Response(data, err)
}

//func (controller *TableController) SplitDataTable() {
//	tableService := service.NewTableService(nil)
//	splitDataTableCommand := &command.SplitDataTableCommand{}
//	controller.Unmarshal(splitDataTableCommand)
//	data, err := tableService.SplitDataTable(splitDataTableCommand)
//	controller.Response(data, err)
//}
//
//func (controller *TableController) BatchEditSubTable() {
//	tableService := service.NewTableService(nil)
//	batchEditSubTableCommand := &command.BatchEditSubTableCommand{}
//	controller.Unmarshal(batchEditSubTableCommand)
//	data, err := tableService.BatchEditSubTable(batchEditSubTableCommand)
//	controller.Response(data, err)
//}

func (controller *TableController) CopyDataTable() {
	tableService := service.NewTableService(nil)
	copyDataTableCommand := &command.CopyDataTableCommand{}
	controller.Unmarshal(copyDataTableCommand)
	data, err := tableService.CopyDataTable(ParseContext(controller.BaseController), copyDataTableCommand)
	controller.Response(data, err)
}

func (controller *TableController) Search() {
	tableService := service.NewTableService(nil)
	cmd := &query.SearchTableQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.Search(cmd)
	controller.Response(data, err)
}

func (controller *TableController) RelationGraph() {
	tableService := service.NewTableService(nil)
	cmd := &query.SearchTableQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.TableTypes = []string{domain.MainTable.ToString(), domain.SideTable.ToString(), domain.SubTable.ToString()}
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.Search(cmd)
	controller.Response(data, err)
}

func (controller *TableController) SearchAppendedList() {
	tableService := service.NewTableService(nil)
	cmd := &query.SearchTableQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.TableTypes = []string{domain.MainTable.ToString(), domain.SideTable.ToString()}
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.Search(cmd)
	controller.Response(data, err)
}

func (controller *TableController) SearchSubTableList() {
	tableService := service.NewTableService(nil)
	cmd := &query.SearchTableQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.TableTypes = []string{domain.SubTable.ToString()}
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.Search(cmd)
	controller.Response(data, err)
}

func (controller *TableController) UpdateTableStruct() {
	tableService := service.NewTableService(nil)
	cmd := &command.UpdateTableStructCommand{}
	controller.Unmarshal(cmd)
	tableId, _ := controller.GetInt(":tableId")
	cmd.TableId = tableId
	data, err := tableService.UpdateTableStruct(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) AddTableStruct() {
	tableService := service.NewTableService(nil)
	cmd := &command.AddTableStructCommand{}
	controller.Unmarshal(cmd)
	data, err := tableService.AddTableStruct(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) ExportDataTable() {
	tableService := service.NewTableService(nil)
	cmd := &command.TablePreviewCommand{}
	controller.Unmarshal(cmd)
	data, err := tableService.ExportDataTable(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) TablePreview() {
	tableService := service.NewTableService(nil)
	cmd := &command.TablePreviewCommand{}
	controller.Unmarshal(cmd)
	data, err := tableService.TablePreview(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) DBTablePreview() {
	tableService := service.NewTableService(nil)
	cmd := &command.DBTablePreviewCommand{}
	controller.Unmarshal(cmd)
	data, err := tableService.DBTablePreview(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) FieldOptionalValues() {
	tableService := service.NewTableService(nil)
	cmd := &command.FieldOptionalValuesCommand{}
	controller.Unmarshal(cmd)
	data, err := tableService.FieldOptionalValues(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) Preview() {
	tableService := service.NewTableService(nil)
	fileService := fileservice.NewFileService(nil)
	cmd := &struct {
		ObjectType string `json:"objectType"`
	}{}
	controller.Unmarshal(cmd)
	var data interface{}
	var err error
	switch cmd.ObjectType {
	case domain.ObjectFile:
		cmd := &filecommand.LoadDataTableCommand{}
		controller.Unmarshal(cmd)
		data, err = fileService.FilePreview(ParseContext(controller.BaseController), cmd)
	case domain.ObjectMetaTable:
		cmd := &command.TablePreviewCommand{}
		controller.Unmarshal(cmd)
		data, err = tableService.TablePreview(ParseContext(controller.BaseController), cmd)
	case domain.ObjectDBTable:
		cmd := &command.DBTablePreviewCommand{}
		controller.Unmarshal(cmd)
		data, err = tableService.DBTablePreview(ParseContext(controller.BaseController), cmd)
	default:

	}
	controller.Response(data, err)
}

func (controller *TableController) RowEdit() {
	tableService := service.NewTableService(nil)
	cmd := &command.RowEditCommand{}
	Must(controller.Unmarshal(cmd))
	data, err := tableService.RowEdit(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}