mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 17:57:47 +03:00
0.4.0
Авторизация через токен вк Слияние schedule_parser с проектом Перенос схемы запросов/ответов в файлы эндпоинтов Переход с библиотеки jwt на jsonwebtokens
This commit is contained in:
@@ -2,13 +2,13 @@ pub mod users {
|
||||
use crate::database::models::User;
|
||||
use crate::database::schema::users::dsl::users;
|
||||
use crate::database::schema::users::dsl::*;
|
||||
use diesel::{insert_into, ExpressionMethods, QueryResult};
|
||||
use diesel::{ExpressionMethods, QueryResult, insert_into};
|
||||
use diesel::{PgConnection, SelectableHelper};
|
||||
use diesel::{QueryDsl, RunQueryDsl};
|
||||
use std::ops::DerefMut;
|
||||
use std::sync::Mutex;
|
||||
|
||||
pub fn get(connection: &Mutex<PgConnection>, _id: String) -> QueryResult<User> {
|
||||
pub fn get(connection: &Mutex<PgConnection>, _id: &String) -> QueryResult<User> {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
|
||||
@@ -20,7 +20,7 @@ pub mod users {
|
||||
|
||||
pub fn get_by_username(
|
||||
connection: &Mutex<PgConnection>,
|
||||
_username: String,
|
||||
_username: &String,
|
||||
) -> QueryResult<User> {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
@@ -30,8 +30,21 @@ pub mod users {
|
||||
.select(User::as_select())
|
||||
.first(con)
|
||||
}
|
||||
|
||||
pub fn get_by_vk_id(
|
||||
connection: &Mutex<PgConnection>,
|
||||
_vk_id: i32,
|
||||
) -> QueryResult<User> {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
|
||||
pub fn contains_by_username(connection: &Mutex<PgConnection>, _username: String) -> bool {
|
||||
users
|
||||
.filter(vk_id.eq(_vk_id))
|
||||
.select(User::as_select())
|
||||
.first(con)
|
||||
}
|
||||
|
||||
pub fn contains_by_username(connection: &Mutex<PgConnection>, _username: &String) -> bool {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
|
||||
@@ -45,7 +58,21 @@ pub mod users {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_by_username(connection: &Mutex<PgConnection>, _username: String) -> bool {
|
||||
pub fn contains_by_vk_id(connection: &Mutex<PgConnection>, _vk_id: i32) -> bool {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
|
||||
match users
|
||||
.filter(vk_id.eq(_vk_id))
|
||||
.count()
|
||||
.get_result::<i64>(con)
|
||||
{
|
||||
Ok(count) => count > 0,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete_by_username(connection: &Mutex<PgConnection>, _username: &String) -> bool {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
|
||||
@@ -61,11 +88,14 @@ pub mod users {
|
||||
|
||||
insert_into(users).values(user).execute(con)
|
||||
}
|
||||
|
||||
|
||||
pub fn insert_or_ignore(connection: &Mutex<PgConnection>, user: &User) -> QueryResult<usize> {
|
||||
let mut lock = connection.lock().unwrap();
|
||||
let con = lock.deref_mut();
|
||||
|
||||
insert_into(users).values(user).on_conflict_do_nothing().execute(con)
|
||||
insert_into(users)
|
||||
.values(user)
|
||||
.on_conflict_do_nothing()
|
||||
.execute(con)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,4 @@ pub struct User {
|
||||
pub group: String,
|
||||
pub role: UserRole,
|
||||
pub version: String,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user