klesh commented on code in PR #3679: URL: https://github.com/apache/incubator-devlake/pull/3679#discussion_r1023901820
########## api/project/project.go: ########## @@ -0,0 +1,243 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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. +*/ + +package project + +import ( + "net/http" + + "github.com/apache/incubator-devlake/api/shared" + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/models" + "github.com/apache/incubator-devlake/services" + "github.com/gin-gonic/gin" +) + +type ProjectCount struct { + Projects []*models.Project + Count int64 +} + +// @Summary Create and run a new project +// @Description Create and run a new project +// @Tags framework/projects +// @Accept application/json +// @Param project body models.Project true "json" +// @Success 200 {object} models.Project +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internal Error" +// @Router /projects/:projectName [get] +func GetProject(c *gin.Context) { + projectName := c.Param("projectName") + + project, err := services.GetProject(projectName) + if err != nil { + shared.ApiOutputError(c, errors.Default.Wrap(err, "error getting project")) + return + } + + shared.ApiOutputSuccess(c, project, http.StatusOK) +} + +// @Summary Get list of projects +// @Description GET /projects?page=1&pagesize=10 +// @Tags framework/projects +// @Param page query int true "query" +// @Param pagesize query int true "query" +// @Success 200 {object} ProjectCount +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internel Error" +// @Router /projects [get] +func GetProjects(c *gin.Context) { + var query services.ProjectQuery + err := c.ShouldBindQuery(&query) + if err != nil { + shared.ApiOutputError(c, errors.BadInput.Wrap(err, shared.BadRequestBody)) + return + } + projects, count, err := services.GetProjects(&query) + if err != nil { + shared.ApiOutputAbort(c, errors.Default.Wrap(err, "error getting projects")) + return + } + shared.ApiOutputSuccess(c, ProjectCount{ + Projects: projects, + Count: count, + }, http.StatusOK) +} + +// @Summary Create a new project +// @Description Create a new project +// @Tags framework/projects +// @Accept application/json +// @Param project body models.Project true "json" +// @Success 200 {object} models.Project +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internal Error" +// @Router /projects [post] +func PostProject(c *gin.Context) { + project := &models.Project{} + + err := c.ShouldBind(project) + if err != nil { + shared.ApiOutputError(c, errors.BadInput.Wrap(err, shared.BadRequestBody)) + return + } + + err = services.CreateProject(project) + if err != nil { + shared.ApiOutputError(c, errors.Default.Wrap(err, "error creating project")) + return + } + + shared.ApiOutputSuccess(c, project, http.StatusCreated) +} + +// @Summary Patch a project +// @Description Patch a project +// @Tags framework/projects +// @Accept application/json +// @Param project body models.Project true "json" +// @Success 200 {object} models.Project +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internal Error" +// @Router /projects/:projectName [patch] +func PatchProject(c *gin.Context) { + projectName := c.Param("projectName") + + var body map[string]interface{} + err := c.ShouldBind(&body) + if err != nil { + shared.ApiOutputError(c, errors.BadInput.Wrap(err, shared.BadRequestBody)) + return + } + + project, err := services.PatchProject(projectName, body) + if err != nil { + shared.ApiOutputError(c, errors.Default.Wrap(err, "error patch project")) + return + } + + shared.ApiOutputSuccess(c, project, http.StatusCreated) +} + +// @Cancel a project +// @Description Cancel a project +// @Tags framework/projects +// @Success 200 +// @Failure 400 {string} er2rcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internel Error" +// @Router /projects/:projectName [delete] +//func DeleteProject(c *gin.Context) { +//} + +// @Summary Get a ProjectMetrics +// @Description Get a ProjectMetrics +// @Tags framework/ProjectMetrics +// @Param page query int true "query" +// @Param pagesize query int true "query" +// @Success 200 {object} models.ProjectMetric +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internel Error" +// @Router /projects/:projectName/metrics/:pluginName [get] +func GetProjectMetric(c *gin.Context) { Review Comment: `GetProjectMetrics` ########## api/project/project.go: ########## @@ -0,0 +1,243 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +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. +*/ + +package project + +import ( + "net/http" + + "github.com/apache/incubator-devlake/api/shared" + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/models" + "github.com/apache/incubator-devlake/services" + "github.com/gin-gonic/gin" +) + +type ProjectCount struct { + Projects []*models.Project + Count int64 +} + +// @Summary Create and run a new project +// @Description Create and run a new project +// @Tags framework/projects +// @Accept application/json +// @Param project body models.Project true "json" +// @Success 200 {object} models.Project +// @Failure 400 {string} errcode.Error "Bad Request" +// @Failure 500 {string} errcode.Error "Internal Error" +// @Router /projects/:projectName [get] +func GetProject(c *gin.Context) { + projectName := c.Param("projectName") + + project, err := services.GetProject(projectName) + if err != nil { + shared.ApiOutputError(c, errors.Default.Wrap(err, "error getting project")) + return + } + + shared.ApiOutputSuccess(c, project, http.StatusOK) +} + +// @Summary Get list of projects +// @Description GET /projects?page=1&pagesize=10 +// @Tags framework/projects +// @Param page query int true "query" +// @Param pagesize query int true "query" +// @Success 200 {object} ProjectCount Review Comment: Not very descriptive, maybe `PaginatedProjects`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
