From e9e208371afa76ee0d75210efac81f4716a74544 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Thu, 9 May 2024 19:08:43 -0700 Subject: [PATCH] handlers got updated for the new dtoconv package --- internal/dtoconv/dtoconv.go | 16 +++++++------- internal/handler/v1/articles.go | 14 ++++++------ internal/handler/v1/auth.go | 2 +- internal/handler/v1/discordwebhooks.go | 18 ++++++++-------- internal/handler/v1/handler.go | 2 +- internal/handler/v1/jwt.go | 2 +- internal/handler/v1/sources.go | 30 +++++++++++++------------- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/internal/dtoconv/dtoconv.go b/internal/dtoconv/dtoconv.go index 17faa4c..153f800 100644 --- a/internal/dtoconv/dtoconv.go +++ b/internal/dtoconv/dtoconv.go @@ -1,11 +1,11 @@ -package services +package dtoconv import ( "git.jamestombleson.com/jtom38/newsbot-api/domain" - internal "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" + "git.jamestombleson.com/jtom38/newsbot-api/internal/entity" ) -func ArticlesToDto(items []internal.ArticleEntity) []domain.ArticleDto { +func ArticlesToDto(items []entity.ArticleEntity) []domain.ArticleDto { var dtos []domain.ArticleDto for _, item := range items { dtos = append(dtos, ArticleToDto(item)) @@ -13,7 +13,7 @@ func ArticlesToDto(items []internal.ArticleEntity) []domain.ArticleDto { return dtos } -func ArticleToDto(item internal.ArticleEntity) domain.ArticleDto { +func ArticleToDto(item entity.ArticleEntity) domain.ArticleDto { return domain.ArticleDto{ ID: item.ID, SourceID: item.SourceID, @@ -29,7 +29,7 @@ func ArticleToDto(item internal.ArticleEntity) domain.ArticleDto { } } -func DiscordWebhooksToDto(items []internal.DiscordWebHookEntity) []domain.DiscordWebHookDto{ +func DiscordWebhooksToDto(items []entity.DiscordWebHookEntity) []domain.DiscordWebHookDto{ var dtos []domain.DiscordWebHookDto for _, item := range items { dtos = append(dtos, DiscordWebhookToDto(item)) @@ -37,7 +37,7 @@ func DiscordWebhooksToDto(items []internal.DiscordWebHookEntity) []domain.Discor return dtos } -func DiscordWebhookToDto(item internal.DiscordWebHookEntity) domain.DiscordWebHookDto { +func DiscordWebhookToDto(item entity.DiscordWebHookEntity) domain.DiscordWebHookDto { return domain.DiscordWebHookDto{ ID: item.ID, Server: item.Server, @@ -47,7 +47,7 @@ func DiscordWebhookToDto(item internal.DiscordWebHookEntity) domain.DiscordWebHo } } -func SourcesToDto(items []internal.SourceEntity) []domain.SourceDto { +func SourcesToDto(items []entity.SourceEntity) []domain.SourceDto { var dtos []domain.SourceDto for _, item := range items { dtos = append(dtos, SourceToDto(item)) @@ -55,7 +55,7 @@ func SourcesToDto(items []internal.SourceEntity) []domain.SourceDto { return dtos } -func SourceToDto(item internal.SourceEntity) domain.SourceDto { +func SourceToDto(item entity.SourceEntity) domain.SourceDto { return domain.SourceDto{ ID: item.ID, Source: item.Source, diff --git a/internal/handler/v1/articles.go b/internal/handler/v1/articles.go index b77f4d9..73b916a 100644 --- a/internal/handler/v1/articles.go +++ b/internal/handler/v1/articles.go @@ -4,8 +4,8 @@ import ( "net/http" "strconv" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" - "git.jamestombleson.com/jtom38/newsbot-api/internal/services" + "git.jamestombleson.com/jtom38/newsbot-api/domain" + "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "github.com/labstack/echo/v4" ) @@ -41,7 +41,7 @@ func (s *Handler) listArticles(c echo.Context) error { return s.WriteError(c, err, http.StatusInternalServerError) } - resp.Payload = services.ArticlesToDto(res) + resp.Payload = dtoconv.ArticlesToDto(res) return c.JSON(http.StatusOK, resp) } @@ -79,7 +79,7 @@ func (s *Handler) getArticle(c echo.Context) error { } var dtos []domain.ArticleDto - dtos = append(dtos, services.ArticleToDto(item)) + dtos = append(dtos, dtoconv.ArticleToDto(item)) p.Payload = dtos return c.JSON(http.StatusOK, p) @@ -123,8 +123,8 @@ func (s *Handler) getArticleDetails(c echo.Context) error { return s.WriteError(c, err, http.StatusInternalServerError) } - p.Payload.Article = services.ArticleToDto(article) - p.Payload.Source = services.SourceToDto(source) + p.Payload.Article = dtoconv.ArticleToDto(article) + p.Payload.Source = dtoconv.SourceToDto(source) return c.JSON(http.StatusOK, p) } @@ -168,6 +168,6 @@ func (s *Handler) ListArticlesBySourceId(c echo.Context) error { return c.JSON(http.StatusInternalServerError, err) } - p.Payload = services.ArticlesToDto(items) + p.Payload = dtoconv.ArticlesToDto(items) return c.JSON(http.StatusOK, p) } diff --git a/internal/handler/v1/auth.go b/internal/handler/v1/auth.go index f73f57e..61a9ad6 100644 --- a/internal/handler/v1/auth.go +++ b/internal/handler/v1/auth.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" + "git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "github.com/labstack/echo/v4" diff --git a/internal/handler/v1/discordwebhooks.go b/internal/handler/v1/discordwebhooks.go index 4328904..944616b 100644 --- a/internal/handler/v1/discordwebhooks.go +++ b/internal/handler/v1/discordwebhooks.go @@ -5,8 +5,8 @@ import ( "strconv" "strings" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" - "git.jamestombleson.com/jtom38/newsbot-api/internal/services" + "git.jamestombleson.com/jtom38/newsbot-api/domain" + "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "github.com/labstack/echo/v4" ) @@ -35,7 +35,7 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error { if err != nil { return c.JSON(http.StatusInternalServerError, err) } - p.Payload = services.DiscordWebhooksToDto(res) + p.Payload = dtoconv.DiscordWebhooksToDto(res) return c.JSON(http.StatusOK, p) } @@ -71,7 +71,7 @@ func (s *Handler) GetDiscordWebHooksById(c echo.Context) error { return s.WriteError(c, err, http.StatusInternalServerError) } var dtos []domain.DiscordWebHookDto - dtos = append(dtos, services.DiscordWebhookToDto(res)) + dtos = append(dtos, dtoconv.DiscordWebhookToDto(res)) p.Payload = dtos return c.JSON(http.StatusOK, p) } @@ -114,7 +114,7 @@ func (s *Handler) GetDiscordWebHooksByServerAndChannel(c echo.Context) error { return s.WriteError(c, err, http.StatusInternalServerError) } - p.Payload = services.DiscordWebhooksToDto(res) + p.Payload = dtoconv.DiscordWebhooksToDto(res) return c.JSON(http.StatusOK, p) } @@ -180,7 +180,7 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error { } var dtos []domain.DiscordWebHookDto - dtos = append(dtos, services.DiscordWebhookToDto(item)) + dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ BaseResponse: domain.BaseResponse{ @@ -239,7 +239,7 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error { } var dtos []domain.DiscordWebHookDto - dtos = append(dtos, services.DiscordWebhookToDto(item)) + dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ BaseResponse: domain.BaseResponse{ Message: ResponseMessageSuccess, @@ -290,7 +290,7 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error { } var dtos []domain.DiscordWebHookDto - dtos = append(dtos, services.DiscordWebhookToDto(item)) + dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ BaseResponse: domain.BaseResponse{ Message: ResponseMessageSuccess, @@ -344,7 +344,7 @@ func (s *Handler) deleteDiscordWebHook(c echo.Context) error { } var dtos []domain.DiscordWebHookDto - dtos = append(dtos, services.DiscordWebhookToDto(item)) + dtos = append(dtos, dtoconv.DiscordWebhookToDto(item)) return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ BaseResponse: domain.BaseResponse{ Message: ResponseMessageSuccess, diff --git a/internal/handler/v1/handler.go b/internal/handler/v1/handler.go index d3e76ad..671479e 100644 --- a/internal/handler/v1/handler.go +++ b/internal/handler/v1/handler.go @@ -13,7 +13,7 @@ import ( swagger "github.com/swaggo/echo-swagger" _ "git.jamestombleson.com/jtom38/newsbot-api/docs" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" + "git.jamestombleson.com/jtom38/newsbot-api/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/services" ) diff --git a/internal/handler/v1/jwt.go b/internal/handler/v1/jwt.go index 1a8d565..fba6795 100644 --- a/internal/handler/v1/jwt.go +++ b/internal/handler/v1/jwt.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" + "git.jamestombleson.com/jtom38/newsbot-api/domain" "github.com/golang-jwt/jwt/v5" "github.com/labstack/echo/v4" ) diff --git a/internal/handler/v1/sources.go b/internal/handler/v1/sources.go index 000cfde..ce66b22 100644 --- a/internal/handler/v1/sources.go +++ b/internal/handler/v1/sources.go @@ -6,8 +6,8 @@ import ( "strconv" "strings" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" - "git.jamestombleson.com/jtom38/newsbot-api/internal/services" + "git.jamestombleson.com/jtom38/newsbot-api/domain" + "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv" "github.com/labstack/echo/v4" ) @@ -43,7 +43,7 @@ func (s *Handler) listSources(c echo.Context) error { return s.WriteError(c, err, http.StatusInternalServerError) } - resp.Payload = services.SourcesToDto(items) + resp.Payload = dtoconv.SourcesToDto(items) return c.JSON(http.StatusOK, resp) } @@ -88,7 +88,7 @@ func (s *Handler) listSourcesBySource(c echo.Context) error { }) } - resp.Payload = services.SourcesToDto(items) + resp.Payload = dtoconv.SourcesToDto(items) return c.JSON(http.StatusOK, resp) } @@ -127,7 +127,7 @@ func (s *Handler) getSource(c echo.Context) error { } var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -169,7 +169,7 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error { } var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -224,7 +224,7 @@ func (s *Handler) newRedditSource(c echo.Context) error { } var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -264,7 +264,7 @@ func (s *Handler) newYoutubeSource(c echo.Context) error { item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name) if err == nil { var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -282,7 +282,7 @@ func (s *Handler) newYoutubeSource(c echo.Context) error { item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name) if err == nil { var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -323,7 +323,7 @@ func (s *Handler) newTwitchSource(c echo.Context) error { item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name) if err == nil { var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -341,7 +341,7 @@ func (s *Handler) newTwitchSource(c echo.Context) error { item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name) var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) @@ -399,7 +399,7 @@ func (s *Handler) newRssSource(c echo.Context) error { } var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -446,7 +446,7 @@ func (s *Handler) deleteSources(c echo.Context) error { } var items []domain.SourceDto - items = append(items, services.SourceToDto(item)) + items = append(items, dtoconv.SourceToDto(item)) return c.JSON(http.StatusOK, domain.SourcesResponse{ BaseResponse: domain.BaseResponse{ @@ -499,7 +499,7 @@ func (s *Handler) disableSource(c echo.Context) error { } var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) } @@ -547,7 +547,7 @@ func (s *Handler) enableSource(c echo.Context) error { } var dto []domain.SourceDto - dto = append(dto, services.SourceToDto(item)) + dto = append(dto, dtoconv.SourceToDto(item)) resp.Payload = dto return c.JSON(http.StatusOK, resp) }