reasonkit_web/portal/
profile.rs1use axum::{
13 extract::{Json, Multipart},
14 http::StatusCode,
15 response::IntoResponse,
16};
17use chrono::{DateTime, Utc};
18use serde::{Deserialize, Serialize};
19use uuid::Uuid;
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct Profile {
24 pub id: Uuid,
26 pub email: String,
28 pub name: Option<String>,
30 pub avatar_url: Option<String>,
32 pub timezone: Option<String>,
34 pub language: String,
36 pub created_at: DateTime<Utc>,
38 pub updated_at: DateTime<Utc>,
40 pub email_verified: bool,
42 pub two_factor_enabled: bool,
44 pub status: AccountStatus,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
49#[serde(rename_all = "lowercase")]
50pub enum AccountStatus {
51 Active,
52 Suspended,
53 PendingDeletion,
54 Deleted,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct ProfileUpdate {
60 pub name: Option<String>,
61 pub timezone: Option<String>,
62 pub language: Option<String>,
63}
64
65pub struct ProfileService {
67 }
69
70impl ProfileService {
71 pub fn new() -> Self {
72 Self {}
73 }
74
75 pub async fn get_profile(&self, _user_id: Uuid) -> Result<Profile, ProfileError> {
77 Err(ProfileError::NotFound)
79 }
80
81 pub async fn update_profile(
83 &self,
84 _user_id: Uuid,
85 _update: ProfileUpdate,
86 ) -> Result<Profile, ProfileError> {
87 Err(ProfileError::NotFound)
89 }
90
91 pub async fn upload_avatar(
93 &self,
94 _user_id: Uuid,
95 _data: Vec<u8>,
96 _content_type: &str,
97 ) -> Result<String, ProfileError> {
98 Err(ProfileError::StorageError("Not implemented".to_string()))
100 }
101
102 pub async fn delete_account(&self, _user_id: Uuid) -> Result<(), ProfileError> {
104 Err(ProfileError::NotFound)
109 }
110}
111
112impl Default for ProfileService {
113 fn default() -> Self {
114 Self::new()
115 }
116}
117
118#[derive(Debug, thiserror::Error)]
120pub enum ProfileError {
121 #[error("Profile not found")]
122 NotFound,
123 #[error("Email already in use")]
124 EmailConflict,
125 #[error("Invalid update data: {0}")]
126 ValidationError(String),
127 #[error("Storage error: {0}")]
128 StorageError(String),
129 #[error("Database error: {0}")]
130 DatabaseError(String),
131}
132
133pub mod handlers {
135 use super::*;
136
137 pub async fn get_profile() -> impl IntoResponse {
139 let profile = Profile {
140 id: Uuid::new_v4(),
141 email: "user@example.com".to_string(),
142 name: Some("Example User".to_string()),
143 avatar_url: None,
144 timezone: Some("UTC".to_string()),
145 language: "en".to_string(),
146 created_at: Utc::now(),
147 updated_at: Utc::now(),
148 email_verified: true,
149 two_factor_enabled: false,
150 status: AccountStatus::Active,
151 };
152 (StatusCode::OK, Json(profile))
153 }
154
155 pub async fn update_profile(Json(_update): Json<ProfileUpdate>) -> impl IntoResponse {
157 (
159 StatusCode::OK,
160 Json(serde_json::json!({"success": true, "message": "Profile updated"})),
161 )
162 }
163
164 pub async fn upload_avatar(_multipart: Multipart) -> impl IntoResponse {
166 StatusCode::NOT_IMPLEMENTED
168 }
169
170 pub async fn delete_account() -> impl IntoResponse {
172 (
174 StatusCode::ACCEPTED,
175 Json(serde_json::json!({
176 "success": true,
177 "message": "Account deletion scheduled. You will receive an email confirmation."
178 })),
179 )
180 }
181}