From 25beef5ccab7481de942a248ec3f1ae84e0f0b96 Mon Sep 17 00:00:00 2001 From: marco Date: Wed, 28 Jan 2026 12:47:02 +0100 Subject: [PATCH] fixed compilation errors --- src/handlers/locations.rs | 5 +++-- src/main.rs | 12 ++++++++++-- src/models/battery_status.rs | 1 - src/models/location.rs | 12 ++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/handlers/locations.rs b/src/handlers/locations.rs index 5dab84a..7cc3c10 100644 --- a/src/handlers/locations.rs +++ b/src/handlers/locations.rs @@ -1,8 +1,9 @@ use actix_web::web::Json; -use serde_json::json; +use serde::{Deserialize, Serialize}; +include!("../models/location.rs"); async fn get_locations() -> impl Responder { - let locations = vec![]; + let locations: Vec = vec![]; Json(locations) } diff --git a/src/main.rs b/src/main.rs index 56541a9..6216ef4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,20 @@ use actix_web::{web, App, HttpRequest, HttpServer, Responder}; +include!("handlers/locations.rs"); -async fn index() -> impl Responder { "Connection successful" } +async fn index(req: HttpRequest) -> impl Responder { "Connection successful" } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() - .service(web::resource("/").to(index)) + .route("/", web::get().to(index)) + .service( + web::scope("/api/v1") + .service(web::resource("/locations").to(|| { + get_locations() + })) + .service(web::resource("/locations").route(web::post().to(create_location))) + ) }) .bind("127.0.0.1:8080")? .run() diff --git a/src/models/battery_status.rs b/src/models/battery_status.rs index a4bb3f7..1019f02 100644 --- a/src/models/battery_status.rs +++ b/src/models/battery_status.rs @@ -1,4 +1,3 @@ -use serde::{Serialize, Deserialize}; use sqlx::Type; #[derive(Debug, Clone, Copy, Serialize, Deserialize, Type)] diff --git a/src/models/location.rs b/src/models/location.rs index 3e6f2b7..6824a89 100644 --- a/src/models/location.rs +++ b/src/models/location.rs @@ -1,15 +1,15 @@ -use serde::Deserialize; use bigdecimal::BigDecimal; +include!("battery_status.rs"); -#[derive(Deserialize)] +#[derive(Deserialize, Serialize)] struct Location { latitude: BigDecimal, longitude: BigDecimal, - accuracy: