fix: statistic upstream url change & save article to private
This commit is contained in:
@@ -35,7 +35,7 @@ func GetHttpClient(key string) (*http.Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CHINA_NCOV_STATISTIC_URL = "https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5"
|
CHINA_NCOV_STATISTIC_URL = "https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail,diseaseh5Shelf"
|
||||||
ENV_NOLOG = "nolog"
|
ENV_NOLOG = "nolog"
|
||||||
TOKEN_EXPIRE_DAYS = 15
|
TOKEN_EXPIRE_DAYS = 15
|
||||||
FACKER_HOST = "http://myhost.fallen-angle.com:5000/"
|
FACKER_HOST = "http://myhost.fallen-angle.com:5000/"
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func ListArticlesByUser(c *gin.Context) {
|
|||||||
Forbidden(c)
|
Forbidden(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var articles *[]models.ListArtile
|
var articles *[]models.ListArticle
|
||||||
if published == "published" {
|
if published == "published" {
|
||||||
articles = article.ListPublishedArticlesByUser(claims.ID)
|
articles = article.ListPublishedArticlesByUser(claims.ID)
|
||||||
} else if published == "notpublished" {
|
} else if published == "notpublished" {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type BackArticle struct {
|
|||||||
IsDelete int8 `gorm:"column:is_delete" json:"isDelete"` // 删除标志
|
IsDelete int8 `gorm:"column:is_delete" json:"isDelete"` // 删除标志
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListArtile struct {
|
type ListArticle struct {
|
||||||
ID int `json:"-"`
|
ID int `json:"-"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
CreateTime time.Time `json:"createTime"`
|
CreateTime time.Time `json:"createTime"`
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
func articlePrivateRouter(router *gin.RouterGroup) {
|
func articlePrivateRouter(router *gin.RouterGroup) {
|
||||||
articleRouter := router.Group("/article")
|
articleRouter := router.Group("/article")
|
||||||
{
|
{
|
||||||
|
articleRouter.POST("", handler.SaveArticleHandler)
|
||||||
articleRouter.DELETE("/:id", handler.DeleteArticleHandler)
|
articleRouter.DELETE("/:id", handler.DeleteArticleHandler)
|
||||||
articleRouter.POST("/:id/publish", handler.PublishArticleHandler)
|
articleRouter.POST("/:id/publish", handler.PublishArticleHandler)
|
||||||
articleRouter.GET("/list/:published", handler.ListArticlesByUser)
|
articleRouter.GET("/list/:published", handler.ListArticlesByUser)
|
||||||
@@ -17,7 +18,6 @@ func articlePrivateRouter(router *gin.RouterGroup) {
|
|||||||
func articlePublicRouter(router *gin.RouterGroup) {
|
func articlePublicRouter(router *gin.RouterGroup) {
|
||||||
articleRouter := router.Group("/article")
|
articleRouter := router.Group("/article")
|
||||||
{
|
{
|
||||||
articleRouter.POST("", handler.SaveArticleHandler)
|
|
||||||
articleRouter.GET("/list", handler.ListPublishedArticlesHandler)
|
articleRouter.GET("/list", handler.ListPublishedArticlesHandler)
|
||||||
articleRouter.GET("/:id", handler.GetArticleHandler)
|
articleRouter.GET("/:id", handler.GetArticleHandler)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,32 +7,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//ListPublishedArticles list the articles published, use to show the articles to all people
|
//ListPublishedArticles list the articles published, use to show the articles to all people
|
||||||
func ListPublishedArticles() *[]models.ListArtile {
|
func ListPublishedArticles() *[]models.ListArticle {
|
||||||
return listArticles(1, 0)
|
return listArticles(1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListPublishedArticlesByUser(id int) *[]models.ListArtile {
|
func ListPublishedArticlesByUser(id int) *[]models.ListArticle {
|
||||||
return listArticles(1, id)
|
return listArticles(1, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
//ListAllArticles list all articles(without not published)
|
//ListNotPublishedArticlesByUser list all articles(without not published)
|
||||||
// TODO: need only show the user's not published article
|
func ListNotPublishedArticlesByUser(id int) *[]models.ListArticle {
|
||||||
func ListNotPublishedArticlesByUser(id int) *[]models.ListArtile {
|
|
||||||
return listArticles(0, id)
|
return listArticles(0, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listArticles(isPublish int, createUser int) *[]models.ListArtile {
|
func listArticles(isPublish int, createUser int) *[]models.ListArticle {
|
||||||
queryStr := "back_article.is_delete = 0 AND is_publish = " + strconv.Itoa(isPublish)
|
queryStr := "back_article.is_delete = 0 AND is_publish = " + strconv.Itoa(isPublish)
|
||||||
if createUser != 0 {
|
if createUser != 0 {
|
||||||
queryStr += " AND create_user = " + strconv.Itoa(createUser)
|
queryStr += " AND create_user = " + strconv.Itoa(createUser)
|
||||||
}
|
}
|
||||||
var res []models.ListArtile
|
var res []models.ListArticle
|
||||||
global.Db.Table("back_article").
|
global.Db.Table("back_article").
|
||||||
Select("back_user.username, back_article.*").
|
Select("back_user.username, back_article.*").
|
||||||
Joins("join back_user on back_article.create_user=back_user.id").
|
Joins("join back_user on back_article.create_user=back_user.id").
|
||||||
Where(queryStr).Find(&res)
|
Where(queryStr).Find(&res)
|
||||||
if res == nil {
|
if res == nil {
|
||||||
res = []models.ListArtile{}
|
res = []models.ListArticle{}
|
||||||
}
|
}
|
||||||
return &res
|
return &res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,13 +45,9 @@ type AreaSlice []models.AreaInfo
|
|||||||
|
|
||||||
func cacheNCovStatistics() {
|
func cacheNCovStatistics() {
|
||||||
resp := utils.GetWhioutHeader(global.CHINA_NCOV_STATISTIC_URL)
|
resp := utils.GetWhioutHeader(global.CHINA_NCOV_STATISTIC_URL)
|
||||||
var nCovRes map[string]string
|
var nCovRes map[string]interface{}
|
||||||
json.Unmarshal([]byte(resp), &nCovRes)
|
json.Unmarshal([]byte(resp), &nCovRes)
|
||||||
var nCovResData map[string]interface{}
|
nCovResData := (nCovRes["data"].(map[string]interface{}))["diseaseh5Shelf"].(map[string]interface{})
|
||||||
err := json.Unmarshal([]byte(nCovRes["data"]), &nCovResData)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if !needToRecache(nCovResData) {
|
if !needToRecache(nCovResData) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user