49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v5"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/borgmatic"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database/model"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/web/api"
|
|
)
|
|
|
|
// @Summary Create a borgmatic infos
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200
|
|
// @Success 400
|
|
// @Router /api/v1/borgmatic/infos [post]
|
|
// @Param request body api.BorgmaticInfos true "Object"
|
|
func ApiBorgmaticInfos(c *echo.Context) error {
|
|
value := new(api.BorgmaticInfos)
|
|
|
|
if err := c.Bind(value); err != nil {
|
|
return c.JSON(http.StatusBadRequest, err.Error())
|
|
}
|
|
|
|
host := database.HostByName(value.Hostname)
|
|
|
|
if host == nil {
|
|
return c.JSON(http.StatusBadRequest, "Host not found")
|
|
}
|
|
|
|
var infos borgmatic.Infos
|
|
|
|
err := json.Unmarshal([]byte(value.Infos), &infos)
|
|
|
|
if err != nil {
|
|
return c.JSON(http.StatusBadRequest, err.Error())
|
|
}
|
|
|
|
info := new(model.Info)
|
|
info.HostID = host.ID
|
|
info.Data = value.Infos
|
|
|
|
database.GetDb().Save(info)
|
|
|
|
return c.JSON(200, "ok")
|
|
}
|