mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-07 02:07:48 +03:00
0.8.0
Реализованы все требуемые эндпоинты schedule. Улучшена документация.
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::routes::auth::shared::parse_vk_id;
|
||||
use crate::routes::auth::sign_in::schema::SignInData::{Default, Vk};
|
||||
use crate::routes::schema::user::UserResponse;
|
||||
use crate::routes::schema::{IntoResponseAsError, ResponseError};
|
||||
use crate::{AppState, utility};
|
||||
use crate::{utility, AppState};
|
||||
use actix_web::{post, web};
|
||||
use diesel::SaveChangesDsl;
|
||||
use std::ops::DerefMut;
|
||||
@@ -55,7 +55,7 @@ async fn sign_in(
|
||||
(status = NOT_ACCEPTABLE, body = ResponseError<ErrorCode>)
|
||||
))]
|
||||
#[post("/sign-in")]
|
||||
pub async fn sign_in_default(data: Json<Request>, app_state: web::Data<AppState>) -> Response {
|
||||
pub async fn sign_in_default(data: Json<Request>, app_state: web::Data<AppState>) -> ServiceResponse {
|
||||
sign_in(Default(data.into_inner()), &app_state).await.into()
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ pub async fn sign_in_default(data: Json<Request>, app_state: web::Data<AppState>
|
||||
(status = NOT_ACCEPTABLE, body = ResponseError<ErrorCode>)
|
||||
))]
|
||||
#[post("/sign-in-vk")]
|
||||
pub async fn sign_in_vk(data_json: Json<vk::Request>, app_state: web::Data<AppState>) -> Response {
|
||||
pub async fn sign_in_vk(data_json: Json<vk::Request>, app_state: web::Data<AppState>) -> ServiceResponse {
|
||||
let data = data_json.into_inner();
|
||||
|
||||
match parse_vk_id(&data.access_token) {
|
||||
@@ -74,51 +74,57 @@ pub async fn sign_in_vk(data_json: Json<vk::Request>, app_state: web::Data<AppSt
|
||||
}
|
||||
|
||||
mod schema {
|
||||
use crate::routes::schema::PartialStatusCode;
|
||||
use crate::routes::schema::user::UserResponse;
|
||||
use actix_macros::IntoResponseError;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_macros::{IntoResponseError, StatusCode};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||
#[derive(Deserialize, Serialize, ToSchema)]
|
||||
#[schema(as = SignIn::Request)]
|
||||
pub struct Request {
|
||||
/// Имя пользователя
|
||||
#[schema(examples("n08i40k"))]
|
||||
pub username: String,
|
||||
|
||||
/// Пароль
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
pub mod vk {
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
||||
#[derive(Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[schema(as = SignInVk::Request)]
|
||||
pub struct Request {
|
||||
/// Токен VK ID
|
||||
pub access_token: String,
|
||||
}
|
||||
}
|
||||
|
||||
pub type Response = crate::routes::schema::Response<UserResponse, ErrorCode>;
|
||||
pub type ServiceResponse = crate::routes::schema::Response<UserResponse, ErrorCode>;
|
||||
|
||||
#[derive(Serialize, utoipa::ToSchema, Clone, IntoResponseError)]
|
||||
#[derive(Serialize, ToSchema, Clone, IntoResponseError, StatusCode)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
#[schema(as = SignIn::ErrorCode)]
|
||||
#[status_code = "actix_web::http::StatusCode::NOT_ACCEPTABLE"]
|
||||
pub enum ErrorCode {
|
||||
/// Некорректное имя пользователя или пароль
|
||||
IncorrectCredentials,
|
||||
|
||||
/// Недействительный токен VK ID
|
||||
InvalidVkAccessToken,
|
||||
}
|
||||
|
||||
impl PartialStatusCode for ErrorCode {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
StatusCode::NOT_ACCEPTABLE
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal
|
||||
|
||||
/// Тип авторизации
|
||||
pub enum SignInData {
|
||||
/// Имя пользователя и пароль
|
||||
Default(Request),
|
||||
|
||||
/// Идентификатор привязанного аккаунта VK
|
||||
Vk(i32),
|
||||
}
|
||||
}
|
||||
@@ -136,7 +142,7 @@ mod tests {
|
||||
use actix_web::http::Method;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
use sha2::{Digest, Sha256};
|
||||
use sha1::{Digest, Sha1};
|
||||
use std::fmt::Write;
|
||||
|
||||
async fn sign_in_client(data: Request) -> ServiceResponse {
|
||||
@@ -152,7 +158,7 @@ mod tests {
|
||||
|
||||
fn prepare(username: String) {
|
||||
let id = {
|
||||
let mut sha = Sha256::new();
|
||||
let mut sha = Sha1::new();
|
||||
sha.update(&username);
|
||||
|
||||
let result = sha.finalize();
|
||||
|
||||
@@ -50,7 +50,10 @@ async fn sign_up(
|
||||
(status = NOT_ACCEPTABLE, body = ResponseError<ErrorCode>)
|
||||
))]
|
||||
#[post("/sign-up")]
|
||||
pub async fn sign_up_default(data_json: Json<Request>, app_state: web::Data<AppState>) -> Response {
|
||||
pub async fn sign_up_default(
|
||||
data_json: Json<Request>,
|
||||
app_state: web::Data<AppState>,
|
||||
) -> ServiceResponse {
|
||||
let data = data_json.into_inner();
|
||||
|
||||
sign_up(
|
||||
@@ -73,7 +76,10 @@ pub async fn sign_up_default(data_json: Json<Request>, app_state: web::Data<AppS
|
||||
(status = NOT_ACCEPTABLE, body = ResponseError<ErrorCode>)
|
||||
))]
|
||||
#[post("/sign-up-vk")]
|
||||
pub async fn sign_up_vk(data_json: Json<vk::Request>, app_state: web::Data<AppState>) -> Response {
|
||||
pub async fn sign_up_vk(
|
||||
data_json: Json<vk::Request>,
|
||||
app_state: web::Data<AppState>,
|
||||
) -> ServiceResponse {
|
||||
let data = data_json.into_inner();
|
||||
|
||||
match parse_vk_id(&data.access_token) {
|
||||
@@ -107,11 +113,9 @@ pub async fn sign_up_vk(data_json: Json<vk::Request>, app_state: web::Data<AppSt
|
||||
|
||||
mod schema {
|
||||
use crate::database::models::{User, UserRole};
|
||||
use crate::routes::schema::PartialStatusCode;
|
||||
use crate::routes::schema::user::UserResponse;
|
||||
use crate::utility;
|
||||
use actix_macros::{IntoResponseError, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use objectid::ObjectId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -120,16 +124,21 @@ mod schema {
|
||||
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
||||
#[schema(as = SignUp::Request)]
|
||||
pub struct Request {
|
||||
/// Имя пользователя
|
||||
#[schema(examples("n08i40k"))]
|
||||
pub username: String,
|
||||
|
||||
/// Пароль
|
||||
pub password: String,
|
||||
|
||||
/// Группа
|
||||
#[schema(examples("ИС-214/23"))]
|
||||
pub group: String,
|
||||
|
||||
/// Роль
|
||||
pub role: UserRole,
|
||||
|
||||
/// Версия установленного приложения Polytechnic+
|
||||
#[schema(examples("3.0.0"))]
|
||||
pub version: String,
|
||||
}
|
||||
@@ -142,43 +151,71 @@ mod schema {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[schema(as = SignUpVk::Request)]
|
||||
pub struct Request {
|
||||
/// Токен VK ID
|
||||
pub access_token: String,
|
||||
|
||||
/// Имя пользователя
|
||||
#[schema(examples("n08i40k"))]
|
||||
pub username: String,
|
||||
|
||||
/// Группа
|
||||
#[schema(examples("ИС-214/23"))]
|
||||
pub group: String,
|
||||
|
||||
/// Роль
|
||||
pub role: UserRole,
|
||||
|
||||
/// Версия установленного приложения Polytechnic+
|
||||
#[schema(examples("3.0.0"))]
|
||||
pub version: String,
|
||||
}
|
||||
}
|
||||
|
||||
pub type Response = crate::routes::schema::Response<UserResponse, ErrorCode>;
|
||||
pub type ServiceResponse = crate::routes::schema::Response<UserResponse, ErrorCode>;
|
||||
|
||||
#[derive(Clone, Serialize, utoipa::ToSchema, IntoResponseError, StatusCode)]
|
||||
#[status_code = "StatusCode::NOT_ACCEPTABLE"]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
#[schema(as = SignUp::ErrorCode)]
|
||||
#[status_code = "actix_web::http::StatusCode::NOT_ACCEPTABLE"]
|
||||
pub enum ErrorCode {
|
||||
/// Передана роль ADMIN
|
||||
DisallowedRole,
|
||||
|
||||
/// Неизвестное название группы
|
||||
InvalidGroupName,
|
||||
|
||||
/// Пользователь с таким именем уже зарегистрирован
|
||||
UsernameAlreadyExists,
|
||||
|
||||
/// Недействительный токен VK ID
|
||||
InvalidVkAccessToken,
|
||||
|
||||
/// Пользователь с таким аккаунтом VK уже зарегистрирован
|
||||
VkAlreadyExists,
|
||||
}
|
||||
|
||||
/// Internal
|
||||
|
||||
/// Данные для регистрации
|
||||
pub struct SignUpData {
|
||||
/// Имя пользователя
|
||||
pub username: String,
|
||||
|
||||
/// Пароль
|
||||
///
|
||||
/// Должен присутствовать даже если регистрация происходит с помощью токена VK ID
|
||||
pub password: String,
|
||||
|
||||
/// Идентификатор аккаунта VK
|
||||
pub vk_id: Option<i32>,
|
||||
|
||||
/// Группа
|
||||
pub group: String,
|
||||
|
||||
/// Роль
|
||||
pub role: UserRole,
|
||||
|
||||
/// Версия установленного приложения Polytechnic+
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user