feat: auth user feedbacks
This commit is contained in:
@@ -85,6 +85,39 @@ func (r *FeedbackRepo) MarkResolved(ctx context.Context, id string) (resolved bo
|
||||
return tag.RowsAffected() == 1, nil
|
||||
}
|
||||
|
||||
// ListByUser returns a single user's own feedback submissions, newest
|
||||
// first, with status timestamps and any admin reply. Backs the "My
|
||||
// feedback" page under /settings. No author joins — the caller IS the
|
||||
// author, so handle/name/email aren't needed here. Bounded limit keeps
|
||||
// the query cheap.
|
||||
func (r *FeedbackRepo) ListByUser(ctx context.Context, userID string, limit int) ([]model.Feedback, error) {
|
||||
if limit <= 0 || limit > 200 {
|
||||
limit = 50
|
||||
}
|
||||
rows, err := r.pg.Pool.Query(ctx, `
|
||||
SELECT id, user_id, category, message, contact_email, created_at,
|
||||
acknowledged_at, resolved_at, replied_at, reply_message
|
||||
FROM feedback
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2`, userID, limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query user feedback: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []model.Feedback{}
|
||||
for rows.Next() {
|
||||
var f model.Feedback
|
||||
if err := rows.Scan(&f.ID, &f.UserID, &f.Category, &f.Message, &f.ContactEmail, &f.CreatedAt,
|
||||
&f.AcknowledgedAt, &f.ResolvedAt, &f.RepliedAt, &f.ReplyMessage); err != nil {
|
||||
return nil, fmt.Errorf("scan user feedback: %w", err)
|
||||
}
|
||||
out = append(out, f)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// Recent returns the most-recent N feedback rows joined with users
|
||||
// for display on /stats. NULL author columns mean anonymous (or the
|
||||
// original submitter's account was since deleted).
|
||||
|
||||
Reference in New Issue
Block a user