Game & Group Put + Delete Endpoints
This commit is contained in:
parent
8fd4321944
commit
eb18526f51
3 changed files with 442 additions and 119 deletions
src
44
src/main.rs
44
src/main.rs
|
@ -12,7 +12,7 @@ use chrono::Local;
|
|||
use actix_web::{middleware::Logger, web, App, HttpServer, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{PgPool, Pool, Postgres, Connection};
|
||||
use utoipa::OpenApi;
|
||||
use utoipa::{OpenApi, openapi::security::{SecurityScheme, ApiKey, ApiKeyValue}, Modify};
|
||||
use utoipa_swagger_ui::{Config, SwaggerUi, Url};
|
||||
|
||||
mod db;
|
||||
|
@ -97,6 +97,18 @@ async fn main() -> Result<()> {
|
|||
|
||||
println!("DATABASE_URL: {}", env::var("DATABASE_URL").unwrap()); // DBEUG
|
||||
|
||||
struct ApiSecurity;
|
||||
|
||||
impl Modify for ApiSecurity {
|
||||
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
|
||||
let components = openapi.components.as_mut().unwrap(); // we can unwrap safely since there already is components registered.
|
||||
components.add_security_scheme(
|
||||
"api_key",
|
||||
SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new("x-api-key"))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(OpenApi)]
|
||||
#[openapi(
|
||||
paths(
|
||||
|
@ -128,25 +140,35 @@ async fn main() -> Result<()> {
|
|||
v3::list_games,
|
||||
v3::get_game_data,
|
||||
v3::create_game,
|
||||
v3::delete_game
|
||||
v3::edit_game,
|
||||
v3::delete_game,
|
||||
v3::create_group,
|
||||
v3::edit_group,
|
||||
v3::delete_group
|
||||
),
|
||||
components(schemas(
|
||||
v3::schemas::AuthParamsOptional,
|
||||
v3::schemas::AuthParams,
|
||||
v3::schemas::AuthReturn,
|
||||
v3::schemas::GetGameParam,
|
||||
v3::schemas::PostGameParams,
|
||||
v3::schemas::UpdateGameParams,
|
||||
v3::schemas::DeleteGameParam,
|
||||
v3::schemas::PostGroupParams,
|
||||
v3::schemas::UpdateGroupParams,
|
||||
v3::schemas::DeleteGroupParams,
|
||||
v3::schemas::FullViewData,
|
||||
v3::schemas::Ethic,
|
||||
v3::schemas::EmpireEthic,
|
||||
v3::schemas::ChellarisGameLegacy,
|
||||
v3::schemas::ChellarisGameFlat,
|
||||
v3::schemas::ChellarisGame,
|
||||
v3::schemas::ChellarisGameLite,
|
||||
v3::schemas::Species,
|
||||
v3::schemas::ChellarisGameGroup,
|
||||
v3::schemas::ChellarisGameGroupLegacy,
|
||||
v3::schemas::ChellarisGroupFlat,
|
||||
v3::schemas::Portrait,
|
||||
v3::schemas::ChellarisEmpire
|
||||
))
|
||||
v3::schemas::ChellarisEmpire,
|
||||
v3::schemas::ChellarisEmpireFlat
|
||||
)),
|
||||
modifiers(&ApiSecurity)
|
||||
)]
|
||||
struct ApiDocV3;
|
||||
|
||||
|
@ -188,7 +210,11 @@ async fn main() -> Result<()> {
|
|||
.service(v3::list_games)
|
||||
.service(v3::get_game_data)
|
||||
.service(v3::create_game)
|
||||
.service(v3::edit_game)
|
||||
.service(v3::delete_game)
|
||||
.service(v3::create_group)
|
||||
.service(v3::edit_group)
|
||||
.service(v3::delete_group)
|
||||
// Swagger UI
|
||||
.service(
|
||||
SwaggerUi::new(concat!(api_base!(), "/swagger/{_:.*}"))
|
||||
|
@ -226,7 +252,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
while is_alive.load(Ordering::Relaxed) {
|
||||
let thread = tokio::spawn(async {
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
sleep(Duration::from_millis(100));
|
||||
});
|
||||
|
||||
let _ = thread.await;
|
||||
|
|
Reference in a new issue