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:
Cameron Cordes
2020-07-07 21:48:29 -04:00
parent 1c1c8531aa
commit 2aa1b61429
13 changed files with 139 additions and 221 deletions

View File

@@ -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