Compare commits

..

No commits in common. "8e3c87f315711afe4d13a18f76eaeeb243e2cade" and "74bd1a89e5ef90ca4c9885c37320ede546542722" have entirely different histories.

2 changed files with 14 additions and 22 deletions

View file

@ -7,14 +7,6 @@ use std::sync::Arc;
#[cfg(feature = "ssr")]
use tokio::sync::Mutex;
use serde::Deserialize;
#[cfg(feature = "ssr")]
#[derive(Deserialize)]
pub struct ItemRequest {
pub url: String,
pub item: DbItem,
}
#[cfg(feature = "ssr")]
pub async fn get_items(
db: web::Data<Arc<Mutex<Database>>>,
@ -33,11 +25,16 @@ pub async fn get_items(
#[cfg(feature = "ssr")]
pub async fn create_item(
db: web::Data<Arc<Mutex<Database>>>,
request: web::Json<ItemRequest>,
url: web::Query<String>,
item: web::Json<DbItem>,
) -> HttpResponse {
match db.lock().await.insert_item_by_url(&request.url, &request.item).await {
Ok(_) => HttpResponse::Ok().body("Item created"),
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
let db = db.lock().await;
match db.insert_item_by_url(&url, &item.into_inner()).await {
Ok(_) => HttpResponse::Ok().body("Item inserted"),
Err(err) => {
leptos::logging::error!("Failed to insert item: {:?}", err);
HttpResponse::InternalServerError().body("Failed to insert item")
}
}
}

View file

@ -1,9 +1,9 @@
#[cfg(feature = "ssr")]
use actix_web::{web, HttpResponse, Responder};
use actix_web::{web, App, HttpServer, HttpResponse, Responder};
use std::sync::Arc;
use tokio::sync::Mutex;
use compareware::db::{Database, DbItem};
use compareware::api::{ItemRequest,create_item, get_items, delete_item_by_url};
use compareware::api::{create_item, get_items, delete_item_by_url};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
@ -12,7 +12,7 @@ async fn main() -> std::io::Result<()> {
use leptos::*;
use leptos_actix::{generate_route_list, LeptosRoutes};
use compareware::app::*;
use compareware::db::Database;
use compareware::db::{Database, DbItem};
use compareware::api::{get_items, create_item, delete_item, delete_property, delete_item_by_url, delete_property_by_url, create_item_by_url, get_items_by_url}; // Import API handlers
use std::sync::Arc;
use tokio::sync::Mutex;
@ -85,15 +85,10 @@ async fn get_items_handler(
// Handler to create an item for a specific URL
async fn create_item_handler(
db: web::Data<Arc<Mutex<Database>>>,
path: web::Path<String>,
url: web::Path<String>,
item: web::Json<DbItem>,
) -> impl Responder {
let url = path.into_inner();
let request = ItemRequest {
url,
item: item.into_inner()
};
create_item(db, web::Json(request)).await
create_item(db, web::Query(url.into_inner()), item).await
}
// Handler to delete an item for a specific URL