mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 17:57:47 +03:00
Compare commits
5 Commits
e02cc4bca7
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0762a1f907 | ||
|
2442641479
|
|||
|
ac16c96e5e
|
|||
|
622464e4c3
|
|||
|
39c60ef939
|
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -140,3 +140,6 @@ jobs:
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
"BINARY_NAME=${{ env.BINARY_NAME }}"
|
||||
|
||||
- name: Deploy
|
||||
run: curl ${{ secrets.DEPLOY_URL }}
|
||||
|
||||
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1884,9 +1884,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "hex-literal"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcaaec4551594c969335c98c903c1397853d4198408ea609190f420500f6be71"
|
||||
checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1"
|
||||
|
||||
[[package]]
|
||||
name = "hkdf"
|
||||
|
||||
@@ -103,6 +103,9 @@ pub enum LessonType {
|
||||
|
||||
/// Практическое занятие.
|
||||
Practice,
|
||||
|
||||
/// Дифференцированный зачёт.
|
||||
DifferentiatedExam,
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, Debug, Serialize, Deserialize, ToSchema)]
|
||||
|
||||
@@ -187,6 +187,7 @@ fn guess_lesson_type(text: &str) -> Option<LessonType> {
|
||||
("курсовой проект", LessonType::CourseProject),
|
||||
("защита курсового проекта", LessonType::CourseProjectDefense),
|
||||
("практическое занятие", LessonType::Practice),
|
||||
("дифференцированный зачет", LessonType::DifferentiatedExam),
|
||||
])
|
||||
});
|
||||
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@@ -50,7 +50,22 @@ pub fn get_api_scope<
|
||||
.service(routes::auth::sign_up_vk);
|
||||
|
||||
let users_scope = utoipa_actix_web::scope("/users")
|
||||
.wrap(JWTAuthorizationBuilder::new().build())
|
||||
.wrap(
|
||||
JWTAuthorizationBuilder::new()
|
||||
.add_paths(
|
||||
["/by/id/{id}", "/by/telegram-id/{id}"],
|
||||
Some(ServiceConfig {
|
||||
allow_service: true,
|
||||
user_roles: Some(&[UserRole::Admin]),
|
||||
}),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.service(
|
||||
utoipa_actix_web::scope("/by")
|
||||
.service(routes::users::by::by_id)
|
||||
.service(routes::users::by::by_telegram_id),
|
||||
)
|
||||
.service(routes::users::change_group)
|
||||
.service(routes::users::change_username)
|
||||
.service(routes::users::me);
|
||||
|
||||
@@ -5,13 +5,13 @@ use actix_web::body::{BoxBody, EitherBody};
|
||||
use actix_web::dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform};
|
||||
use actix_web::{web, Error, HttpRequest, ResponseError};
|
||||
use database::entity::sea_orm_active_enums::UserRole;
|
||||
use database::entity::UserType;
|
||||
use database::query::Query;
|
||||
use futures_util::future::LocalBoxFuture;
|
||||
use std::future::{ready, Ready};
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use database::entity::UserType;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct ServiceConfig {
|
||||
@@ -42,7 +42,11 @@ impl JWTAuthorizationBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_paths(mut self, paths: impl AsRef<[&'static str]>, config: Option<ServiceConfig>) -> Self {
|
||||
pub fn add_paths(
|
||||
mut self,
|
||||
paths: impl AsRef<[&'static str]>,
|
||||
config: Option<ServiceConfig>,
|
||||
) -> Self {
|
||||
self.path_configs.push((Arc::from(paths.as_ref()), config));
|
||||
self
|
||||
}
|
||||
@@ -176,11 +180,20 @@ where
|
||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||
let service = Rc::clone(&self.service);
|
||||
|
||||
let Some(config) = Self::find_config(
|
||||
req.match_info().unprocessed(),
|
||||
&self.path_configs,
|
||||
&self.default_config,
|
||||
) else {
|
||||
let match_info = req.match_info();
|
||||
let path = if let Some(pattern) = req.match_pattern() {
|
||||
let scope_start_idx = match_info
|
||||
.as_str()
|
||||
.find(match_info.unprocessed())
|
||||
.unwrap_or(0);
|
||||
|
||||
pattern.as_str().split_at(scope_start_idx).1.to_owned()
|
||||
} else {
|
||||
match_info.unprocessed().to_owned()
|
||||
};
|
||||
|
||||
let Some(config) = Self::find_config(&path, &self.path_configs, &self.default_config)
|
||||
else {
|
||||
let fut = self.service.call(req);
|
||||
return Box::pin(async move { Ok(fut.await?.map_into_left_body()) });
|
||||
};
|
||||
|
||||
@@ -163,6 +163,7 @@ pub mod user {
|
||||
#[schema(examples(
|
||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjY3ZGNjOWE5NTA3YjAwMDA3NzI3NDRhMiIsImlhdCI6IjE3NDMxMDgwOTkiLCJleHAiOiIxODY5MjUyMDk5In0.rMgXRb3JbT9AvLK4eiY9HMB5LxgUudkpQyoWKOypZFY"
|
||||
))]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub access_token: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
56
src/routes/users/by.rs
Normal file
56
src/routes/users/by.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use crate::routes::schema::user::UserResponse;
|
||||
use crate::routes::users::by::schema::{ErrorCode, ServiceResponse};
|
||||
use crate::state::AppState;
|
||||
use actix_web::{get, web};
|
||||
use database::query::Query;
|
||||
|
||||
#[utoipa::path(responses((status = OK, body = UserResponse)))]
|
||||
#[get("/id/{id}")]
|
||||
pub async fn by_id(app_state: web::Data<AppState>, path: web::Path<String>) -> ServiceResponse {
|
||||
let user_id = path.into_inner();
|
||||
|
||||
let db = app_state.get_database();
|
||||
|
||||
match Query::find_user_by_id(db, &user_id).await {
|
||||
Ok(Some(user)) => Ok(UserResponse::from(user)),
|
||||
_ => Err(ErrorCode::NotFound),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
#[utoipa::path(responses((status = OK, body = UserResponse)))]
|
||||
#[get("/telegram-id/{id}")]
|
||||
pub async fn by_telegram_id(
|
||||
app_state: web::Data<AppState>,
|
||||
path: web::Path<i64>,
|
||||
) -> ServiceResponse {
|
||||
let telegram_id = path.into_inner();
|
||||
|
||||
let db = app_state.get_database();
|
||||
|
||||
match Query::find_user_by_telegram_id(db, telegram_id).await {
|
||||
Ok(Some(user)) => Ok(UserResponse::from(user)),
|
||||
_ => Err(ErrorCode::NotFound),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
mod schema {
|
||||
use crate::routes::schema::user::UserResponse;
|
||||
use actix_macros::ErrResponse;
|
||||
use derive_more::Display;
|
||||
use serde::Serialize;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
pub type ServiceResponse = crate::routes::schema::Response<UserResponse, ErrorCode>;
|
||||
|
||||
#[derive(Clone, Serialize, Display, ToSchema, ErrResponse)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
#[schema(as = Users::By::ErrorCode)]
|
||||
pub enum ErrorCode {
|
||||
/// User not found.
|
||||
#[status_code = "actix_web::http::StatusCode::NOT_FOUND"]
|
||||
#[display("Required user not found.")]
|
||||
NotFound,
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod by;
|
||||
mod change_group;
|
||||
mod change_username;
|
||||
mod me;
|
||||
|
||||
Reference in New Issue
Block a user