Ver código fonte

Update mappers

Dima 1 ano atrás
pai
commit
4688c1a42c
1 arquivos alterados com 4 adições e 24 exclusões
  1. 4 24
      internal/mapper/article.go

+ 4 - 24
internal/mapper/article.go

@@ -12,20 +12,15 @@ func ConvertArticleModelsToDTO(m []models.Article) ([]dto.ArticleDTO, error) {
 	res := make([]dto.ArticleDTO, 0, len(m))
 
 	for i := range m {
-		parsedDateTime, err := helpers.ParseDateTime(m[i].PublishTime)
-		if err != nil {
-			return nil, err
-		}
-
 		res = append(res, dto.ArticleDTO{
 			ID:              m[i].ID,
 			URL:             m[i].URL,
 			Title:           m[i].Title,
 			Text:            m[i].Text,
-			PublishTime:     helpers.FormatDateStr(parsedDateTime),
 			Image:           m[i].Image.String,
 			MetaKeywords:    m[i].MetaKeywords.String,
 			MetaDescription: m[i].MetaDescription.String,
+			PublishTime:     helpers.FormatDateStr(m[i].PublishTime),
 		})
 	}
 
@@ -33,20 +28,15 @@ func ConvertArticleModelsToDTO(m []models.Article) ([]dto.ArticleDTO, error) {
 }
 
 func ConvertArticleModelToDTO(m models.Article) (*dto.ArticleDTO, error) {
-	parsedDateTime, err := helpers.ParseDateTime(m.PublishTime)
-	if err != nil {
-		return nil, err
-	}
-
 	return &dto.ArticleDTO{
 		ID:              m.ID,
 		URL:             m.URL,
 		Title:           m.Title,
-		PublishTime:     helpers.FormatDateStr(parsedDateTime),
 		Text:            m.Text,
 		Image:           m.Image.String,
 		MetaKeywords:    m.MetaKeywords.String,
 		MetaDescription: m.MetaDescription.String,
+		PublishTime:     helpers.FormatDateStr(m.PublishTime),
 	}, nil
 }
 
@@ -54,18 +44,13 @@ func ConvertArticlePreviewModelsToDTO(m []models.ArticlePreview) ([]dto.ArticleP
 	res := make([]dto.ArticlePreviewDTO, 0, len(m))
 
 	for i := range m {
-		parsedDateTime, err := helpers.ParseDateTime(m[i].PublishTime)
-		if err != nil {
-			return nil, err
-		}
-
 		res = append(res, dto.ArticlePreviewDTO{
 			ID:          m[i].ID,
 			URL:         m[i].URL,
 			Title:       m[i].Title,
-			PublishTime: helpers.FormatDateStr(parsedDateTime),
 			PreviewText: m[i].PreviewText.String,
 			Image:       m[i].Image.String,
+			PublishTime: helpers.FormatDateStr(m[i].PublishTime),
 		})
 	}
 
@@ -73,11 +58,6 @@ func ConvertArticlePreviewModelsToDTO(m []models.ArticlePreview) ([]dto.ArticleP
 }
 
 func ConvertArticleModelToForm(a models.Article, tags []models.Tag) (*models.ArticleForm, error) {
-	parsedDateTime, err := helpers.ParseDateTime(a.PublishTime)
-	if err != nil {
-		return nil, err
-	}
-
 	tagMap := make(map[int]bool, len(tags))
 	for i := range tags {
 		tagMap[tags[i].ID] = true
@@ -93,7 +73,7 @@ func ConvertArticleModelToForm(a models.Article, tags []models.Tag) (*models.Art
 		PreviewText:     a.PreviewText.String,
 		MetaKeywords:    a.MetaKeywords.String,
 		MetaDescription: a.MetaDescription.String,
-		PublishTime:     helpers.FormatDateForm(parsedDateTime),
+		PublishTime:     a.PublishTime,
 		ActiveTags:      tagMap,
 	}, nil
 }