file_controller.go 3.2 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"
)

type FileController struct {
	beego.BaseController
}

func (controller *FileController) CreateFile() {
	fileService := service.NewFileService(nil)
	createFileCommand := &command.CreateFileCommand{}
	controller.Unmarshal(createFileCommand)
	data, err := fileService.CreateFile(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(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) LoadDataTable() {
	fileService := service.NewFileService(nil)
	loadDataTableCommand := &command.LoadDataTableCommand{}
	controller.Unmarshal(loadDataTableCommand)
	data, err := fileService.LoadDataTable(loadDataTableCommand)
	controller.Response(data, err)
}

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

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

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