-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.go
47 lines (40 loc) · 1.2 KB
/
news.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package handlers
import (
"database/sql"
"net/http"
"strconv"
"github.com/ezeoleaf/just-the-headlines-api/models"
"github.com/labstack/echo"
)
func GetNews(db *sql.DB) echo.HandlerFunc {
return func(c echo.Context) error {
userID, _ := getUserFromJWT(c)
return c.JSON(http.StatusOK, models.GetNews(db, userID))
}
}
func GetNewsBySection(db *sql.DB) echo.HandlerFunc {
return func(c echo.Context) error {
id, _ := strconv.ParseInt(c.Param("id"), 10, 64)
return c.JSON(http.StatusOK, models.GetNewsBySection(db, id))
}
}
func GetFilteredNews(db *sql.DB) echo.HandlerFunc {
return func(c echo.Context) error {
id, _ := strconv.ParseInt(c.Param("id"), 10, 64)
filter := c.Param("filter")
return c.JSON(http.StatusOK, models.GetFilteredNews(db, id, filter))
}
}
func GetMultipleNews(db *sql.DB) echo.HandlerFunc {
return func(c echo.Context) error {
sections := c.Param("sections")
return c.JSON(http.StatusOK, models.GetMultipleNews(db, sections, ``))
}
}
func GetFilteredMultipleNews(db *sql.DB) echo.HandlerFunc {
return func(c echo.Context) error {
sections := c.Param("sections")
filter := c.Param("filter")
return c.JSON(http.StatusOK, models.GetMultipleNews(db, sections, filter))
}
}