Add frontend tests and other stuff
[recipes.git] / backend / src / data / asynchronous.rs
index 4dda803..a5a5cdf 100644 (file)
@@ -49,17 +49,17 @@ fn combine_errors<T>(error: std::result::Result<std::result::Result<T, DBAsyncEr
 type Result<T> = std::result::Result<T, DBAsyncError>;
 
 impl Connection {
-    pub async fn get_all_recipe_titles_async(&self) -> Result<Vec<(i32, String)>> {
+    pub async fn get_all_recipe_titles_async(&self) -> Result<Vec<(i64, String)>> {
         let self_copy = self.clone();
         web::block(move || { self_copy.get_all_recipe_titles().unwrap_or_default() }).await.map_err(DBAsyncError::from)
     }
 
-    pub async fn get_recipe_async(&self, id: i32) -> Result<model::Recipe> {
+    pub async fn get_recipe_async(&self, id: i64) -> Result<model::Recipe> {
         let self_copy = self.clone();
         combine_errors(web::block(move || { self_copy.get_recipe(id).map_err(DBAsyncError::from) }).await)
     }
 
-    pub async fn load_user_async(&self, user_id: i32) -> Result<User> {
+    pub async fn load_user_async(&self, user_id: i64) -> Result<User> {
         let self_copy = self.clone();
         combine_errors(web::block(move || { self_copy.load_user(user_id).map_err(DBAsyncError::from) }).await)
     }
@@ -101,4 +101,15 @@ impl Connection {
         let token_copy = token.to_string();
         combine_errors(web::block(move || { self_copy.sign_out(&token_copy).map_err(DBAsyncError::from) }).await)
     }
+
+    pub async fn create_recipe_async(&self, user_id: i64) -> Result<i64> {
+        let self_copy = self.clone();
+        combine_errors(web::block(move || { self_copy.create_recipe(user_id).map_err(DBAsyncError::from) }).await)
+    }
+
+    pub async fn set_recipe_title_async(&self, recipe_id: i64, title: &str) -> Result<()> {
+        let self_copy = self.clone();
+        let title_copy = title.to_string();
+        combine_errors(web::block(move || { self_copy.set_recipe_title(recipe_id, &title_copy).map_err(DBAsyncError::from) }).await)
+    }
 }
\ No newline at end of file