diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-11-06 10:19:06 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-11-06 14:49:43 +0100 |
commit | a58e296c780f3f9f3a8f71a27cef0d202b13674b (patch) | |
tree | 72dcd72ca9a8a7c30c7e44338c708a86ab18a8e7 /lib/agent/apiv1-projects.go | |
parent | be13167b869161b6e19dc3e94835245cdc7911e5 (diff) |
Support short project id name if not ambiguous.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/agent/apiv1-projects.go')
-rw-r--r-- | lib/agent/apiv1-projects.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/agent/apiv1-projects.go b/lib/agent/apiv1-projects.go index 89218ab..c835967 100644 --- a/lib/agent/apiv1-projects.go +++ b/lib/agent/apiv1-projects.go @@ -15,7 +15,12 @@ func (s *APIService) getProjects(c *gin.Context) { // getProject returns a specific project configuration func (s *APIService) getProject(c *gin.Context) { - prj := s.projects.Get(c.Param("id")) + id, err := s.projects.ResolveID(c.Param("id")) + if err != nil { + common.APIError(c, err.Error()) + return + } + prj := s.projects.Get(id) if prj == nil { common.APIError(c, "Invalid id") return @@ -45,22 +50,30 @@ func (s *APIService) addProject(c *gin.Context) { // syncProject force synchronization of project files func (s *APIService) syncProject(c *gin.Context) { - id := c.Param("id") + id, err := s.projects.ResolveID(c.Param("id")) + if err != nil { + common.APIError(c, err.Error()) + return + } s.Log.Debugln("Sync project id: ", id) - err := s.projects.ForceSync(id) + err = s.projects.ForceSync(id) if err != nil { common.APIError(c, err.Error()) return } - c.JSON(http.StatusOK, "") + c.JSON(http.StatusOK, nil) } // delProject deletes project from server config func (s *APIService) delProject(c *gin.Context) { - id := c.Param("id") + id, err := s.projects.ResolveID(c.Param("id")) + if err != nil { + common.APIError(c, err.Error()) + return + } s.Log.Debugln("Delete project id ", id) |