Compare commits
No commits in common. "01b0cbce3ec529070b62fe5ae2d4905e2ebe9ad9" and "97aa2d626e109c5cfb5a2e082b8ac19739d3c8ab" have entirely different histories.
01b0cbce3e
...
97aa2d626e
@ -9,23 +9,15 @@ import (
|
|||||||
func listNewsArticles(c *fiber.Ctx) error {
|
func listNewsArticles(c *fiber.Ctx) error {
|
||||||
take := c.QueryInt("take", 0)
|
take := c.QueryInt("take", 0)
|
||||||
offset := c.QueryInt("offset", 0)
|
offset := c.QueryInt("offset", 0)
|
||||||
source := c.Query("source")
|
|
||||||
|
|
||||||
tx := database.C
|
|
||||||
|
|
||||||
if len(source) > 0 {
|
|
||||||
tx = tx.Where("source = ?", source)
|
|
||||||
}
|
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
countTx := tx
|
if err := database.C.Model(&models.NewsArticle{}).Count(&count).Error; err != nil {
|
||||||
if err := countTx.Model(&models.NewsArticle{}).Count(&count).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var articles []models.NewsArticle
|
var articles []models.NewsArticle
|
||||||
if err := tx.Limit(take).Offset(offset).
|
if err := database.C.Limit(take).Offset(offset).
|
||||||
Omit("Content").Order("COALESCE(published_at, created_at) DESC").
|
Omit("Content").Order("created_at DESC").
|
||||||
Find(&articles).Error; err != nil {
|
Find(&articles).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hypernet/reader/pkg/internal/models"
|
|
||||||
"git.solsynth.dev/hypernet/reader/pkg/internal/services"
|
"git.solsynth.dev/hypernet/reader/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getNewsSources(c *fiber.Ctx) error {
|
func getNewsSources(c *fiber.Ctx) error {
|
||||||
return c.JSON(lo.Filter(services.NewsSources, func(item models.NewsSource, index int) bool {
|
return c.JSON(services.NewsSources)
|
||||||
return item.Enabled
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user