chore: fix memo parent_id

This commit is contained in:
Steven
2024-01-06 13:22:02 +08:00
parent f5a1739472
commit fd8333eeda
3 changed files with 29 additions and 17 deletions

View File

@@ -80,8 +80,8 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
`memo.updated_ts AS updated_ts`,
`memo.row_status AS row_status`,
`memo.visibility AS visibility`,
`CASE WHEN memo_organizer.pinned = 1 THEN 1 ELSE 0 END AS pinned`,
"(SELECT related_memo_id from memo_relation where memo_id = id AND type = \"COMMENT\" LIMIT 1) as parent_id",
`memo_organizer.pinned AS pinned`,
`memo_relation.related_memo_id AS parent_id`,
}
if !find.ExcludeContent {
fields = append(fields, `memo.content AS content`)
@@ -89,9 +89,9 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
query := `SELECT ` + strings.Join(fields, ", ") + `
FROM memo
LEFT JOIN memo_organizer ON memo.id = memo_organizer.memo_id
LEFT JOIN memo_organizer ON memo.id = memo_organizer.memo_id AND memo.creator_id = memo_organizer.user_id
FULL JOIN memo_relation ON memo.id = memo_relation.memo_id AND memo_relation.type = "COMMENT"
WHERE ` + strings.Join(where, " AND ") + `
GROUP BY memo.id
ORDER BY ` + strings.Join(orders, ", ")
if find.Limit != nil {
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
@@ -109,6 +109,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
list := make([]*store.Memo, 0)
for rows.Next() {
var memo store.Memo
pinned := sql.NullBool{}
dests := []any{
&memo.ID,
&memo.CreatorID,
@@ -116,7 +117,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
&memo.UpdatedTs,
&memo.RowStatus,
&memo.Visibility,
&memo.Pinned,
&pinned,
&memo.ParentID,
}
if !find.ExcludeContent {
@@ -125,6 +126,9 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if err := rows.Scan(dests...); err != nil {
return nil, err
}
if pinned.Valid {
memo.Pinned = pinned.Bool
}
list = append(list, &memo)
}