mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
invites: CreateInvite, GetInvite, UseInviteAtomic, RevokeInvite, ListInvites. attachments: CreateAttachment, GetAttachmentByID, GetAttachmentWithChannel, DeleteOrphanedAttachments. Added ptrI64toI / ptrItoI64 helpers for the *int64<->*int narrowing (invite max_uses, attachment width/height). LinkAttachmentsToMessage and GetAttachmentsByMessageIDs keep raw SQL (variable-length IN() lists sqlc can't express). Behavior and signatures unchanged. Verified: go build ./...; go test ./db (Invite, Attachment). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UA17KPvqGBX3XbXYnMf1rA
27 lines
669 B
Go
27 lines
669 B
Go
package db
|
|
|
|
import "fmt"
|
|
|
|
// ListInvites returns invites ordered by creation time descending.
|
|
// M-12: Limited to 200 rows to prevent unbounded result sets.
|
|
func (d *DB) ListInvites() ([]*Invite, error) {
|
|
rows, err := d.q.ListInvites(dbCtx())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("ListInvites: %w", err)
|
|
}
|
|
invites := make([]*Invite, 0, len(rows))
|
|
for _, r := range rows {
|
|
invites = append(invites, &Invite{
|
|
ID: r.ID,
|
|
Code: r.Code,
|
|
CreatedBy: r.CreatedBy,
|
|
Uses: int(r.UseCount),
|
|
MaxUses: ptrI64toI(r.MaxUses),
|
|
ExpiresAt: r.ExpiresAt,
|
|
Revoked: r.Revoked != 0,
|
|
CreatedAt: r.CreatedAt,
|
|
})
|
|
}
|
|
return invites, nil
|
|
}
|