Can delete member image

This commit is contained in:
2023-08-07 11:07:24 +02:00
parent c27ed56b8a
commit c6148f6562
14 changed files with 555 additions and 14 deletions

View File

@ -1,4 +1,4 @@
use crate::schema::{families, members, memberships, users};
use crate::schema::{families, members, memberships, photos, users};
use diesel::prelude::*;
/// User ID holder
@ -121,6 +121,52 @@ pub struct FamilyMembership {
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
pub struct PhotoID(pub i32);
#[derive(Queryable, Debug, serde::Serialize)]
pub struct Photo {
id: i32,
pub file_id: String,
pub time_create: i64,
pub mime_type: String,
pub sha512: String,
pub file_size: i32,
pub thumb_sha512: String,
}
impl Photo {
pub fn id(&self) -> PhotoID {
PhotoID(self.id)
}
pub fn photo_path(&self) -> String {
format!("photo/{}", self.file_id)
}
pub fn thumbnail_path(&self) -> String {
format!("thumbnail/{}", self.file_id)
}
}
#[derive(Insertable)]
#[diesel(table_name = photos)]
pub struct NewPhoto {
pub file_id: String,
pub time_create: i64,
pub mime_type: String,
pub sha512: String,
pub file_size: i32,
pub thumb_sha512: String,
}
impl NewPhoto {
pub fn photo_path(&self) -> String {
format!("photo/{}", self.file_id)
}
pub fn thumbnail_path(&self) -> String {
format!("thumbnail/{}", self.file_id)
}
}
/// Member ID holder
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
pub struct MemberID(pub i32);
@ -187,6 +233,10 @@ impl Member {
FamilyID(self.family_id)
}
pub fn set_photo_id(&mut self, p: Option<PhotoID>) {
self.photo_id = p.map(|p| p.0)
}
pub fn photo_id(&self) -> Option<PhotoID> {
self.photo_id.map(PhotoID)
}