working example with write and select

This commit is contained in:
2026-01-29 15:50:56 +01:00
parent 361bd7bc4a
commit 71b17a11bd
10 changed files with 150 additions and 99 deletions

View File

@@ -1,42 +1,19 @@
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use colota_backend::establish_connection;
use diesel::prelude::*;
use dotenvy::dotenv;
use std::env;
use actix_web::{web, App, HttpServer};
use colota_backend::{create_pool, DbPool};
pub use colota_backend::schema;
pub use colota_backend::models;
include!("handlers/locations.rs");
async fn index() -> impl Responder { "Connection successful" }
pub use colota_backend::routes;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use self::schema::locations::dsl::*;
let pool: DbPool = create_pool();
let connection = &mut establish_connection();
let results = locations
.select(Location::as_select())
.load(connection)
.expect("Error loading locations");
println!("Displaying {} locations", results.len());
HttpServer::new(|| {
HttpServer::new(move || {
App::new()
.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)))
)
.app_data(web::Data::new(pool.clone()))
.configure(routes::config_routes)
})
.bind("127.0.0.1:8080")?
.bind(("0.0.0.0", 8080))?
.run()
.await
}