file_controller.go 8.8 KB
package controllers

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

type FileController struct {
	beego.BaseController
}

func (controller *FileController) CreateFile() {
	fileService := service.NewFileService(nil)
	createFileCommand := &command.CreateFileCommand{}
	controller.Unmarshal(createFileCommand)
	createFileCommand.FileFrom = domain.FileFromByteBankWebClient
	ctx := ParseContext(controller.BaseController)
	data, err := fileService.CreateFile(ctx, createFileCommand)
	controller.Response(data, err)
}

func (controller *FileController) CreateAppTableFile() {
	fileService := service.NewFileService(nil)
	createDigitalAppFileCommand := &command.CreateAppTableFileCommand{}
	controller.Unmarshal(createDigitalAppFileCommand)

	ctx := ParseContext(controller.BaseController)
	createFileCommand, err := fileService.CreateAppTableFile(ctx, createDigitalAppFileCommand)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	createFileCommand.AppKey = ParseAppKey(controller.BaseController)
	data, err := fileService.CreateFile(&domain.Context{}, createFileCommand)
	controller.Response(data, err)
}

func (controller *FileController) DeleteAppTableFile() {
	fileService := service.NewFileService(nil)
	cmd := &command.DeleteAppTableFileCommand{}
	controller.Unmarshal(cmd)
	cmd.AppKey = ParseAppKey(controller.BaseController)
	data, err := fileService.DeleteAppTableFile(&domain.Context{}, cmd)
	controller.Response(data, err)
}

func (controller *FileController) AppendDataAppTableFile() {
	fileService := service.NewFileService(nil)
	cmd := &command.AppTableFileAppendDataCommand{}
	controller.Unmarshal(cmd)
	cmd.AppKey = ParseAppKey(controller.BaseController)
	data, err := fileService.AppTableFileAppendData(&domain.Context{}, cmd)
	controller.Response(data, err)
}

func (controller *FileController) ListAppTableFile() {
	fileService := service.NewFileService(nil)
	cmd := &query.ListAppTableFileCommand{}
	controller.Unmarshal(cmd)
	cmd.AppKey = ParseAppKey(controller.BaseController)
	data, err := fileService.AppTableFileList(&domain.Context{}, cmd)
	controller.Response(data, err)
}

func (controller *FileController) UpdateFile() {
	fileService := service.NewFileService(nil)
	updateFileCommand := &command.UpdateFileCommand{}
	controller.Unmarshal(updateFileCommand)
	fileId, _ := controller.GetInt(":fileId")
	updateFileCommand.FileId = fileId
	data, err := fileService.UpdateFile(updateFileCommand)
	controller.Response(data, err)
}

func (controller *FileController) GetFile() {
	fileService := service.NewFileService(nil)
	getFileQuery := &query.GetFileQuery{}
	fileId, _ := controller.GetInt(":fileId")
	getFileQuery.FileId = fileId
	getFileQuery.FileName = controller.GetString("name")
	getFileQuery.FileType = controller.GetString("type")
	data, err := fileService.GetFile(ParseContext(controller.BaseController), getFileQuery)
	controller.Response(data, err)
}

func (controller *FileController) RemoveFile() {
	fileService := service.NewFileService(nil)
	removeFileCommand := &command.RemoveFileCommand{}
	controller.Unmarshal(removeFileCommand)
	fileId, _ := controller.GetInt(":fileId")
	removeFileCommand.FileId = fileId
	data, err := fileService.RemoveFile(ParseContext(controller.BaseController), removeFileCommand)
	controller.Response(data, err)
}

func (controller *FileController) ListFile() {
	fileService := service.NewFileService(nil)
	listFileQuery := &query.ListFileQuery{}
	offset, _ := controller.GetInt("offset")
	listFileQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listFileQuery.Limit = limit
	data, err := fileService.ListFile(listFileQuery)
	controller.Response(data, err)
}

func (controller *FileController) SearchFile() {
	fileService := service.NewFileService(nil)
	cmd := &query.SearchFileQuery{}
	Must(controller.Unmarshal(cmd))
	cmd.Context = ParseContext(controller.BaseController)
	data, err := fileService.SearchFile(cmd)
	controller.Response(data, err)
}

func (controller *FileController) SearchSourceFile() {
	fileService := service.NewFileService(nil)
	cmd := &query.SearchFileQuery{}
	Must(controller.Unmarshal(cmd))
	if cmd.PageSize == 0 {
		cmd.PageSize = domain.MaxQueryRow
	}
	cmd.FileType = domain.SourceFile
	cmd.Context = ParseContext(controller.BaseController)
	data, err := fileService.SearchFile(cmd)
	controller.Response(data, err)
}

