mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 09:47:50 +03:00
0.7.0
Добавлена OpenAPI документация эндпоинтов и структур с интерфейсом RapiDoc. Добавлены derive макросы для преобразования структуры в HttpResponse с помощью ResponderJson и IResponse<T> с помощью IntoIResponse. Ревью кода эндпоинтов связанных с авторизацией. Эндпоинт users/me теперь объект пользователя в требуемом виде.
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -3,8 +3,10 @@ use crate::middlewares::authorization::Authorization;
|
||||
use crate::routes::auth::sign_in::{sign_in_default, sign_in_vk};
|
||||
use crate::routes::auth::sign_up::{sign_up_default, sign_up_vk};
|
||||
use crate::routes::users::me::me;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use actix_web::{App, HttpServer};
|
||||
use dotenvy::dotenv;
|
||||
use utoipa_actix_web::AppExt;
|
||||
use utoipa_rapidoc::RapiDoc;
|
||||
|
||||
mod app_state;
|
||||
|
||||
@@ -29,23 +31,37 @@ async fn main() {
|
||||
env_logger::init();
|
||||
|
||||
HttpServer::new(move || {
|
||||
let auth_scope = web::scope("/auth")
|
||||
let auth_scope = utoipa_actix_web::scope("/auth")
|
||||
.service(sign_in_default)
|
||||
.service(sign_in_vk)
|
||||
.service(sign_up_default)
|
||||
.service(sign_up_vk);
|
||||
|
||||
let users_scope = web::scope("/users")
|
||||
let users_scope = utoipa_actix_web::scope("/users")
|
||||
.wrap(Authorization)
|
||||
.service(me);
|
||||
|
||||
let api_scope = web::scope("/api/v1")
|
||||
let api_scope = utoipa_actix_web::scope("/api/v1")
|
||||
.service(auth_scope)
|
||||
.service(users_scope);
|
||||
|
||||
App::new().app_data(app_state()).service(api_scope)
|
||||
let (app, api) = App::new()
|
||||
.into_utoipa_app()
|
||||
.app_data(app_state())
|
||||
.service(api_scope)
|
||||
.split_for_parts();
|
||||
|
||||
let rapidoc_service = RapiDoc::with_openapi("/api-docs-json", api).path("/api-docs");
|
||||
|
||||
// Because CORS error on non-localhost
|
||||
let patched_rapidoc_html = rapidoc_service.to_html().replace(
|
||||
"https://unpkg.com/rapidoc/dist/rapidoc-min.js",
|
||||
"https://cdn.jsdelivr.net/npm/rapidoc/dist/rapidoc-min.min.js",
|
||||
);
|
||||
|
||||
app.service(rapidoc_service.custom_html(patched_rapidoc_html))
|
||||
})
|
||||
.bind(("127.0.0.1", 8080))
|
||||
.bind(("0.0.0.0", 8080))
|
||||
.unwrap()
|
||||
.run()
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user