/*
 * @description: 项目管理首页
 * @Author: CP
 * @Date: 2021-01-18 14:57:19
 * @FilePath: \construction_management\web\api\dashboard_api.go
 */
package api

import (
	"github.com/kataras/iris/v12"
	"go.mod/services"
	"go.mod/web/utils"
)

type DashboardApi struct {
	//框架-web应用上下文环境
	Ctx iris.Context
	// // 需要用的service
	ServiceSafe           services.SafeService
	ServiceQuality        services.QualityService
	ServiceProjectMessage services.ProjectMessageService
	ServiceVersion        services.VersionService
}

// @Summary 获得代办事项的内容
// @Tags 代办事项
// @Description 获得代办事项的内容
// @Accept  json
// @Produce  json
// @Security ApiKeyAuth
// @Success 200 {object} viewmodels.FolderContract "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
// @Router /api/dashboard [get]
func (c *DashboardApi) Get() {
	// 获得项目ID
	projectId, err := utils.GetProjectId(c.Ctx)
	if err != nil {
		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
		return
	}
	// 获得项目账号ID
	projectAccountId, err := utils.GetProjectAccountId(c.Ctx)
	if err != nil {
		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
		return
	}

	// 需要你处理
	approverData := c.ServiceSafe.GetPending(projectId, projectAccountId)
	// qualityData := c.ServiceQuality.GetPending(projectId, projectAccountId)

	// 需要你关注
	messageData := c.ServiceProjectMessage.GetAll(projectId, projectAccountId)

	versionData := c.ServiceVersion.Get()

	data := map[string]interface{}{
		"approverData": approverData,
		"messageData":  messageData,
		"versionData":  versionData,
	}
	c.Ctx.JSON(iris.Map{
		"code": 0,
		"msg":  "",
		"data": data,
	})
}
