去年默认配置。
This commit is contained in:
@@ -77,6 +77,11 @@ func GetPosts(c *gin.Context) {
|
||||
db = db.Where("category_id = ?", query.CategoryID)
|
||||
}
|
||||
|
||||
userId, exists := c.Get("userID")
|
||||
if exists {
|
||||
db = db.Where("author_id = ?", userId)
|
||||
}
|
||||
|
||||
if query.TagID > 0 {
|
||||
db = db.Joins("JOIN post_tags ON post_tags.post_id = posts.id").
|
||||
Where("post_tags.tag_id = ?", query.TagID)
|
||||
|
||||
@@ -76,6 +76,12 @@ func IndexView(c *gin.Context) {
|
||||
db := database.DB.Model(&models.Post{}).Preload("Category").Preload("Tags").Preload("Author").
|
||||
Where("status = ?", "published")
|
||||
|
||||
userId, exists := c.Get("userID")
|
||||
userId, exists = 1, true
|
||||
if exists {
|
||||
db = db.Or("author_id = ?", userId)
|
||||
}
|
||||
|
||||
if categoryID > 0 {
|
||||
db = db.Where("category_id = ?", categoryID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user