Skip to content

Commit edefe27

Browse files
chidiimitchellecm7
andauthored
feat: add profile avatar, verification, preferences, and activity history (#244)
Co-authored-by: mitchellecm7 <149884682+mitchellecm7@users.noreply.github.com>
1 parent b1cbd50 commit edefe27

5 files changed

Lines changed: 683 additions & 10 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
-- Profile Enhancements: verification, preferences, activity history
2+
-- Migration: 20260528000003_profile_enhancements.sql
3+
4+
-- Add verification status to user_profiles
5+
ALTER TABLE user_profiles
6+
ADD COLUMN IF NOT EXISTS verification_status VARCHAR(20) NOT NULL DEFAULT 'unverified'
7+
CHECK (verification_status IN ('unverified', 'pending', 'verified', 'rejected'));
8+
9+
-- Create user_preferences table
10+
CREATE TABLE IF NOT EXISTS user_preferences (
11+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
12+
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
13+
preferences JSONB NOT NULL DEFAULT '{}',
14+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
15+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
16+
CONSTRAINT user_preferences_user_id_key UNIQUE (user_id)
17+
);
18+
19+
-- Create profile_activity table
20+
CREATE TABLE IF NOT EXISTS profile_activity (
21+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
22+
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
23+
activity_type VARCHAR(50) NOT NULL,
24+
description TEXT,
25+
metadata JSONB DEFAULT '{}',
26+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
27+
);
28+
29+
-- Index for activity queries
30+
CREATE INDEX IF NOT EXISTS idx_profile_activity_user_id ON profile_activity(user_id);
31+
CREATE INDEX IF NOT EXISTS idx_profile_activity_created_at ON profile_activity(created_at DESC);
32+
33+
-- Trigger for user_preferences updated_at
34+
CREATE OR REPLACE FUNCTION update_user_preferences_updated_at()
35+
RETURNS TRIGGER AS $$
36+
BEGIN
37+
NEW.updated_at = NOW();
38+
RETURN NEW;
39+
END;
40+
$$ LANGUAGE plpgsql;
41+
42+
CREATE TRIGGER update_user_preferences_updated_at
43+
BEFORE UPDATE ON user_preferences
44+
FOR EACH ROW
45+
EXECUTE FUNCTION update_user_preferences_updated_at();

backend/src/app.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ pub async fn create_app(
114114
.route("/me", get(profiles::get_my_profile))
115115
.route("/:user_id", get(profiles::get_profile))
116116
.route("/:user_id", patch(profiles::update_profile))
117-
.route("/:user_id", delete(profiles::delete_profile));
117+
.route("/:user_id", delete(profiles::delete_profile))
118+
.route("/avatar", post(profiles::upload_avatar))
119+
.route("/preferences", get(profiles::get_preferences).put(profiles::update_preferences))
120+
.route("/:user_id/verify", patch(profiles::update_verification))
121+
.route("/:user_id/activity", get(profiles::get_profile_activity));
118122

119123
// -------------------- Files --------------------
120124
let files_routes = Router::new()

0 commit comments

Comments
 (0)