2024-04-23 07:15:38 -07:00
|
|
|
package v1
|
2022-06-19 22:02:44 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2024-04-23 22:18:07 -07:00
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
2022-06-19 22:02:44 -07:00
|
|
|
"github.com/google/uuid"
|
2024-04-23 22:18:07 -07:00
|
|
|
"github.com/labstack/echo/v4"
|
2022-06-19 22:02:44 -07:00
|
|
|
)
|
|
|
|
|
2024-04-23 22:18:07 -07:00
|
|
|
// GetSettings
|
|
|
|
// @Summary Returns a object based on the Key that was given.
|
|
|
|
// @Param key path string true "Settings Key value"
|
|
|
|
// @Produce application/json
|
|
|
|
// @Tags Settings
|
|
|
|
// @Router /settings/{key} [get]
|
|
|
|
func (s *Handler) getSettings(c echo.Context) error {
|
|
|
|
id := c.Param("ID")
|
2022-06-19 22:02:44 -07:00
|
|
|
|
|
|
|
uuid, err := uuid.Parse(id)
|
|
|
|
if err != nil {
|
2024-04-23 22:18:07 -07:00
|
|
|
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
|
|
|
Message: err.Error(),
|
|
|
|
})
|
2022-06-19 22:02:44 -07:00
|
|
|
}
|
|
|
|
|
2024-04-23 22:18:07 -07:00
|
|
|
res, err := s.Db.GetSourceByID(c.Request().Context(), uuid)
|
2022-06-19 22:02:44 -07:00
|
|
|
if err != nil {
|
2024-04-23 22:18:07 -07:00
|
|
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
2022-06-19 22:02:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bResult, err := json.Marshal(res)
|
|
|
|
if err != nil {
|
2024-04-23 22:18:07 -07:00
|
|
|
return c.JSON(http.StatusInternalServerError, err.Error())
|
2022-06-19 22:02:44 -07:00
|
|
|
}
|
|
|
|
|
2024-04-23 22:18:07 -07:00
|
|
|
return c.JSON(http.StatusOK, bResult)
|
2022-12-04 08:49:17 -08:00
|
|
|
}
|