Skip to content

Commit

Permalink
feat (News): Include featured image
Browse files Browse the repository at this point in the history
  • Loading branch information
Owbird committed Mar 23, 2024
1 parent efd82f3 commit 96912bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
14 changes: 8 additions & 6 deletions internal/handlers/news_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}

Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions models/news.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tests/news_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
})

}
Expand Down

0 comments on commit 96912bc

Please sign in to comment.