minimal working example with diesel
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -1,19 +1,39 @@
|
||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||
use colota_backend::establish_connection;
|
||||
use diesel::prelude::*;
|
||||
use dotenvy::dotenv;
|
||||
use std::env;
|
||||
|
||||
pub use colota_backend::schema;
|
||||
pub use colota_backend::models;
|
||||
|
||||
include!("handlers/locations.rs");
|
||||
|
||||
async fn index(req: HttpRequest) -> impl Responder { "Connection successful" }
|
||||
async fn index() -> impl Responder { "Connection successful" }
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
use self::schema::locations::dsl::*;
|
||||
|
||||
|
||||
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(|| {
|
||||
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)))
|
||||
// .service(web::resource("/locations").to(|| {
|
||||
// // get_locations()
|
||||
// }))
|
||||
// .service(web::resource("/locations").route(web::post().to(create_location)))
|
||||
)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
|
||||
Reference in New Issue
Block a user