Formatted files
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use crate::types::*;
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
use crate::types::*;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder, get, web};
|
||||||
use serde_json::to_string;
|
use serde_json::to_string;
|
||||||
use sqlx::query_as;
|
use sqlx::query_as;
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ async fn get_case_items(query: web::Query<DataUuid>, app_state: Data<AppState>)
|
|||||||
"SELECT * FROM items_cases WHERE \"case\" = $1",
|
"SELECT * FROM items_cases WHERE \"case\" = $1",
|
||||||
case.id
|
case.id
|
||||||
)
|
)
|
||||||
.fetch_all(&app_state.database)
|
.fetch_all(&app_state.database)
|
||||||
.await;
|
.await;
|
||||||
if items_cases.is_err() {
|
if items_cases.is_err() {
|
||||||
return HttpResponse::NotFound().finish();
|
return HttpResponse::NotFound().finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::types::*;
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
use crate::types::*;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{get, web, HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder, get, web};
|
||||||
use serde_json::to_string;
|
use serde_json::to_string;
|
||||||
use sqlx::query_as;
|
use sqlx::query_as;
|
||||||
|
|
||||||
@@ -51,8 +51,8 @@ async fn get_item_cases(query: web::Query<DataUuid>, app_state: Data<AppState>)
|
|||||||
"SELECT * FROM items_cases WHERE \"item\" = $1",
|
"SELECT * FROM items_cases WHERE \"item\" = $1",
|
||||||
item.id
|
item.id
|
||||||
)
|
)
|
||||||
.fetch_all(&app_state.database)
|
.fetch_all(&app_state.database)
|
||||||
.await;
|
.await;
|
||||||
if items_cases.is_err() {
|
if items_cases.is_err() {
|
||||||
return HttpResponse::NotFound().finish();
|
return HttpResponse::NotFound().finish();
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
mod cases;
|
mod cases;
|
||||||
|
mod inventories;
|
||||||
mod items;
|
mod items;
|
||||||
mod types;
|
mod types;
|
||||||
mod users;
|
mod users;
|
||||||
@@ -10,7 +11,7 @@ use users::*;
|
|||||||
use utils::*;
|
use utils::*;
|
||||||
|
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{middleware::DefaultHeaders, App, HttpServer};
|
use actix_web::{App, HttpServer, middleware::DefaultHeaders};
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -32,10 +33,14 @@ async fn main() -> std::io::Result<()> {
|
|||||||
});
|
});
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(DefaultHeaders::new().add((
|
.wrap(
|
||||||
"Access-Control-Allow-Origin",
|
DefaultHeaders::new()
|
||||||
app_state.allow_origins.join(","),
|
.add((
|
||||||
)).add(("Access-Control-Allow-Credentials", "true")))
|
"Access-Control-Allow-Origin",
|
||||||
|
app_state.allow_origins.join(","),
|
||||||
|
))
|
||||||
|
.add(("Access-Control-Allow-Credentials", "true")),
|
||||||
|
)
|
||||||
.service(login)
|
.service(login)
|
||||||
.service(register)
|
.service(register)
|
||||||
.service(logout)
|
.service(logout)
|
||||||
@@ -48,7 +53,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.service(options)
|
.service(options)
|
||||||
.app_data(app_state.clone())
|
.app_data(app_state.clone())
|
||||||
})
|
})
|
||||||
.bind(("127.0.0.1", 8000))?
|
.bind(("127.0.0.1", 8000))?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{options, HttpResponse, Responder};
|
use actix_web::{HttpResponse, Responder, options};
|
||||||
|
|
||||||
// This is needed for the web client.
|
// This is needed for the web client.
|
||||||
// This returns the same options for every path of the api
|
// This returns the same options for every path of the api
|
||||||
@@ -12,7 +12,10 @@ async fn options(app_state: Data<AppState>) -> impl Responder {
|
|||||||
app_state.allow_origins.join(","),
|
app_state.allow_origins.join(","),
|
||||||
))
|
))
|
||||||
.append_header(("Access-Control-Allow-Methods", "GET, OPTIONS"))
|
.append_header(("Access-Control-Allow-Methods", "GET, OPTIONS"))
|
||||||
.append_header(("Access-Control-Allow-Headers", "Content-Type, Authorization"))
|
.append_header((
|
||||||
|
"Access-Control-Allow-Headers",
|
||||||
|
"Content-Type, Authorization",
|
||||||
|
))
|
||||||
.append_header(("Access-Control-Allow-Credentials", "true"))
|
.append_header(("Access-Control-Allow-Credentials", "true"))
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user