Can download uploaded images
This commit is contained in:
@ -2,7 +2,7 @@ use crate::constants::{SizeConstraint, StaticConstraints};
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::extractors::family_extractor::FamilyInPath;
|
||||
use crate::extractors::member_extractor::FamilyAndMemberInPath;
|
||||
use crate::models::{Member, MemberID, Sex};
|
||||
use crate::models::{Member, MemberID, PhotoID, Sex};
|
||||
use crate::services::{members_service, photos_service};
|
||||
use crate::utils::countries_utils;
|
||||
use actix_multipart::form::tempfile::TempFile;
|
||||
@ -231,6 +231,22 @@ impl MemberRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct MemberAPI {
|
||||
#[serde(flatten)]
|
||||
member: Member,
|
||||
signed_photo_id: Option<String>,
|
||||
}
|
||||
|
||||
impl MemberAPI {
|
||||
pub fn new(member: Member) -> Self {
|
||||
Self {
|
||||
signed_photo_id: member.photo_id().as_ref().map(PhotoID::to_signed_hash),
|
||||
member,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new family member
|
||||
pub async fn create(f: FamilyInPath, req: web::Json<MemberRequest>) -> HttpResult {
|
||||
let mut member = members_service::create(f.family_id()).await?;
|
||||
@ -253,12 +269,12 @@ pub async fn create(f: FamilyInPath, req: web::Json<MemberRequest>) -> HttpResul
|
||||
/// Get the entire list of members of the family
|
||||
pub async fn get_all(f: FamilyInPath) -> HttpResult {
|
||||
let members = members_service::get_all_of_family(f.family_id()).await?;
|
||||
Ok(HttpResponse::Ok().json(members))
|
||||
Ok(HttpResponse::Ok().json(members.into_iter().map(MemberAPI::new).collect::<Vec<_>>()))
|
||||
}
|
||||
|
||||
/// Get the information of a single family member
|
||||
pub async fn get_single(m: FamilyAndMemberInPath) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(m.to_member()))
|
||||
Ok(HttpResponse::Ok().json(MemberAPI::new(m.to_member())))
|
||||
}
|
||||
|
||||
/// Update a member information
|
||||
|
Reference in New Issue
Block a user