file_controller.go 6.3 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)
	ctx := ParseContext(controller.BaseController)
	data, err := fileService.CreateFile(ctx, createFileCommand)
	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
	data, err := fileService.GetFile(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))
	cmd.FileType = domain.SourceFile
	cmd.Context = ParseContext(controller.BaseController)
	data, err := fileService.SearchFile(cmd)
	controller.Response(data, err)
}

func (controller *FileController) SearchVerifiedFile() {
	fileService := service.NewFileService(nil)
	cmd := &query.SearchFileQuery{}
	Must(controller.Unmarshal(cmd))
	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)
}