log_controller.go 3.8 KB
package controllers

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

type LogController struct {
	beego.BaseController
}

func (controller *LogController) CreateLog() {
	logService := service.NewLogService(nil)
	createLogCommand := &command.CreateLogCommand{}
	controller.Unmarshal(createLogCommand)
	data, err := logService.CreateLog(createLogCommand)
	controller.Response(data, err)
}

func (controller *LogController) UpdateLog() {
	logService := service.NewLogService(nil)
	updateLogCommand := &command.UpdateLogCommand{}
	controller.Unmarshal(updateLogCommand)
	logId, _ := controller.GetInt(":logId")
	updateLogCommand.LogId = logId
	data, err := logService.UpdateLog(updateLogCommand)
	controller.Response(data, err)
}

func (controller *LogController) GetLog() {
	logService := service.NewLogService(nil)
	getLogQuery := &query.GetLogQuery{}
	logId, _ := controller.GetInt(":logId")
	getLogQuery.LogId = logId
	data, err := logService.GetLog(getLogQuery)
	controller.Response(data, err)
}

func (controller *LogController) RemoveLog() {
	logService := service.NewLogService(nil)
	removeLogCommand := &command.RemoveLogCommand{}
	controller.Unmarshal(removeLogCommand)
	logId, _ := controller.GetInt(":logId")
	removeLogCommand.LogId = logId
	data, err := logService.RemoveLog(removeLogCommand)
	controller.Response(data, err)
}

func (controller *LogController) ListLog() {
	logService := service.NewLogService(nil)
	listLogQuery := &query.ListLogQuery{}
	offset, _ := controller.GetInt("offset")
	listLogQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listLogQuery.Limit = limit
	data, err := logService.ListLog(listLogQuery)
	controller.Response(data, err)
}

func (controller *LogController) SearchLog() {
	logService := service.NewLogService(nil)
	cmd := &command.SearchLogCommand{}
	controller.Unmarshal(cmd)
	cmd.Context = ParseContext(controller.BaseController)
	total, data, err := logService.SearchLog(cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *LogController) TableOperateLog() {
	logService := service.NewLogService(nil)
	cmd := &command.SearchLogCommand{}
	controller.Unmarshal(cmd)
	cmd.LogType = domain.CommonLog.ToString()
	cmd.SortByLogId = "DESC"
	cmd.Context = ParseContext(controller.BaseController)
	total, data, err := logService.SearchLog(cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *LogController) QuerySetLog() {
	logService := service.NewLogService(nil)
	cmd := &command.SearchLogCommand{}
	controller.Unmarshal(cmd)
	cmd.LogType = domain.QuerySetLog.ToString()
	cmd.SortByLogId = "DESC"
	cmd.Context = ParseContext(controller.BaseController)
	total, data, err := logService.SearchLog(cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *LogController) FormulaLog() {
	logService := service.NewLogService(nil)
	cmd := &command.SearchLogCommand{}
	controller.Unmarshal(cmd)
	cmd.LogType = domain.FormulaLog.ToString()
	cmd.SortByLogId = "DESC"
	cmd.Context = ParseContext(controller.BaseController)
	total, data, err := logService.SearchLog(cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *LogController) VerifiedStepLog() {
	logService := service.NewLogService(nil)
	cmd := &command.SearchLogCommand{}
	controller.Unmarshal(cmd)
	cmd.Context = ParseContext(controller.BaseController)
	_, data, err := logService.VerifiedStepLog(cmd)
	controller.Response(data, err)
}