118 lines
2.9 KiB
Go
118 lines
2.9 KiB
Go
package server
|
|
|
|
import (
|
|
"admin/apps/game/model/dto"
|
|
"admin/internal/consts"
|
|
"admin/internal/context"
|
|
"admin/lib/httpclient"
|
|
"admin/lib/xlog"
|
|
"strings"
|
|
)
|
|
|
|
func (ctl *controller) GetRoutes(ctx *context.WebContext, params *dto.NilReq, rsp *dto.RoutesListRsp) error {
|
|
projects, err := ctl.svc.GetProjectList()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, project := range projects {
|
|
projectDto := &dto.ProjectInitInfo{
|
|
ProjectId: project.ProjectPo.ProjectId,
|
|
ProjectName: project.ProjectPo.Name,
|
|
}
|
|
for _, v := range ctl.svc.GetSupportResourcesList() {
|
|
if v.Resource == consts.ResourcesName_Project {
|
|
continue
|
|
}
|
|
projectDto.ResourceList = append(projectDto.ResourceList, v)
|
|
}
|
|
rsp.Projects = append(rsp.Projects, projectDto)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) CommandList(ctx *context.WebContext, params *dto.CommandListReq, rsp *dto.CommandListRsp) error {
|
|
|
|
url := params.Addr + "/api/commandlist"
|
|
|
|
xlog.Debugf("request url:%v command list", url)
|
|
|
|
cmdListRsp := make(map[string]any)
|
|
err := httpclient.Request(url, "get", nil, &cmdListRsp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
xlog.Debugf("command list rsp:%+v", cmdListRsp)
|
|
|
|
ctx.Ok(cmdListRsp)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourceList(ctx *context.WebContext, params *dto.CommonListReq, rsp *dto.CommonListRsp) error {
|
|
projectId := getCtxURIProjectId(ctx)
|
|
resource := getCtxURIResource(ctx)
|
|
|
|
apiAddr, err := ctl.svc.GetProjectInvokeApiAddr(projectId, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
url := apiAddr[0] + "/api/" + resource
|
|
|
|
listRsp := make(map[string]any)
|
|
err = httpclient.Request(url, "get", nil, &listRsp)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
xlog.Debugf("receive project %v resource %v list", "projectId", resource)
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourcePost(ctx *context.WebContext, params *dto.CommonPostReq, rsp *dto.CommonPostRsp) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourcePut(ctx *context.WebContext, params *dto.CommonPutReq, rsp *dto.CommonPutRsp) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) ProjectResourceDelete(ctx *context.WebContext, params *dto.CommonDeleteReq, rsp *dto.CommonDeleteRsp) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ctl *controller) getProjectResourceCommandApiAddr(ctx *context.WebContext) ([]string, error) {
|
|
projectId := getCtxURIProjectId(ctx)
|
|
//resouce := getCtxURIResource(ctx)
|
|
return ctl.svc.GetProjectInvokeApiAddr(projectId, nil)
|
|
}
|
|
|
|
func getCtxURIProjectIdAndResource(ctx *context.WebContext) (string, string) {
|
|
return getCtxURIProjectId(ctx), getCtxURIResource(ctx)
|
|
}
|
|
|
|
func getCtxURIResource(ctx *context.WebContext) string {
|
|
resource := ctx.GinCtx().Param("resource")
|
|
if resource == "" {
|
|
if strings.HasPrefix(ctx.GinCtx().Request.RequestURI, "/api/"+consts.ResourcesName_Project) {
|
|
return consts.ResourcesName_Project
|
|
}
|
|
}
|
|
return resource
|
|
}
|
|
|
|
func getCtxURIProjectId(ctx *context.WebContext) string {
|
|
projectId := ctx.GinCtx().Param("projectId")
|
|
return projectId
|
|
}
|
|
|
|
func (ctl *controller) apiRequest() {
|
|
|
|
}
|