X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fagent%2Fapiv1-projects.go;h=281886fe1377ac020460150b59418db955c7c09c;hb=7c7d90a781082c6bd22d12a5e2451ca61a5198af;hp=c83596778cd7235765e1e9869229e3c6cb5a1984;hpb=a58e296c780f3f9f3a8f71a27cef0d202b13674b;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/agent/apiv1-projects.go b/lib/agent/apiv1-projects.go index c835967..281886f 100644 --- a/lib/agent/apiv1-projects.go +++ b/lib/agent/apiv1-projects.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - "github.com/iotbzh/xds-agent/lib/apiv1" + "github.com/iotbzh/xds-agent/lib/xaapiv1" common "github.com/iotbzh/xds-common/golib" ) @@ -31,7 +31,7 @@ func (s *APIService) getProject(c *gin.Context) { // addProject adds a new project to server config func (s *APIService) addProject(c *gin.Context) { - var cfgArg apiv1.ProjectConfig + var cfgArg xaapiv1.ProjectConfig if c.BindJSON(&cfgArg) != nil { common.APIError(c, "Invalid arguments") return @@ -39,7 +39,7 @@ func (s *APIService) addProject(c *gin.Context) { s.Log.Debugln("Add project config: ", cfgArg) - newFld, err := s.projects.Add(cfgArg) + newFld, err := s.projects.Add(cfgArg, s.sessions.GetID(c)) if err != nil { common.APIError(c, err.Error()) return @@ -77,10 +77,34 @@ func (s *APIService) delProject(c *gin.Context) { s.Log.Debugln("Delete project id ", id) - delEntry, err := s.projects.Delete(id) + delEntry, err := s.projects.Delete(id, s.sessions.GetID(c)) if err != nil { common.APIError(c, err.Error()) return } c.JSON(http.StatusOK, delEntry) } + +// updateProject Update some field of a specific project +func (s *APIService) updateProject(c *gin.Context) { + id, err := s.projects.ResolveID(c.Param("id")) + if err != nil { + common.APIError(c, err.Error()) + return + } + + var cfgArg xaapiv1.ProjectConfig + if c.BindJSON(&cfgArg) != nil { + common.APIError(c, "Invalid arguments") + return + } + + s.Log.Debugln("Update project id ", id) + + upPrj, err := s.projects.Update(id, cfgArg, s.sessions.GetID(c)) + if err != nil { + common.APIError(c, err.Error()) + return + } + c.JSON(http.StatusOK, upPrj) +}