features/repo-updates #4
@ -60,21 +60,21 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error {
|
|||||||
|
|
||||||
_id := c.Param("ID")
|
_id := c.Param("ID")
|
||||||
if _id == "" {
|
if _id == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: ErrIdValueMissing,
|
Message: ErrIdValueMissing,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, err := uuid.Parse(_id)
|
uuid, err := uuid.Parse(_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: ErrUnableToParseId,
|
Message: ErrUnableToParseId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.dto.GetDiscordWebhook(c.Request().Context(), uuid)
|
res, err := s.dto.GetDiscordWebhook(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: ErrNoRecordFound,
|
Message: ErrNoRecordFound,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -100,21 +100,21 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error {
|
|||||||
|
|
||||||
_server := c.QueryParam("server")
|
_server := c.QueryParam("server")
|
||||||
if _server == "" {
|
if _server == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: ErrIdValueMissing,
|
Message: ErrIdValueMissing,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
_channel := c.QueryParam("channel")
|
_channel := c.QueryParam("channel")
|
||||||
if _channel == "" {
|
if _channel == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: fmt.Sprintf("%s channel", ErrParameterMissing),
|
Message: fmt.Sprintf("%s channel", ErrParameterMissing),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.dto.GetDiscordWebHookByServerAndChannel(c.Request().Context(), _server, _channel)
|
res, err := s.dto.GetDiscordWebHookByServerAndChannel(c.Request().Context(), _server, _channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -136,22 +136,22 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
|
|||||||
_channel := c.QueryParam("channel")
|
_channel := c.QueryParam("channel")
|
||||||
|
|
||||||
if _url == "" {
|
if _url == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "url is missing a value",
|
Message: "url is missing a value",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !strings.Contains(_url, "discord.com/api/webhooks") {
|
if !strings.Contains(_url, "discord.com/api/webhooks") {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "invalid url",
|
Message: "invalid url",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if _server == "" {
|
if _server == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "server is missing",
|
Message: "server is missing",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if _channel == "" {
|
if _channel == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "channel is missing",
|
Message: "channel is missing",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
|||||||
id := c.Param("ID")
|
id := c.Param("ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -189,7 +189,7 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
|
|||||||
|
|
||||||
err = s.Db.DisableDiscordWebHook(c.Request().Context(), uuid)
|
err = s.Db.DisableDiscordWebHook(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
|
|||||||
id := c.Param("ID")
|
id := c.Param("ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func (s *Handler) ListDiscordWebhookQueue(c echo.Context) error {
|
|||||||
// Get the raw resp from sql
|
// Get the raw resp from sql
|
||||||
res, err := s.dto.ListDiscordWebhookQueueDetails(c.Request().Context(), 50)
|
res, err := s.dto.ListDiscordWebhookQueueDetails(c.Request().Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func (s *Handler) getSettings(c echo.Context) error {
|
|||||||
|
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,10 @@ import (
|
|||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain/models"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain/models"
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Handler) GetSourcesRouter() http.Handler {
|
|
||||||
r := chi.NewRouter()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListSources struct {
|
type ListSources struct {
|
||||||
ApiStatusModel
|
ApiStatusModel
|
||||||
Payload []models.SourceDto `json:"payload"`
|
Payload []models.SourceDto `json:"payload"`
|
||||||
@ -39,7 +30,7 @@ type GetSource struct {
|
|||||||
// @Tags Source
|
// @Tags Source
|
||||||
// @Router /sources [get]
|
// @Router /sources [get]
|
||||||
// @Success 200 {object} ListSources "ok"
|
// @Success 200 {object} ListSources "ok"
|
||||||
// @Failure 400 {object} ApiError "Unable to reach SQL or Data problems"
|
// @Failure 400 {object} domain.BaseResponse "Unable to reach SQL or Data problems"
|
||||||
func (s *Handler) listSources(c echo.Context) error {
|
func (s *Handler) listSources(c echo.Context) error {
|
||||||
//TODO Add top?
|
//TODO Add top?
|
||||||
/*
|
/*
|
||||||
@ -61,9 +52,7 @@ func (s *Handler) listSources(c echo.Context) error {
|
|||||||
// Default way of showing all sources
|
// Default way of showing all sources
|
||||||
items, err := s.dto.ListSources(c.Request().Context(), 50)
|
items, err := s.dto.ListSources(c.Request().Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
s.WriteError(c, err, http.StatusInternalServerError)
|
||||||
Message: err.Error(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = items
|
p.Payload = items
|
||||||
@ -102,7 +91,7 @@ func (s *Handler) listSourcesBySource(c echo.Context) error {
|
|||||||
// Shows the list by Sources.source
|
// Shows the list by Sources.source
|
||||||
res, err := s.dto.ListSourcesBySource(c.Request().Context(), source)
|
res, err := s.dto.ListSourcesBySource(c.Request().Context(), source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -132,14 +121,14 @@ func (s *Handler) getSources(c echo.Context) error {
|
|||||||
id := c.Param("ID")
|
id := c.Param("ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: ErrUnableToParseId,
|
Message: ErrUnableToParseId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.dto.GetSourceById(c.Request().Context(), uuid)
|
res, err := s.dto.GetSourceById(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: ErrNoRecordFound,
|
Message: ErrNoRecordFound,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -170,7 +159,7 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
|
|||||||
var param domain.GetSourceBySourceAndNameParamRequest
|
var param domain.GetSourceBySourceAndNameParamRequest
|
||||||
err := c.Bind(¶m)
|
err := c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -206,7 +195,7 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
|||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err := c.Bind(¶m)
|
err := c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -216,12 +205,12 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
|||||||
//_tags := query["tags"][0]
|
//_tags := query["tags"][0]
|
||||||
|
|
||||||
if param.Url == "" {
|
if param.Url == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "Url is missing a value",
|
Message: "Url is missing a value",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !strings.Contains(param.Url, "reddit.com") {
|
if !strings.Contains(param.Url, "reddit.com") {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "Invalid URL given",
|
Message: "Invalid URL given",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -248,7 +237,7 @@ func (s *Handler) newRedditSource(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
err = s.Db.CreateSource(c.Request().Context(), params)
|
err = s.Db.CreateSource(c.Request().Context(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -272,7 +261,7 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
|
|||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err := c.Bind(¶m)
|
err := c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -283,12 +272,12 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
|
|||||||
////_tags := query["tags"][0]
|
////_tags := query["tags"][0]
|
||||||
|
|
||||||
if param.Url == "" {
|
if param.Url == "" {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "url is missing a value",
|
Message: "url is missing a value",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !strings.Contains(param.Url, "youtube.com") {
|
if !strings.Contains(param.Url, "youtube.com") {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: "Invalid URL",
|
Message: "Invalid URL",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -318,7 +307,7 @@ func (s *Handler) newYoutubeSource(c echo.Context) error {
|
|||||||
|
|
||||||
bJson, err := json.Marshal(¶ms)
|
bJson, err := json.Marshal(¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -335,7 +324,7 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
|
|||||||
var param domain.NewSourceParamRequest
|
var param domain.NewSourceParamRequest
|
||||||
err := c.Bind(¶m)
|
err := c.Bind(¶m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -358,14 +347,14 @@ func (s *Handler) newTwitchSource(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
err = s.Db.CreateSource(c.Request().Context(), params)
|
err = s.Db.CreateSource(c.Request().Context(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
bJson, err := json.Marshal(¶ms)
|
bJson, err := json.Marshal(¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -382,7 +371,7 @@ func (s *Handler) deleteSources(c echo.Context) error {
|
|||||||
id := c.Param("ID")
|
id := c.Param("ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -390,7 +379,7 @@ func (s *Handler) deleteSources(c echo.Context) error {
|
|||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -398,7 +387,7 @@ func (s *Handler) deleteSources(c echo.Context) error {
|
|||||||
// Delete the record
|
// Delete the record
|
||||||
err = s.Db.DeleteSource(c.Request().Context(), uuid)
|
err = s.Db.DeleteSource(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -410,7 +399,7 @@ func (s *Handler) deleteSources(c echo.Context) error {
|
|||||||
|
|
||||||
b, err := json.Marshal(p)
|
b, err := json.Marshal(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -427,7 +416,7 @@ func (s *Handler) disableSource(c echo.Context) error {
|
|||||||
id := c.Param("ID")
|
id := c.Param("ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, domain.ErrorResponse{
|
return c.JSON(http.StatusBadRequest, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -435,14 +424,14 @@ func (s *Handler) disableSource(c echo.Context) error {
|
|||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Db.DisableSource(context.Background(), uuid)
|
err = s.Db.DisableSource(context.Background(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -454,7 +443,7 @@ func (s *Handler) disableSource(c echo.Context) error {
|
|||||||
|
|
||||||
b, err := json.Marshal(p)
|
b, err := json.Marshal(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -477,14 +466,14 @@ func (s *Handler) enableSource(c echo.Context) error {
|
|||||||
// Check to make sure we can find the record
|
// Check to make sure we can find the record
|
||||||
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
_, err = s.Db.GetSourceByID(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Db.EnableSource(c.Request().Context(), uuid)
|
err = s.Db.EnableSource(c.Request().Context(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -496,7 +485,7 @@ func (s *Handler) enableSource(c echo.Context) error {
|
|||||||
|
|
||||||
b, err := json.Marshal(p)
|
b, err := json.Marshal(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, domain.ErrorResponse{
|
return c.JSON(http.StatusInternalServerError, domain.BaseResponse{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/database"
|
||||||
@ -44,7 +45,7 @@ func (s *Handler) ListSubscriptions(c echo.Context) error {
|
|||||||
|
|
||||||
res, err := s.dto.ListSubscriptions(c.Request().Context(), 50)
|
res, err := s.dto.ListSubscriptions(c.Request().Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusBadRequest)
|
return s.WriteError(c, err, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
payload.Payload = res
|
payload.Payload = res
|
||||||
@ -67,7 +68,7 @@ func (s *Handler) ListSubscriptionDetails(c echo.Context) error {
|
|||||||
|
|
||||||
res, err := s.dto.ListSubscriptionDetails(c.Request().Context(), 50)
|
res, err := s.dto.ListSubscriptionDetails(c.Request().Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusInternalServerError)
|
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
payload.Payload = res
|
payload.Payload = res
|
||||||
@ -93,18 +94,18 @@ func (s *Handler) GetSubscriptionsByDiscordId(c echo.Context) error {
|
|||||||
|
|
||||||
id := c.QueryParam("id")
|
id := c.QueryParam("id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return s.WriteError(c, ErrIdValueMissing, http.StatusBadRequest)
|
return s.WriteError(c, errors.New(ErrIdValueMissing), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, ErrValueNotUuid, http.StatusBadRequest)
|
return s.WriteError(c, errors.New(ErrValueNotUuid), http.StatusBadRequest)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.dto.ListSubscriptionsByDiscordWebhookId(context.Background(), uuid)
|
res, err := s.dto.ListSubscriptionsByDiscordWebhookId(context.Background(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusNoContent)
|
return s.WriteError(c, err, http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
@ -128,17 +129,17 @@ func (s *Handler) GetSubscriptionsBySourceId(c echo.Context) error {
|
|||||||
|
|
||||||
_id := c.QueryParam("id")
|
_id := c.QueryParam("id")
|
||||||
if _id == "" {
|
if _id == "" {
|
||||||
return s.WriteError(c, ErrIdValueMissing, http.StatusBadRequest)
|
return s.WriteError(c, errors.New(ErrIdValueMissing), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, err := uuid.Parse(_id)
|
uuid, err := uuid.Parse(_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusBadRequest)
|
return s.WriteError(c, err, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.dto.ListSubscriptionsBySourceId(context.Background(), uuid)
|
res, err := s.dto.ListSubscriptionsBySourceId(context.Background(), uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusNoContent)
|
return s.WriteError(c, err, http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
@ -158,20 +159,20 @@ func (s *Handler) newDiscordWebHookSubscription(c echo.Context) error {
|
|||||||
|
|
||||||
// Check to make we didn't get a null
|
// Check to make we didn't get a null
|
||||||
if discordWebHookId == "" {
|
if discordWebHookId == "" {
|
||||||
return s.WriteError(c, "invalid discordWebHooksId given", http.StatusBadRequest)
|
return s.WriteError(c, errors.New("invalid discordWebHooksId given"), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
if sourceId == "" {
|
if sourceId == "" {
|
||||||
return s.WriteError(c, "invalid sourceID given", http.StatusBadRequest)
|
return s.WriteError(c, errors.New("invalid sourceID given"), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate they are UUID values
|
// Validate they are UUID values
|
||||||
uHook, err := uuid.Parse(discordWebHookId)
|
uHook, err := uuid.Parse(discordWebHookId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusBadRequest)
|
return s.WriteError(c, err, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
uSource, err := uuid.Parse(sourceId)
|
uSource, err := uuid.Parse(sourceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusBadRequest)
|
return s.WriteError(c, err, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the sub already exists
|
// Check if the sub already exists
|
||||||
@ -180,7 +181,7 @@ func (s *Handler) newDiscordWebHookSubscription(c echo.Context) error {
|
|||||||
Sourceid: uSource,
|
Sourceid: uSource,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return s.WriteError(c, "a subscription already exists between these two entities", http.StatusBadRequest)
|
return s.WriteError(c, errors.New("a subscription already exists between these two entities"), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does not exist, so make it.
|
// Does not exist, so make it.
|
||||||
@ -191,12 +192,12 @@ func (s *Handler) newDiscordWebHookSubscription(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
err = s.Db.CreateSubscription(context.Background(), params)
|
err = s.Db.CreateSubscription(context.Background(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusInternalServerError)
|
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
bJson, err := json.Marshal(¶ms)
|
bJson, err := json.Marshal(¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusInternalServerError)
|
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, bJson)
|
return c.JSON(http.StatusOK, bJson)
|
||||||
@ -212,17 +213,17 @@ func (s *Handler) DeleteDiscordWebHookSubscription(c echo.Context) error {
|
|||||||
|
|
||||||
id := c.QueryParam("id")
|
id := c.QueryParam("id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return s.WriteError(c, ErrMissingSubscriptionID, http.StatusBadRequest)
|
return s.WriteError(c, errors.New(ErrMissingSubscriptionID), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
uid, err := uuid.Parse(id)
|
uid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusBadRequest)
|
return s.WriteError(c, err, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Db.DeleteSubscription(context.Background(), uid)
|
err = s.Db.DeleteSubscription(context.Background(), uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return s.WriteError(c, err.Error(), http.StatusInternalServerError)
|
return s.WriteError(c, err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, nil)
|
return c.JSON(http.StatusOK, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user