去年默认配置。

This commit is contained in:
2026-07-22 18:02:05 +08:00
parent aab3aeb5b2
commit 8d0b75e484
7 changed files with 43 additions and 76 deletions
+5
View File
@@ -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)
+6
View File
@@ -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)
}