table_controller.go 10.5 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.SearchTableRelationGraphQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.TableTypes = []string{domain.MainTable.ToString(), domain.SideTable.ToString(), domain.SubTable.ToString()}
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.RelationGraph(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) SearchQuerySetTables() {
	tableService := service.NewTableService(nil)
	cmd := &query.SearchTableQuery{}
	Must(controller.Unmarshal(cmd))
	if len(cmd.TableTypes) == 0 {
		cmd.TableTypes = []string{domain.MainTable.ToString(), domain.SideTable.ToString(), domain.SubTable.ToString(),
			domain.SubProcessTable.ToString(), domain.CalculateTable.ToString()}
	}
	cmd.Module = domain.ModuleQuerySetCenter
	cmd.ReturnDetailStructInfo = true
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.Search(cmd)
	controller.Response(data, err)
}

func (controller *TableController) TableObjectSearch() {
	tableService := service.NewTableService(nil)
	cmd := &query.SearchTableQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.Context = ParseContext(controller.BaseController)
	data, err := tableService.TableObjectSearch(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) ApplyOn() {
	tableService := service.NewTableService(nil)
	cmd := &command.ApplyOnCommand{}
	Must(controller.Unmarshal(cmd))
	data, err := tableService.ApplyOn(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

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

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

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

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

func (controller *TableController) TablePreview() {
	tableService := service.NewTableService(nil)
	cmd := &command.TablePreviewCommand{}
	Must(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{}
	Must(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{}
	Must(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"`
	}{}
	Must(controller.Unmarshal(cmd))
	var data interface{}
	var err error
	switch cmd.ObjectType {
	case domain.ObjectFile:
		cmd := &filecommand.LoadDataTableCommand{}
		Must(controller.Unmarshal(cmd))
		data, err = fileService.FilePreview(ParseContext(controller.BaseController), cmd)
	case domain.ObjectMetaTable:
		cmd := &command.TablePreviewCommand{}
		Must(controller.Unmarshal(cmd))
		data, err = tableService.TablePreview(ParseContext(controller.BaseController), cmd)
	case domain.ObjectDBTable:
		cmd := &command.DBTablePreviewCommand{}
		Must(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.RowEditCommandV2{}
	Must(controller.Unmarshal(cmd))
	data, err := tableService.RowEditV2(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *TableController) DependencyGraph() {
	tableService := service.NewTableService(nil)
	updateTableCommand := &query.GetTableQuery{}
	controller.Unmarshal(updateTableCommand)
	data, err := tableService.DependencyGraph(ParseContext(controller.BaseController), updateTableCommand)
	controller.Response(data, err)
}