func (controller *FileController) SearchAppSourceFile() {
	fileService := service.NewFileService(nil)
	cmd := &query.SearchFileQuery{}
	Must(controller.Unmarshal(cmd))
	if cmd.PageSize == 0 {
		cmd.PageSize = domain.MaxQueryRow
	}
	cmd.FileType = domain.SourceFile
	data, err := fileService.SearchAppFile(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *FileController) GetAppFile() {
	fileService := service.NewFileService(nil)
	appKey := controller.GetString("app_key", "")
	data, err := fileService.GetAppFile(ParseContext(controller.BaseController), appKey, "")
	controller.Response(data, err)
}

func (controller *FileController) SearchVerifiedFile() {
	fileService := service.NewFileService(nil)
	cmd := &query.SearchFileQuery{}
	Must(controller.Unmarshal(cmd))
	if cmd.PageSize == 0 {
		cmd.PageSize = domain.MaxQueryRow
	}
	cmd.FileType = domain.VerifiedFile
	cmd.Context = ParseContext(controller.BaseController)
	data, err := fileService.SearchFile(cmd)
	controller.Response(data, err)
}

func (controller *FileController) FilePreview() {
	fileService := service.NewFileService(nil)
	loadDataTableCommand := &command.LoadDataTableCommand{}
	controller.Unmarshal(loadDataTableCommand)
	data, err := fileService.FilePreview(ParseContext(controller.BaseController), loadDataTableCommand)
	controller.Response(data, err)
}

func (controller *FileController) PrepareTemporaryFile() {
	fileService := service.NewFileService(nil)
	loadDataTableCommand := &command.PrepareTemporaryFileCommand{}
	controller.Unmarshal(loadDataTableCommand)
	data, err := fileService.PrepareTemporaryFile(ParseContext(controller.BaseController), loadDataTableCommand)
	controller.Response(data, err)
}

func (controller *FileController) EditDataTable() {
	fileService := service.NewFileService(nil)
	editDataTableCommand := &command.EditDataTableCommand{}
	Must(controller.Unmarshal(editDataTableCommand))
	data, err := fileService.EditDataTable(ParseContext(controller.BaseController), editDataTableCommand)
	controller.Response(data, err)
}

func (controller *FileController) FlushDataTable() {
	fileService := service.NewFileService(nil)
	flushDataTableCommand := &command.FlushDataTableCommand{}
	controller.Unmarshal(flushDataTableCommand)
	data, err := fileService.FlushDataTable(ParseContext(controller.BaseController), flushDataTableCommand)
	controller.Response(data, err)
}

func (controller *FileController) GenerateMainTable() {
	fileService := service.NewFileService(nil)
	generateMainTableCommand := &command.GenerateMainTableCommand{}
	controller.Unmarshal(generateMainTableCommand)
	data, err := fileService.GenerateMainTable(ParseContext(controller.BaseController), generateMainTableCommand)
	controller.Response(data, err)
}

func (controller *FileController) AppendDataToTable() {
	fileService := service.NewFileService(nil)
	cmd := &command.AppendDataToTableCommand{}
	controller.Unmarshal(cmd)
	data, err := fileService.AppendDataToTable(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *FileController) AppendDataToTablePreflightCheck() {
	fileService := service.NewFileService(nil)
	cmd := &command.AppendDataToTableCommand{}
	controller.Unmarshal(cmd)
	data, err := fileService.AppendDataToTablePreflightCheck(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *FileController) CancelVerifyingFile() {
	fileService := service.NewFileService(nil)
	cmd := &command.CancelVerifyingFileCommand{}
	controller.Unmarshal(cmd)
	data, err := fileService.CancelVerifyingFile(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *FileController) CheckFileVerifyStatus() {
	fileService := service.NewFileService(nil)
	cmd := &command.CheckFileVerifyStatusCommand{}
	controller.Unmarshal(cmd)
	data, err := fileService.CheckFileVerifyStatus(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}

func (controller *FileController) ExportFile() {
	fileService := service.NewFileService(nil)
	cmd := &command.ExportFileCommand{}
	controller.Unmarshal(cmd)
	data, err := fileService.ExportFile(ParseContext(controller.BaseController), cmd)
	controller.Response(data, err)
}