Handle no avatar, add delete avatar support

This commit is contained in:
blankhex committed 2026-10-22 23:08:23 +03:00
1 parent 35bff424f1
commit 3864a4c1cc
9 files changed
+110 -11

No files matched your search

+22
View File
@@ -179,6 +179,28 @@ func (r *Repository) SetAvatar(ctx context.Context, id int64, data []byte) error
return nil
}
func (r *Repository) DeleteAvatar(ctx context.Context, id int64) error {
query := "DELETE FROM avatars WHERE id = ?"
_, err := r.q.ExecContext(ctx, query, id)
if err != nil {
slog.Error("delete avatar", slog.String("op", "repo.DeleteAvatar"), slog.Int64("user_id", id), slog.Any("error", err))
return ErrInternal
}
return nil
}
// HasAvatar reports whether the user currently has an avatar stored.
func (r *Repository) HasAvatar(ctx context.Context, id int64) (bool, error) {
query := "SELECT EXISTS(SELECT 1 FROM avatars WHERE id = ?)"
var exists bool
err := r.q.QueryRowContext(ctx, query, id).Scan(&exists)
if err != nil {
slog.Error("has avatar", slog.String("op", "repo.HasAvatar"), slog.Int64("user_id", id), slog.Any("error", err))
return false, ErrInternal
}
return exists, nil
}
func (r *Repository) CleanupUsers(ctx context.Context) error {
query := "DELETE FROM users WHERE activated_at IS NULL and created_at < ?"
_, err := r.q.ExecContext(ctx, query, time.Now().UTC().Add(-5*time.Minute))