Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ target/
.idea/
*.swp
*.swo
*#
*~

# OS
.DS_Store
Expand Down
97 changes: 56 additions & 41 deletions backend/Cargo.lock

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

6 changes: 3 additions & 3 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[[bin]]
name = "guild-backend-dev"
path = "src/main_dev.rs"
name = "guild-backend"
path = "src/main.rs"

[[bin]]
name = "migrate"
Expand All @@ -32,7 +32,7 @@ ethers = { version = "2.0", features = ["rustls"] }
sha3 = "0.10"

# Pin problematic dependencies to avoid edition 2024
base64ct = "=1.7.3"
base64ct = "1.7.3"

# Utilities
anyhow = "1.0"
Expand Down
1 change: 1 addition & 0 deletions backend/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edition = "2018"
55 changes: 55 additions & 0 deletions backend/src/application/commands/create_profile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::application::dtos::profile_dtos::{
CreateProfileRequest, ProfileListResponse, ProfileResponse, UpdateProfileRequest,
};
use crate::domain::repositories::profile_repository::ProfileRepository;
use crate::domain::services::AuthService;
use crate::domain::value_objects::wallet_address::WalletAddress;
use std::sync::Arc;

#[derive(Clone)]
pub struct ProfileApplicationService {
profile_repository: Arc<dyn ProfileRepository + Send + Sync>,
auth_service: Arc<dyn AuthService + Send + Sync>,
}

pub async fn create_profile(
&self,
request: CreateProfileRequest,
) -> Result<ProfileResponse, String> {
let wallet_address = WalletAddress::new(request.address).map_err(|e| e.to_string())?;
let user = self
.user_repository
.find_by_wallet_address(&wallet_address.to_string())
.await
.map_err(|e| e.to_string())?
.ok_or("User not found")?;

// Check if profile already exists
if self
.profile_repository
.find_by_user_id(&user.id)
.await
.map_err(|e| e.to_string())?
.is_some()
{
return Err("Profile already exists for this user".to_string());
}

let mut profile = crate::domain::entities::profile::Profile::new(user.id);
profile.update_info(Some(request.name), request.description, request.avatar_url);

self.profile_repository
.create(&profile)
.await
.map_err(|e| e.to_string())?;

Ok(ProfileResponse {
id: profile.id,
user_id: profile.user_id,
name: profile.name.unwrap_or_default(),
description: profile.description,
avatar_url: profile.avatar_url,
created_at: profile.created_at,
updated_at: profile.updated_at,
})
}
40 changes: 40 additions & 0 deletions backend/src/application/commands/get_profile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::application::dtos::profile_dtos::{
CreateProfileRequest, ProfileListResponse, ProfileResponse, UpdateProfileRequest,
};
use crate::domain::repositories::profile_repository::ProfileRepository;
use crate::domain::services::AuthService;
use crate::domain::value_objects::wallet_address::WalletAddress;
use std::sync::Arc;

#[derive(Clone)]
pub struct ProfileApplicationService {
profile_repository: Arc<dyn ProfileRepository + Send + Sync>,
auth_service: Arc<dyn AuthService + Send + Sync>,
}

pub async fn GetProfile(&self, address: String) -> Result<ProfileResponse, String> {
let wallet_address = WalletAddress::new(address).map_err(|e| e.to_string())?;
let user = self
.user_repository
.find_by_wallet_address(&wallet_address.to_string())
.await
.map_err(|e| e.to_string())?
.ok_or("User not found")?;

let profile = self
.profile_repository
.find_by_user_id(&user.id)
.await
.map_err(|e| e.to_string())?
.ok_or("Profile not found")?;

Ok(ProfileResponse {
id: profile.id,
user_id: profile.user_id,
name: profile.name.unwrap_or_default(),
description: profile.description,
avatar_url: profile.avatar_url,
created_at: profile.created_at,
updated_at: profile.updated_at,
})
}
3 changes: 3 additions & 0 deletions backend/src/application/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod create_profile;
pub mod get_profile;
pub mod update_profile;
Loading
Loading