newsbot-api/internal/handler/v1/settings.go

40 lines
914 B
Go
Raw Normal View History

2024-04-23 07:15:38 -07:00
package v1
import (
"encoding/json"
"net/http"
2024-04-23 22:18:07 -07:00
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
"github.com/google/uuid"
2024-04-23 22:18:07 -07:00
"github.com/labstack/echo/v4"
)
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")
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(),
})
}
2024-04-23 22:18:07 -07:00
res, err := s.Db.GetSourceByID(c.Request().Context(), uuid)
if err != nil {
2024-04-23 22:18:07 -07:00
return c.JSON(http.StatusInternalServerError, err.Error())
}
bResult, err := json.Marshal(res)
if err != nil {
2024-04-23 22:18:07 -07:00
return c.JSON(http.StatusInternalServerError, err.Error())
}
2024-04-23 22:18:07 -07:00
return c.JSON(http.StatusOK, bResult)
}