37 lines
744 B
Go
37 lines
744 B
Go
package handlers
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/tradarr/backend/internal/httputil"
|
|
)
|
|
|
|
func (h *Handler) ListArticles(c *gin.Context) {
|
|
symbol := c.Query("symbol")
|
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "50"))
|
|
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
|
|
if limit > 100 {
|
|
limit = 100
|
|
}
|
|
articles, err := h.repo.ListArticles(symbol, limit, offset)
|
|
if err != nil {
|
|
httputil.InternalError(c, err)
|
|
return
|
|
}
|
|
httputil.OK(c, articles)
|
|
}
|
|
|
|
func (h *Handler) GetArticle(c *gin.Context) {
|
|
article, err := h.repo.GetArticleByID(c.Param("id"))
|
|
if err != nil {
|
|
httputil.InternalError(c, err)
|
|
return
|
|
}
|
|
if article == nil {
|
|
httputil.NotFound(c)
|
|
return
|
|
}
|
|
httputil.OK(c, article)
|
|
}
|