🐛 Bug fixes on query statement

This commit is contained in:
2024-11-02 23:47:44 +08:00
parent 553a87ab78
commit f9a01bff70
8 changed files with 12 additions and 10 deletions

View File

@ -37,7 +37,7 @@ func universalPostFilter(c *fiber.Ctx, tx *gorm.DB) (*gorm.DB, error) {
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
return tx, fiber.NewError(fiber.StatusNotFound, err.Error())
}
tx = tx.Where("author_id = ?", author.ID)
tx = tx.Where("publisher_id = ?", author.ID)
}
if len(c.Query("category")) > 0 {
@ -330,7 +330,7 @@ func pinPost(c *fiber.Ctx) error {
user := c.Locals("user").(authm.Account)
var res models.Post
if err := database.C.Where("id = ? AND author_id = ?", c.Params("postId"), user.ID).First(&res).Error; err != nil {
if err := database.C.Where("id = ? AND publisher_id = ?", c.Params("postId"), user.ID).First(&res).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find post in your posts to pin: %v", err))
}

View File

@ -25,7 +25,7 @@ func listPinnedPost(c *fiber.Ctx) error {
}
tx := services.FilterPostDraft(database.C)
tx = tx.Where("author_id = ?", user.ID)
tx = tx.Where("publisher_id = ?", user.ID)
tx = tx.Where("pinned_at IS NOT NULL")
items, err := services.ListPost(tx, 100, 0, "published_at DESC")

View File

@ -74,7 +74,7 @@ func listRecommendationFriends(c *fiber.Ctx) error {
return uint(item.GetId())
})
tx = tx.Where("author_id IN ?", friendList)
tx = tx.Where("publisher_id IN ?", friendList)
countTx := tx
count, err := services.CountPost(countTx)

View File

@ -25,7 +25,7 @@ func listPostReplies(c *fiber.Ctx) error {
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
tx = tx.Where("author_id = ?", author.ID)
tx = tx.Where("publisher_id = ?", author.ID)
}
if len(c.Query("category")) > 0 {
@ -68,7 +68,7 @@ func listPostFeaturedReply(c *fiber.Ctx) error {
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
tx = tx.Where("author_id = ?", author.ID)
tx = tx.Where("publisher_id = ?", author.ID)
}
if len(c.Query("category")) > 0 {

View File

@ -24,7 +24,7 @@ func GetConversation(start uint, offset, take int, order string, participants []
SELECT p.*
FROM %s p
INNER JOIN conversation c ON p.reply_id = c.id AND p.author_id IN (?)
INNER JOIN conversation c ON p.reply_id = c.id AND p.publisher_id IN (?)
)
SELECT * FROM conversation ORDER BY %s DESC OFFSET %d LIMIT %d`,
table, table, order, offset, take,

View File

@ -41,7 +41,7 @@ func FilterPostWithUserContext(tx *gorm.DB, user *authm.Account) *gorm.DB {
})
tx = tx.Where(
"(visibility != ? OR (visibility != ? AND author_id IN ? AND author_id NOT IN ?) OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR author_id = ?)",
"(visibility != ? OR (visibility != ? AND publisher_id IN ? AND publisher_id NOT IN ?) OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR publisher_id = ?)",
NoneVisibility,
FriendsVisibility,
allowlist,
@ -91,7 +91,7 @@ func FilterPostWithPublishedAt(tx *gorm.DB, date time.Time) *gorm.DB {
}
func FilterPostWithAuthorDraft(tx *gorm.DB, uid uint) *gorm.DB {
return tx.Where("author_id = ? AND is_draft = ?", uid, true)
return tx.Where("publisher_id = ? AND is_draft = ?", uid, true)
}
func FilterPostDraft(tx *gorm.DB) *gorm.DB {