project_module_files_controller.go 4.0 KB
package controllers

import (
	"encoding/json"

	"github.com/astaxie/beego"
	"github.com/linmadan/egglib-go/web/beego/utils"
	"github.com/tiptok/godevp/pkg/application/projectModuleFiles/command"
	"github.com/tiptok/godevp/pkg/application/projectModuleFiles/query"
	"github.com/tiptok/godevp/pkg/application/projectModuleFiles/service"
)

type ProjectModuleFilesController struct {
	beego.Controller
}

func (controller *ProjectModuleFilesController) CreateProjectModuleFiles() {
	projectModuleFilesService := service.NewProjectModuleFilesService(nil)
	createProjectModuleFilesCommand := &command.CreateProjectModuleFilesCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleFilesCommand)
	data, err := projectModuleFilesService.CreateProjectModuleFiles(createProjectModuleFilesCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *ProjectModuleFilesController) UpdateProjectModuleFiles() {
	projectModuleFilesService := service.NewProjectModuleFilesService(nil)
	updateProjectModuleFilesCommand := &command.UpdateProjectModuleFilesCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleFilesCommand)
	projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
	updateProjectModuleFilesCommand.ProjectModuleFilesId = projectModuleFilesId
	data, err := projectModuleFilesService.UpdateProjectModuleFiles(updateProjectModuleFilesCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *ProjectModuleFilesController) GetProjectModuleFiles() {
	projectModuleFilesService := service.NewProjectModuleFilesService(nil)
	getProjectModuleFilesQuery := &query.GetProjectModuleFilesQuery{}
	projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
	getProjectModuleFilesQuery.ProjectModuleFilesId = projectModuleFilesId
	data, err := projectModuleFilesService.GetProjectModuleFiles(getProjectModuleFilesQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *ProjectModuleFilesController) RemoveProjectModuleFiles() {
	projectModuleFilesService := service.NewProjectModuleFilesService(nil)
	removeProjectModuleFilesCommand := &command.RemoveProjectModuleFilesCommand{}
	json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleFilesCommand)
	projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
	removeProjectModuleFilesCommand.ProjectModuleFilesId = projectModuleFilesId
	data, err := projectModuleFilesService.RemoveProjectModuleFiles(removeProjectModuleFilesCommand)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}

func (controller *ProjectModuleFilesController) ListProjectModuleFiles() {
	projectModuleFilesService := service.NewProjectModuleFilesService(nil)
	listProjectModuleFilesQuery := &query.ListProjectModuleFilesQuery{}
	offset, _ := controller.GetInt("offset")
	listProjectModuleFilesQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProjectModuleFilesQuery.Limit = limit
	data, err := projectModuleFilesService.ListProjectModuleFiles(listProjectModuleFilesQuery)
	var response utils.JsonResponse
	if err != nil {
		response = utils.ResponseError(controller.Ctx, err)
	} else {
		response = utils.ResponseData(controller.Ctx, data)
	}
	controller.Data["json"] = response
	controller.ServeJSON()
}