diff --git a/internal/handlers/news_handler.go b/internal/handlers/news_handler.go index ea61d16..559819b 100644 --- a/internal/handlers/news_handler.go +++ b/internal/handlers/news_handler.go @@ -49,12 +49,15 @@ func (h *Handlers) GetNewsHandler(c *gin.Context) { categoryTag := newsTag.Find("span", "class", "post-cat") + featuredImage := newsTag.Find("img").Attrs()["src"] + appNews = append(appNews, models.News{ - Title: titleTag.Text(), - Description: descriptionTag.Text(), - Date: strings.TrimSpace(date), - Category: strings.TrimSpace(categoryTag.Text()), - Slug: strings.TrimSpace(slug), + Title: titleTag.Text(), + Description: descriptionTag.Text(), + Date: strings.TrimSpace(date), + Category: strings.TrimSpace(categoryTag.Text()), + Slug: strings.TrimSpace(slug), + FeaturedImage: fmt.Sprintf("%s%s", config.MainUrl , featuredImage), }) } @@ -65,7 +68,6 @@ func (h *Handlers) GetNewsHandler(c *gin.Context) { } - // @Summary Get news post details // @Description Get the post details of the news based on the slug // @Tags News diff --git a/models/news.go b/models/news.go index 91e330c..0afdb01 100644 --- a/models/news.go +++ b/models/news.go @@ -1,11 +1,12 @@ package models type News struct { - Title string `json:"title"` - Description string `json:"description"` - Date string `json:"date"` - Category string `json:"category"` - Slug string `json:"slug"` + Title string `json:"title"` + Description string `json:"description"` + Date string `json:"date"` + Category string `json:"category"` + Slug string `json:"slug"` + FeaturedImage string `json:"featured_image"` } type NewsResponse struct { diff --git a/tests/news_handler_test.go b/tests/news_handler_test.go index 7e3c76d..643e6d7 100644 --- a/tests/news_handler_test.go +++ b/tests/news_handler_test.go @@ -52,6 +52,7 @@ func TestNewsHandler(t *testing.T) { assert.NotEqual(t, news.Title, "") assert.NotEqual(t, news.Description, "") assert.NotEqual(t, news.Slug, "") + assert.NotEqual(t, news.FeaturedImage, "") }) }