This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit d0edd10753d89e67d04404d48e0f7a959082e2c0
Author: abeizn <[email protected]>
AuthorDate: Wed Mar 27 18:14:09 2024 +0800

    feat: add project exist check (#7228)
    
    * feat: add project exist check
    
    * fix: swagger doc
---
 backend/core/models/project.go        |  4 ++++
 backend/server/api/project/project.go | 31 +++++++++++++++++++++++++++----
 backend/server/api/router.go          |  3 ++-
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/backend/core/models/project.go b/backend/core/models/project.go
index 4da6afc67..0c7723891 100644
--- a/backend/core/models/project.go
+++ b/backend/core/models/project.go
@@ -71,6 +71,10 @@ type ApiOutputProject struct {
        LastPipeline *Pipeline     `json:"lastPipeline,omitempty" 
mapstructure:"lastPipeline"`
 }
 
+type ApiProjectCheck struct {
+       Exist bool `json:"exist" mapstructure:"exist"`
+}
+
 type Store struct {
        StoreKey   string          `gorm:"primaryKey;type:varchar(255)"`
        StoreValue json.RawMessage `gorm:"type:json;serializer:json"`
diff --git a/backend/server/api/project/project.go 
b/backend/server/api/project/project.go
index 24cd57b2f..3305974ac 100644
--- a/backend/server/api/project/project.go
+++ b/backend/server/api/project/project.go
@@ -33,17 +33,17 @@ type PaginatedProjects struct {
        Count    int64                      `json:"count"`
 }
 
-// @Summary Create and run a new project
-// @Description Create and run a new project
+// @Summary Get a project
+// @Description Get a project
 // @Tags framework/projects
 // @Accept application/json
 // @Param projectName path string true "project name"
 // @Success 200  {object} models.ApiOutputProject
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 500  {string} errcode.Error "Internal Error"
-// @Router /projects/:projectName [get]
+// @Router /projects/{projectName} [get]
 func GetProject(c *gin.Context) {
-       projectName := c.Param("projectName")[1:]
+       projectName := c.Param("projectName")
 
        projectOutput, err := services.GetProject(projectName)
        if err != nil {
@@ -53,6 +53,29 @@ func GetProject(c *gin.Context) {
        shared.ApiOutputSuccess(c, projectOutput, http.StatusOK)
 }
 
+// @Summary Get project exist check
+// @Description Get project exist check
+// @Tags framework/projects
+// @Accept application/json
+// @Param projectName path string true "project name"
+// @Success 200  {object} models.ApiOutputProject
+// @Failure 400  {string} errcode.Error "Bad Request"
+// @Failure 500  {string} errcode.Error "Internal Error"
+// @Router /projects/{projectName}/check [get]
+func GetProjectCheck(c *gin.Context) {
+       projectName := c.Param("projectName")
+
+       projectOutputCheck := &models.ApiProjectCheck{}
+       _, err := services.GetProject(projectName)
+       if err != nil {
+               projectOutputCheck.Exist = false
+       } else {
+               projectOutputCheck.Exist = true
+       }
+
+       shared.ApiOutputSuccess(c, projectOutputCheck, http.StatusOK) // 
//shared.ApiOutputSuccess(c, projectOutputCheck, http.StatusOK)
+}
+
 // @Summary Get list of projects
 // @Description GET /projects?page=1&pageSize=10
 // @Tags framework/projects
diff --git a/backend/server/api/router.go b/backend/server/api/router.go
index 9577b2494..3698aef25 100644
--- a/backend/server/api/router.go
+++ b/backend/server/api/router.go
@@ -70,7 +70,8 @@ func RegisterRouter(r *gin.Engine, basicRes context.BasicRes) 
{
        r.GET("/plugins", plugininfo.GetPluginMetas)
 
        // project api
-       r.GET("/projects/*projectName", project.GetProject)
+       r.GET("/projects/:projectName", project.GetProject)
+       r.GET("/projects/:projectName/check", project.GetProjectCheck)
        r.PATCH("/projects/*projectName", project.PatchProject)
        r.DELETE("/projects/*projectName", project.DeleteProject)
        r.POST("/projects", project.PostProject)

Reply via email to