2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
25 "github.com/gin-gonic/gin"
28 // getFolders returns all folders configuration
29 func (s *APIService) getFolders(c *gin.Context) {
30 c.JSON(http.StatusOK, s.mfolders.GetConfigArr())
33 // getFolder returns a specific folder configuration
34 func (s *APIService) getFolder(c *gin.Context) {
35 id, err := s.mfolders.ResolveID(c.Param("id"))
37 common.APIError(c, err.Error())
40 f := s.mfolders.Get(id)
42 common.APIError(c, "Invalid id")
46 c.JSON(http.StatusOK, (*f).GetConfig())
49 // addFolder adds a new folder to server config
50 func (s *APIService) addFolder(c *gin.Context) {
51 var cfgArg xsapiv1.FolderConfig
52 if c.BindJSON(&cfgArg) != nil {
53 common.APIError(c, "Invalid arguments")
57 s.Log.Debugln("Add folder config: ", cfgArg)
59 newFld, err := s.mfolders.Add(cfgArg)
61 common.APIError(c, err.Error())
65 c.JSON(http.StatusOK, newFld)
68 // syncFolder force synchronization of folder files
69 func (s *APIService) syncFolder(c *gin.Context) {
70 id, err := s.mfolders.ResolveID(c.Param("id"))
72 common.APIError(c, err.Error())
75 s.Log.Debugln("Sync folder id: ", id)
77 err = s.mfolders.ForceSync(id)
79 common.APIError(c, err.Error())
83 c.JSON(http.StatusOK, "")
86 // delFolder deletes folder from server config
87 func (s *APIService) delFolder(c *gin.Context) {
88 id, err := s.mfolders.ResolveID(c.Param("id"))
90 common.APIError(c, err.Error())
94 s.Log.Debugln("Delete folder id ", id)
96 delEntry, err := s.mfolders.Delete(id)
98 common.APIError(c, err.Error())
101 c.JSON(http.StatusOK, delEntry)
104 // updateFolder update some field of a folder
105 func (s *APIService) updateFolder(c *gin.Context) {
106 id, err := s.mfolders.ResolveID(c.Param("id"))
108 common.APIError(c, err.Error())
112 s.Log.Debugln("Update folder id ", id)
114 var cfgArg xsapiv1.FolderConfig
115 if c.BindJSON(&cfgArg) != nil {
116 common.APIError(c, "Invalid arguments")
120 upFld, err := s.mfolders.Update(id, cfgArg)
122 common.APIError(c, err.Error())
125 c.JSON(http.StatusOK, upFld)