forked from mtusi2026/mtusi2026lab2
fixed a bug with NUL in strings
This commit is contained in:
@@ -50,7 +50,7 @@ func (c *Chats) CreateChat(ctx context.Context, callerID, title string, memberID
|
||||
INSERT INTO chats (title)
|
||||
VALUES ($1)
|
||||
RETURNING id::text, created_at`,
|
||||
title,
|
||||
encodeText(title),
|
||||
).Scan(&chat.ID, &chat.CreatedAt)
|
||||
if err != nil {
|
||||
return domain.Chat{}, mapErr(err)
|
||||
@@ -95,6 +95,7 @@ func (c *Chats) ChatByID(ctx context.Context, callerID, chatID string) (domain.C
|
||||
}
|
||||
return domain.Chat{}, err
|
||||
}
|
||||
chat.Title = decodeText(chat.Title)
|
||||
chat.CreatedAt = chat.CreatedAt.UTC()
|
||||
return chat, nil
|
||||
}
|
||||
@@ -134,6 +135,7 @@ func (c *Chats) ListChats(ctx context.Context, callerID, cursor string, limit in
|
||||
out, err := pgx.CollectRows(rows, func(r pgx.CollectableRow) (domain.Chat, error) {
|
||||
var ch domain.Chat
|
||||
err := r.Scan(&ch.ID, &ch.Title, &ch.CreatedAt, &ch.MemberIDs)
|
||||
ch.Title = decodeText(ch.Title)
|
||||
ch.CreatedAt = ch.CreatedAt.UTC()
|
||||
return ch, err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user