|
- /* ******************************************************************************
- * 2019 - present Contributed by Apulis Technology (Shenzhen) Co. LTD
- *
- * This program and the accompanying materials are made available under the
- * terms of the MIT License, which is available at
- * https://www.opensource.org/licenses/MIT
- *
- * See the NOTICE file distributed with this work for additional
- * information regarding copyright ownership.
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- * SPDX-License-Identifier: MIT
- ******************************************************************************/
- package controllers
-
- import (
- "fmt"
-
- "github.com/apulis/app/ai-arts-backend/internal/constant"
- "github.com/apulis/app/ai-arts-backend/internal/dto"
- "github.com/apulis/app/ai-arts-backend/internal/middlewares"
- "github.com/apulis/app/ai-arts-backend/internal/services"
- "github.com/apulis/app/ai-arts-backend/pkg/exports"
- "github.com/apulis/sdk/go-utils/logging"
- "github.com/gin-gonic/gin"
- )
-
- type Project struct {
- UserInfo
- HeaderInfo
- }
-
- func (p *Project) Create(c *gin.Context) {
- var projectDto dto.CreateProject
-
- p.InitUserInfo(c)
- p.InitHeader(c)
-
- if bindAndValidate(c, &projectDto) {
- logging.Info().Msgf("create project %v", projectDto)
- switch projectDto.Type {
- case exports.AIStudio_labs_expert:
- p.HandlerCreateCodeLab(projectDto, c)
- case exports.AIStudio_labs_preset:
- p.HandlerCreatePresetLab(projectDto, c)
- default:
- fail(c, fmt.Errorf("type %s is error", projectDto.Type))
- }
- }
- }
-
- func (p *Project) Delete(c *gin.Context) {
- var projectDto dto.DeleteProject
- if bindAndValidate(c, &projectDto) {
- logging.Info().Msgf("delete project %v", projectDto)
- pService := services.ProjectService{}
- err := pService.Delete(&projectDto)
-
- if err != nil {
- fail(c, err)
- } else {
- ok(c)
- }
- }
- }
-
- func (p *Project) List(c *gin.Context) {
- var projectDto dto.ListProject
- if bindAndValidate(c, &projectDto) {
- logging.Info().Msgf("list project %v", projectDto)
- if len(projectDto.GroupId) == 0 {
- groupId, _ := middlewares.GroupId(c)
- projectDto.GroupId = append(projectDto.GroupId, groupId)
- }
- logging.Info().Msgf("list project %v", projectDto)
- pService := services.ProjectService{}
- project, total, err := pService.List(&projectDto)
-
- resp := &dto.BaseListResp{}
- resp.Items = project
- resp.Total = total
-
- if err != nil {
- fail(c, err)
- } else {
- respWithData(c, resp)
- }
- }
- }
-
- func (p *Project) Get(c *gin.Context) {
- var getProjectReqDto dto.GetProjectReq
- if bindAndValidate(c, &getProjectReqDto) {
- logging.Info().Msgf("get project %v", getProjectReqDto)
- pService := services.ProjectService{}
- userName := middlewares.UserName(c)
- uid, _ := middlewares.UserId(c)
- project, err := pService.Get(&getProjectReqDto)
- if err != nil {
- fail(c, err)
- return
- }
- //获取run lab列表
- getRunListReq := &dto.GetAiLabRunListReq{}
- getRunListReq.LabId = project.LabId
- getRunListReq.JobType = constant.AILAB_RUN_CODE_DEVELOP
- getRunListReq.Creator = userName
- getRunListReq.UserId = uid
- aiLabService := &services.AiLabService{}
- resp, commResp, err := aiLabService.GetRunList(getRunListReq, nil)
- if err != nil {
- fail(c, err)
- return
- } else if commResp.Code != 0 {
- failWithData(c, commResp.Code, commResp.Msg, commResp.Data)
- return
- } else if len(resp.Items) > 0 && resp.Items[0].Creator == userName {
- project.LabStatus = resp.Items[0].Status
- project.RegisterStatus = resp.Items[0].RegisterStatus
- project.ScratchStatus = resp.Items[0].ScratchStatus
- project.ViewStatus = resp.Items[0].ViewStatus
- }
- respWithData(c, project)
- }
- }
|