6 "github.com/gin-gonic/gin"
7 "github.com/iotbzh/xds-agent/lib/apiv1"
8 common "github.com/iotbzh/xds-common/golib"
11 // getProjects returns all projects configuration
12 func (s *APIService) getProjects(c *gin.Context) {
13 c.JSON(http.StatusOK, s.projects.GetProjectArr())
16 // getProject returns a specific project configuration
17 func (s *APIService) getProject(c *gin.Context) {
18 prj := s.projects.Get(c.Param("id"))
20 common.APIError(c, "Invalid id")
24 c.JSON(http.StatusOK, (*prj).GetProject())
27 // addProject adds a new project to server config
28 func (s *APIService) addProject(c *gin.Context) {
29 var cfgArg apiv1.ProjectConfig
30 if c.BindJSON(&cfgArg) != nil {
31 common.APIError(c, "Invalid arguments")
35 s.Log.Debugln("Add project config: ", cfgArg)
37 newFld, err := s.projects.Add(cfgArg)
39 common.APIError(c, err.Error())
43 c.JSON(http.StatusOK, newFld)
46 // syncProject force synchronization of project files
47 func (s *APIService) syncProject(c *gin.Context) {
50 s.Log.Debugln("Sync project id: ", id)
52 err := s.projects.ForceSync(id)
54 common.APIError(c, err.Error())
58 c.JSON(http.StatusOK, "")
61 // delProject deletes project from server config
62 func (s *APIService) delProject(c *gin.Context) {
65 s.Log.Debugln("Delete project id ", id)
67 delEntry, err := s.projects.Delete(id)
69 common.APIError(c, err.Error())
72 c.JSON(http.StatusOK, delEntry)