Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/migrations/005_add_twitter_handle.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS twitter_handle TEXT;
CREATE UNIQUE INDEX IF NOT EXISTS unique_twitter_handle_lower ON profiles (LOWER(twitter_handle));
1 change: 1 addition & 0 deletions backend/src/application/commands/create_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub async fn create_profile(
description: profile.description,
avatar_url: profile.avatar_url,
github_login: profile.github_login,
twitter_handle: profile.twitter_handle,
created_at: profile.created_at,
updated_at: profile.updated_at,
})
Expand Down
26 changes: 26 additions & 0 deletions backend/src/application/commands/update_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ pub async fn update_profile(
profile.github_login = Some(trimmed.to_string());
}
}
if let Some(ref handle) = request.twitter_handle {
let trimmed = handle.trim();

// Allow empty handles (set to None)
if trimmed.is_empty() {
profile.twitter_handle = None;
} else {
// Validate format for non-empty handles (Twitter/X handle: 1-15 alphanumeric + underscores)
let valid_format = regex::Regex::new(r"^[a-zA-Z0-9_]{1,15}$").unwrap();
if !valid_format.is_match(trimmed) {
return Err("Invalid Twitter handle format".to_string());
}
if let Some(conflicting_profile) = profile_repository
.find_by_twitter_handle(trimmed)
.await
.map_err(|e| e.to_string())?
{
// Only conflict if it's not the current user's profile
if conflicting_profile.address != wallet_address {
return Err("Twitter handle already taken".to_string());
}
}
profile.twitter_handle = Some(trimmed.to_string());
}
}
profile_repository
.update(&profile)
.await
Expand All @@ -54,6 +79,7 @@ pub async fn update_profile(
description: profile.description,
avatar_url: profile.avatar_url,
github_login: profile.github_login,
twitter_handle: profile.twitter_handle,
created_at: profile.created_at,
updated_at: profile.updated_at,
})
Expand Down
2 changes: 2 additions & 0 deletions backend/src/application/dtos/profile_dtos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct UpdateProfileRequest {
pub description: Option<String>,
pub avatar_url: Option<String>,
pub github_login: Option<String>,
pub twitter_handle: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -24,6 +25,7 @@ pub struct ProfileResponse {
pub description: Option<String>,
pub avatar_url: Option<String>,
pub github_login: Option<String>,
pub twitter_handle: Option<String>,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
}
1 change: 1 addition & 0 deletions backend/src/application/queries/get_all_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub async fn get_all_profiles(
description: profile.description,
avatar_url: profile.avatar_url,
github_login: profile.github_login,
twitter_handle: profile.twitter_handle,
created_at: profile.created_at,
updated_at: profile.updated_at,
})
Expand Down
1 change: 1 addition & 0 deletions backend/src/application/queries/get_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub async fn get_profile(
description: profile.description,
avatar_url: profile.avatar_url,
github_login: profile.github_login,
twitter_handle: profile.twitter_handle,
created_at: profile.created_at,
updated_at: profile.updated_at,
})
Expand Down
2 changes: 2 additions & 0 deletions backend/src/domain/entities/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Profile {
pub description: Option<String>,
pub avatar_url: Option<String>,
pub github_login: Option<String>,
pub twitter_handle: Option<String>,
pub login_nonce: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
Expand All @@ -24,6 +25,7 @@ impl Profile {
description: None,
avatar_url: None,
github_login: None,
twitter_handle: None,
login_nonce: 1,
created_at: now,
updated_at: now,
Expand Down
4 changes: 4 additions & 0 deletions backend/src/domain/repositories/profile_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub trait ProfileRepository: Send + Sync {
&self,
github_login: &str,
) -> Result<Option<Profile>, Box<dyn std::error::Error + Send + Sync>>;
async fn find_by_twitter_handle(
&self,
twitter_handle: &str,
) -> Result<Option<Profile>, Box<dyn std::error::Error + Send + Sync>>;
async fn get_login_nonce_by_wallet_address(
&self,
address: &WalletAddress,
Expand Down
Loading
Loading