features/move-domain-for-portal #8

Merged
jtom38 merged 6 commits from features/move-domain-for-portal into main 2024-05-09 19:10:04 -07:00
7 changed files with 42 additions and 42 deletions
Showing only changes of commit e9e208371a - Show all commits

View File

@ -1,11 +1,11 @@
package services package dtoconv
import ( import (
"git.jamestombleson.com/jtom38/newsbot-api/domain" "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 var dtos []domain.ArticleDto
for _, item := range items { for _, item := range items {
dtos = append(dtos, ArticleToDto(item)) dtos = append(dtos, ArticleToDto(item))
@ -13,7 +13,7 @@ func ArticlesToDto(items []internal.ArticleEntity) []domain.ArticleDto {
return dtos return dtos
} }
func ArticleToDto(item internal.ArticleEntity) domain.ArticleDto { func ArticleToDto(item entity.ArticleEntity) domain.ArticleDto {
return domain.ArticleDto{ return domain.ArticleDto{
ID: item.ID, ID: item.ID,
SourceID: item.SourceID, 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 var dtos []domain.DiscordWebHookDto
for _, item := range items { for _, item := range items {
dtos = append(dtos, DiscordWebhookToDto(item)) dtos = append(dtos, DiscordWebhookToDto(item))
@ -37,7 +37,7 @@ func DiscordWebhooksToDto(items []internal.DiscordWebHookEntity) []domain.Discor
return dtos return dtos
} }
func DiscordWebhookToDto(item internal.DiscordWebHookEntity) domain.DiscordWebHookDto { func DiscordWebhookToDto(item entity.DiscordWebHookEntity) domain.DiscordWebHookDto {
return domain.DiscordWebHookDto{ return domain.DiscordWebHookDto{
ID: item.ID, ID: item.ID,
Server: item.Server, 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 var dtos []domain.SourceDto
for _, item := range items { for _, item := range items {
dtos = append(dtos, SourceToDto(item)) dtos = append(dtos, SourceToDto(item))
@ -55,7 +55,7 @@ func SourcesToDto(items []internal.SourceEntity) []domain.SourceDto {
return dtos return dtos
} }
func SourceToDto(item internal.SourceEntity) domain.SourceDto { func SourceToDto(item entity.SourceEntity) domain.SourceDto {
return domain.SourceDto{ return domain.SourceDto{
ID: item.ID, ID: item.ID,
Source: item.Source, Source: item.Source,

View File

@ -4,8 +4,8 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -41,7 +41,7 @@ func (s *Handler) listArticles(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
resp.Payload = services.ArticlesToDto(res) resp.Payload = dtoconv.ArticlesToDto(res)
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -79,7 +79,7 @@ func (s *Handler) getArticle(c echo.Context) error {
} }
var dtos []domain.ArticleDto var dtos []domain.ArticleDto
dtos = append(dtos, services.ArticleToDto(item)) dtos = append(dtos, dtoconv.ArticleToDto(item))
p.Payload = dtos p.Payload = dtos
return c.JSON(http.StatusOK, p) 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) return s.WriteError(c, err, http.StatusInternalServerError)
} }
p.Payload.Article = services.ArticleToDto(article) p.Payload.Article = dtoconv.ArticleToDto(article)
p.Payload.Source = services.SourceToDto(source) p.Payload.Source = dtoconv.SourceToDto(source)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -168,6 +168,6 @@ func (s *Handler) ListArticlesBySourceId(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, err) return c.JSON(http.StatusInternalServerError, err)
} }
p.Payload = services.ArticlesToDto(items) p.Payload = dtoconv.ArticlesToDto(items)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

View File

@ -5,8 +5,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -35,7 +35,7 @@ func (s *Handler) ListDiscordWebHooks(c echo.Context) error {
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, err) return c.JSON(http.StatusInternalServerError, err)
} }
p.Payload = services.DiscordWebhooksToDto(res) p.Payload = dtoconv.DiscordWebhooksToDto(res)
return c.JSON(http.StatusOK, p) 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) return s.WriteError(c, err, http.StatusInternalServerError)
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, services.DiscordWebhookToDto(res)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(res))
p.Payload = dtos p.Payload = dtos
return c.JSON(http.StatusOK, p) 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) return s.WriteError(c, err, http.StatusInternalServerError)
} }
p.Payload = services.DiscordWebhooksToDto(res) p.Payload = dtoconv.DiscordWebhooksToDto(res)
return c.JSON(http.StatusOK, p) return c.JSON(http.StatusOK, p)
} }
@ -180,7 +180,7 @@ func (s *Handler) NewDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, services.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -239,7 +239,7 @@ func (s *Handler) disableDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, services.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -290,7 +290,7 @@ func (s *Handler) enableDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, services.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,
@ -344,7 +344,7 @@ func (s *Handler) deleteDiscordWebHook(c echo.Context) error {
} }
var dtos []domain.DiscordWebHookDto var dtos []domain.DiscordWebHookDto
dtos = append(dtos, services.DiscordWebhookToDto(item)) dtos = append(dtos, dtoconv.DiscordWebhookToDto(item))
return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{ return c.JSON(http.StatusOK, domain.DiscordWebhookResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
Message: ResponseMessageSuccess, Message: ResponseMessageSuccess,

View File

@ -13,7 +13,7 @@ import (
swagger "github.com/swaggo/echo-swagger" swagger "github.com/swaggo/echo-swagger"
_ "git.jamestombleson.com/jtom38/newsbot-api/docs" _ "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" "git.jamestombleson.com/jtom38/newsbot-api/internal/services"
) )

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"time" "time"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )

View File

@ -6,8 +6,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/domain"
"git.jamestombleson.com/jtom38/newsbot-api/internal/services" "git.jamestombleson.com/jtom38/newsbot-api/internal/dtoconv"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -43,7 +43,7 @@ func (s *Handler) listSources(c echo.Context) error {
return s.WriteError(c, err, http.StatusInternalServerError) return s.WriteError(c, err, http.StatusInternalServerError)
} }
resp.Payload = services.SourcesToDto(items) resp.Payload = dtoconv.SourcesToDto(items)
return c.JSON(http.StatusOK, resp) 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) return c.JSON(http.StatusOK, resp)
} }
@ -127,7 +127,7 @@ func (s *Handler) getSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -169,7 +169,7 @@ func (s *Handler) GetSourceBySourceAndName(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -224,7 +224,7 @@ func (s *Handler) newRedditSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) 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) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) 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) item, err = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorYoutube, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) 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) item, err := s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name)
if err == nil { if err == nil {
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) 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) item, _ = s.repo.Sources.GetBySourceAndName(c.Request().Context(), domain.SourceCollectorTwitch, param.Name)
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
@ -399,7 +399,7 @@ func (s *Handler) newRssSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -446,7 +446,7 @@ func (s *Handler) deleteSources(c echo.Context) error {
} }
var items []domain.SourceDto var items []domain.SourceDto
items = append(items, services.SourceToDto(item)) items = append(items, dtoconv.SourceToDto(item))
return c.JSON(http.StatusOK, domain.SourcesResponse{ return c.JSON(http.StatusOK, domain.SourcesResponse{
BaseResponse: domain.BaseResponse{ BaseResponse: domain.BaseResponse{
@ -499,7 +499,7 @@ func (s *Handler) disableSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }
@ -547,7 +547,7 @@ func (s *Handler) enableSource(c echo.Context) error {
} }
var dto []domain.SourceDto var dto []domain.SourceDto
dto = append(dto, services.SourceToDto(item)) dto = append(dto, dtoconv.SourceToDto(item))
resp.Payload = dto resp.Payload = dto
return c.JSON(http.StatusOK, resp) return c.JSON(http.StatusOK, resp)
} }