6 "github.com/gin-gonic/gin"
7 common "github.com/iotbzh/xds-common/golib"
10 // getProjects returns all projects configuration
11 func (s *APIService) getProjects(c *gin.Context) {
12 c.JSON(http.StatusOK, s.projects.GetProjectArr())
15 // getProject returns a specific project configuration
16 func (s *APIService) getProject(c *gin.Context) {
17 prj := s.projects.Get(c.Param("id"))
19 common.APIError(c, "Invalid id")
23 c.JSON(http.StatusOK, (*prj).GetProject())
26 // addProject adds a new project to server config
27 func (s *APIService) addProject(c *gin.Context) {
28 var cfgArg ProjectConfig
29 if c.BindJSON(&cfgArg) != nil {
30 common.APIError(c, "Invalid arguments")
34 s.Log.Debugln("Add project config: ", cfgArg)
36 newFld, err := s.projects.Add(cfgArg)
38 common.APIError(c, err.Error())
42 c.JSON(http.StatusOK, newFld)
45 // syncProject force synchronization of project files
46 func (s *APIService) syncProject(c *gin.Context) {
49 s.Log.Debugln("Sync project id: ", id)
51 err := s.projects.ForceSync(id)
53 common.APIError(c, err.Error())
57 c.JSON(http.StatusOK, "")
60 // delProject deletes project from server config
61 func (s *APIService) delProject(c *gin.Context) {
64 s.Log.Debugln("Delete project id ", id)
66 delEntry, err := s.projects.Delete(id)
68 common.APIError(c, err.Error())
71 c.JSON(http.StatusOK, delEntry)