Move database into the main app
I was having issues including the lib as a crate, its fine just being a module for now.
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -1,21 +1,32 @@
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
use actix_web::web::{HttpResponse, Json};
|
||||
use actix_web::{get, post, App, HttpServer, Responder};
|
||||
use data::{LoginRequest, ThumbnailRequest};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::files::list_files;
|
||||
use crate::database::{create_user, get_user};
|
||||
|
||||
mod data;
|
||||
mod database;
|
||||
mod files;
|
||||
|
||||
#[post("/register")]
|
||||
async fn register() -> impl Responder {
|
||||
create_user("u", "p");
|
||||
println!("{:?}", get_user("u", "p"));
|
||||
"".to_owned()
|
||||
}
|
||||
|
||||
#[post("/login")]
|
||||
async fn login(_creds: Json<LoginRequest>) -> impl Responder {
|
||||
"".to_owned()
|
||||
async fn login(creds: Json<LoginRequest>) -> impl Responder {
|
||||
if let Some(user) = get_user(&creds.username, &creds.password) {
|
||||
HttpResponse::Ok().json(user)
|
||||
} else {
|
||||
HttpResponse::NotFound().finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/photos")]
|
||||
@@ -43,7 +54,7 @@ async fn list_photos(req: Json<ThumbnailRequest>) -> impl Responder {
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(login).service(list_photos))
|
||||
HttpServer::new(|| App::new().service(login).service(list_photos).service(register))
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user