Пример #1
0
/*
Index show list
*/
func (n *NewsController) Index(c *gin.Context) {
	if page, err := strconv.Atoi(c.DefaultQuery("page", "0")); err != nil || page < 0 {
		c.JSON(http.StatusBadRequest, gin.H{"error": "invalid page number"})

	} else if news, err := models.GetNewsItems(n.DB, nil, nil, nil, nil, nil, nil, page); err != nil {
		c.JSON(http.StatusNoContent, gin.H{"error": err.Error()})

	} else {
		n.Log("NewsItems", "Index")
		c.JSON(http.StatusOK, gin.H{"news": news})
	}
}
Пример #2
0
/*
Search a new
*/
func (n *NewsController) Search(c *gin.Context) {
	tags := c.Request.URL.Query()["tags"]
	providers := c.Request.URL.Query()["providers"]
	categories := c.Request.URL.Query()["categories"]
	locations := c.Request.URL.Query()["locations"]
	people := c.Request.URL.Query()["people"]
	companies := c.Request.URL.Query()["companies"]

	if page, err := strconv.Atoi(c.DefaultQuery("page", "0")); err != nil || page < 0 {
		c.JSON(http.StatusBadRequest, gin.H{"error": "invalid page number"})

	} else if news, err := models.GetNewsItems(n.DB, tags, providers, categories, people, locations, companies, page); err != nil {
		c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})

	} else {
		n.Log("NewsItems", "Search")
		c.JSON(http.StatusOK, gin.H{"news": news})
	}
}