Move to FKs
This commit is contained in:
1 parent
96bfef4575
commit
a9cc0b8f0a
32 files changed
+875
-305
No files matched your search
@@ -109,3 +109,34 @@ macro_rules! path {
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! update_image_field {
|
||||
($pool:expr, $error:ident, $reminder:ident, $field:ident, $id:ident) => {
|
||||
if let Some(value) = &$reminder.$field {
|
||||
match crate::image_upload::ImageReference::from_url($pool, value.as_deref()).await {
|
||||
Ok(image) => {
|
||||
if let Err(e) = sqlx::query(concat!(
|
||||
"UPDATE reminders SET `",
|
||||
stringify!($field),
|
||||
"` = ?, `",
|
||||
stringify!($id),
|
||||
"` = ? WHERE uid = ?"
|
||||
))
|
||||
.bind(image.url)
|
||||
.bind(image.id)
|
||||
.bind(&$reminder.uid)
|
||||
.execute($pool)
|
||||
.await
|
||||
{
|
||||
warn!("Could not update image reference: {:?}", e);
|
||||
$error.push(format!("Error setting field {}", stringify!($field)));
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Could not resolve image upload: {:?}", e);
|
||||
$error.push(format!("Error setting field {}", stringify!($field)));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user