✨ Able to get feed full content
This commit is contained in:
parent
0c28766336
commit
c812359f8b
41
pkg/internal/server/api/feed_items_api.go
Normal file
41
pkg/internal/server/api/feed_items_api.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.solsynth.dev/hypernet/reader/pkg/internal/database"
|
||||||
|
"git.solsynth.dev/hypernet/reader/pkg/internal/models"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func listFeedItem(c *fiber.Ctx) error {
|
||||||
|
take := c.QueryInt("take", 10)
|
||||||
|
offset := c.QueryInt("offset", 0)
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
if err := database.C.Model(&models.SubscriptionItem{}).Count(&count).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var items []models.SubscriptionItem
|
||||||
|
if err := database.C.
|
||||||
|
Order("published_at DESC").
|
||||||
|
Omit("Content").
|
||||||
|
Limit(take).Offset(offset).Find(&items).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(fiber.Map{
|
||||||
|
"count": count,
|
||||||
|
"data": items,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFeedItem(c *fiber.Ctx) error {
|
||||||
|
id, _ := c.ParamsInt("id", 0)
|
||||||
|
|
||||||
|
var item models.SubscriptionItem
|
||||||
|
if err := database.C.Where("id = ?", id).First(&item).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(item)
|
||||||
|
}
|
@ -17,6 +17,9 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
|||||||
|
|
||||||
subscription := api.Group("/subscriptions").Name("Subscriptions")
|
subscription := api.Group("/subscriptions").Name("Subscriptions")
|
||||||
{
|
{
|
||||||
|
subscription.Get("/", listFeedItem)
|
||||||
|
subscription.Get("/:id", getFeedItem)
|
||||||
|
|
||||||
feed := subscription.Group("/feed").Name("Feed")
|
feed := subscription.Group("/feed").Name("Feed")
|
||||||
{
|
{
|
||||||
feed.Get("/", listFeedSubscriptions)
|
feed.Get("/", listFeedSubscriptions)
|
||||||
|
@ -10,6 +10,7 @@ func GetTodayFeedRandomly(limit int) ([]models.SubscriptionItem, error) {
|
|||||||
if err := database.C.Limit(limit).
|
if err := database.C.Limit(limit).
|
||||||
Where("DATE(created_at) = CURRENT_DATE"). // Created in today
|
Where("DATE(created_at) = CURRENT_DATE"). // Created in today
|
||||||
Order("RANDOM()").
|
Order("RANDOM()").
|
||||||
|
Omit("Content").
|
||||||
Find(&articles).Error; err != nil {
|
Find(&articles).Error; err != nil {
|
||||||
return articles, err
|
return articles, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user