Fixed file upload
This commit is contained in:
@@ -6,6 +6,6 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
last_name TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
profile TEXT,
|
||||
profile_picture TEXT,
|
||||
verified BOOLEAN NOT NULL DEFAULT FALSE
|
||||
);
|
||||
@@ -29,7 +29,7 @@ impl RegisterUser {
|
||||
last_name: self.last_name,
|
||||
updated_at: chrono::Utc::now().naive_utc(),
|
||||
created_at: chrono::Utc::now().naive_utc(),
|
||||
profile: None,
|
||||
profile_picture: None,
|
||||
verified: false,
|
||||
})
|
||||
}
|
||||
@@ -51,7 +51,7 @@ pub struct QueryUser {
|
||||
pub last_name: String,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
pub created_at: chrono::NaiveDateTime,
|
||||
pub profile: Option<String>,
|
||||
pub profile_picture: Option<String>,
|
||||
pub verified: bool,
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ pub struct InsertUser {
|
||||
pub last_name: String,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
pub created_at: chrono::NaiveDateTime,
|
||||
pub profile: Option<String>,
|
||||
pub profile_picture: Option<String>,
|
||||
pub verified: bool,
|
||||
}
|
||||
|
||||
@@ -90,11 +90,11 @@ impl InsertUser {
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
pub fn update_profile(email: &str, profile: Option<&str>) -> Result<QueryUser, ServiceError> {
|
||||
pub fn update_profile(email: &str, profile_picture: Option<&str>) -> Result<QueryUser, ServiceError> {
|
||||
let mut conn = connection()?;
|
||||
let user = diesel::update(users::table)
|
||||
.filter(users::email.eq(&email))
|
||||
.set(users::profile.eq(profile))
|
||||
.set(users::profile_picture.eq(profile_picture))
|
||||
.get_result(&mut conn)?;
|
||||
Ok(user)
|
||||
}
|
||||
@@ -106,6 +106,7 @@ pub struct ResponseUser {
|
||||
pub role: String,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
pub profile_picture: Option<String>,
|
||||
}
|
||||
|
||||
impl From<QueryUser> for ResponseUser {
|
||||
@@ -115,6 +116,7 @@ impl From<QueryUser> for ResponseUser {
|
||||
role: user.role,
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
profile_picture: user.profile_picture,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ diesel::table! {
|
||||
last_name -> Text,
|
||||
updated_at -> Timestamp,
|
||||
created_at -> Timestamp,
|
||||
profile -> Nullable<Text>,
|
||||
profile_picture -> Nullable<Text>,
|
||||
verified -> Bool,
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ async fn get_picture(auth: JwtAuth) -> HttpResponse {
|
||||
return ResponseError::error_response(&err);
|
||||
}
|
||||
};
|
||||
if let Some(path) = user.profile {
|
||||
if let Some(path) = user.profile_picture {
|
||||
match get_file(&path).await {
|
||||
Ok(bytes) => return HttpResponse::Ok().body(bytes),
|
||||
Err(err) => {
|
||||
@@ -98,7 +98,7 @@ async fn get_picture(auth: JwtAuth) -> HttpResponse {
|
||||
async fn delete_picture(auth: JwtAuth) -> HttpResponse {
|
||||
match QueryUser::get_by_email(&auth.user.email) {
|
||||
Ok(user) => {
|
||||
match user.profile {
|
||||
match user.profile_picture {
|
||||
Some(path) => {
|
||||
match delete_file(&path).await {
|
||||
Ok(_) => {
|
||||
|
||||
Reference in New Issue
Block a user