Compare commits
No commits in common. "66704b4e2e805c5d4fcfee9f569532ffa3ceecdd" and "111bcedf2c84125a9829b1aa46b42292652f591c" have entirely different histories.
66704b4e2e
...
111bcedf2c
|
@ -1,2 +1 @@
|
||||||
[env]
|
DATABASE_URL="postgres://postgres:postgres@127.0.0.1:5432/persmgr""
|
||||||
DATABASE_URL="postgres://postgres:postgres@127.0.0.1:5432/persmgr"
|
|
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -153,7 +153,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5"
|
checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum-core",
|
"axum-core",
|
||||||
"axum-macros",
|
|
||||||
"bytes",
|
"bytes",
|
||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
@ -201,17 +200,6 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "axum-macros"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
version = "0.3.75"
|
version = "0.3.75"
|
||||||
|
@ -1283,7 +1271,6 @@ dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"axum",
|
"axum",
|
||||||
"base64",
|
"base64",
|
||||||
"cfg-if",
|
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -7,9 +7,8 @@ edition = "2024"
|
||||||
anyhow = "1.0.99"
|
anyhow = "1.0.99"
|
||||||
argon2 = { version = "0.5.3", features = ["simple", "std"] }
|
argon2 = { version = "0.5.3", features = ["simple", "std"] }
|
||||||
askama = "0.14.0"
|
askama = "0.14.0"
|
||||||
axum = { version = "0.8.4", features = ["macros"] }
|
axum = "0.8.4"
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
cfg-if = "1.0.3"
|
|
||||||
pulldown-cmark = "0.13.0"
|
pulldown-cmark = "0.13.0"
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
|
|
@ -7,7 +7,6 @@ CREATE TABLE IF NOT EXISTS users (
|
||||||
username TEXT NOT NULL UNIQUE,
|
username TEXT NOT NULL UNIQUE,
|
||||||
pw_hash TEXT NOT NULL,
|
pw_hash TEXT NOT NULL,
|
||||||
pw_salt TEXT NOT NULL,
|
pw_salt TEXT NOT NULL,
|
||||||
pfp_id BIGINT NOT NULL,
|
pfp_id BIGINT NOT NULL
|
||||||
rank_id BIGINT NOT NULL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,5 @@
|
||||||
CREATE TABLE IF NOT EXISTS sessions (
|
CREATE TABLE IF NOT EXISTS sessions (
|
||||||
user_id BIGINT NOT NULL,
|
user_id BIGINT NOT NULL,
|
||||||
session_key TEXT NOT NULL UNIQUE,
|
session_key TEXT NOT NULL UNIQUE,
|
||||||
expires BIGINT NOT NULL,
|
expires BIGINT NOT NULL
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS ranks;
|
|
|
@ -1,7 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS ranks (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
description TEXT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
modified_at BIGINT NOT NULL
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS awards;
|
|
|
@ -1,7 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS awards (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
description TEXT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
modified_at BIGINT NOT NULL
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS trainings;
|
|
|
@ -1,7 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS trainings (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
description TEXT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
modified_at BIGINT NOT NULL
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS missions;
|
|
|
@ -1,9 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS missions (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
description TEXT NOT NULL,
|
|
||||||
starting_at BIGINT NOT NULL,
|
|
||||||
estimated_length BIGINT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
modified_at BIGINT NOT NULL
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS qualifications;
|
|
|
@ -1,7 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS qualifications (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
description TEXT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
modified_at BIGINT NOT NULL
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS record_ranks;
|
|
|
@ -1,11 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS records_ranks (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
rank_id BIGINT NOT NULL,
|
|
||||||
author_id BIGINT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
||||||
CONSTRAINT fk_rank FOREIGN KEY (rank_id) REFERENCES ranks(id) ON DELETE CASCADE
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS record_awards;
|
|
|
@ -1,11 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS records_awards (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
award_id BIGINT NOT NULL,
|
|
||||||
author_id BIGINT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
||||||
CONSTRAINT fk_award FOREIGN KEY (award_id) REFERENCES awards(id) ON DELETE CASCADE
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS record_training;
|
|
|
@ -1,11 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS records_trainings (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
training_id BIGINT NOT NULL,
|
|
||||||
author_id BIGINT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
||||||
CONSTRAINT fk_training FOREIGN KEY (training_id) REFERENCES trainings(id) ON DELETE CASCADE
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS record_qualifications;
|
|
|
@ -1,11 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS records_qualifications (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
qualification_id BIGINT NOT NULL,
|
|
||||||
author_id BIGINT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
||||||
CONSTRAINT fk_qualification FOREIGN KEY (qualification_id) REFERENCES qualifications(id) ON DELETE CASCADE
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS records_missions;
|
|
|
@ -1,11 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS records_missions (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
mission_id BIGINT NOT NULL,
|
|
||||||
author_id BIGINT NOT NULL,
|
|
||||||
created_at BIGINT NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
||||||
CONSTRAINT fk_mission FOREIGN KEY (mission_id) REFERENCES missions(id) ON DELETE CASCADE
|
|
||||||
);
|
|
|
@ -1 +0,0 @@
|
||||||
DROP TABLE IF EXISTS attendance;
|
|
|
@ -1,10 +0,0 @@
|
||||||
CREATE TABLE IF NOT EXISTS attendance (
|
|
||||||
id BIGSERIAL PRIMARY KEY NOT NULL,
|
|
||||||
user_id BIGINT NOT NULL,
|
|
||||||
mission_id BIGINT NOT NULL,
|
|
||||||
confirmed_at BIGINT NOT NULL,
|
|
||||||
attending BOOL NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL,
|
|
||||||
CONSTRAINT fk_mission FOREIGN KEY (mission_id) REFERENCES missions(id) ON DELETE CASCADE
|
|
||||||
);
|
|
|
@ -1,29 +0,0 @@
|
||||||
use axum::{
|
|
||||||
body::{Body, Bytes},
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{HeaderMap, HeaderValue, StatusCode},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use crate::db::Database;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Data {
|
|
||||||
path: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[axum::debug_handler]
|
|
||||||
pub async fn route(State(db): State<Database>) -> impl IntoResponse {
|
|
||||||
if false {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
use axum::{
|
|
||||||
body::{Body, Bytes},
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{HeaderMap, HeaderValue, StatusCode},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use crate::db::Database;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Data {
|
|
||||||
id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[axum::debug_handler]
|
|
||||||
pub async fn route(State(db): State<Database>) -> impl IntoResponse {
|
|
||||||
if false {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
use axum::{
|
|
||||||
body::{Body, Bytes},
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{HeaderMap, HeaderValue, StatusCode},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use crate::db::Database;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Data {
|
|
||||||
id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[axum::debug_handler]
|
|
||||||
pub async fn route(State(db): State<Database>) -> impl IntoResponse {
|
|
||||||
if false {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
use axum::{
|
|
||||||
body::{Body, Bytes},
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{HeaderMap, HeaderValue, StatusCode},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use crate::db::Database;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Data {
|
|
||||||
id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[axum::debug_handler]
|
|
||||||
pub async fn route(State(db): State<Database>) -> impl IntoResponse {
|
|
||||||
if false {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
use axum::{
|
|
||||||
Router,
|
|
||||||
routing::{get, post},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::db::Database;
|
|
||||||
|
|
||||||
mod create;
|
|
||||||
mod delete;
|
|
||||||
mod get_file;
|
|
||||||
mod mkdir;
|
|
||||||
mod rmdir;
|
|
||||||
|
|
||||||
pub fn register_routes() -> Router<Database> {
|
|
||||||
Router::new()
|
|
||||||
.route("/file/upload", post(create::route))
|
|
||||||
.route("/file/get", get(get_file::route))
|
|
||||||
.route("/file/delete", get(delete::route))
|
|
||||||
.route("/dir/create", get(mkdir::route))
|
|
||||||
.route("/dir/remove", get(rmdir::route))
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
use axum::{
|
|
||||||
body::{Body, Bytes},
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{HeaderMap, HeaderValue, StatusCode},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
use crate::db::Database;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Data {
|
|
||||||
id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[axum::debug_handler]
|
|
||||||
pub async fn route(State(db): State<Database>) -> impl IntoResponse {
|
|
||||||
if false {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.body(String::new())
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::db::Database;
|
use crate::db::Database;
|
||||||
use axum::{Router, extract::State, http::StatusCode, routing::get};
|
use axum::{Router, extract::State, http::StatusCode, routing::get};
|
||||||
|
|
||||||
pub mod files;
|
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
async fn root(State(state): State<Database>) -> (StatusCode, &'static str) {
|
async fn root(State(state): State<Database>) -> (StatusCode, &'static str) {
|
||||||
|
@ -11,8 +10,7 @@ async fn root(State(state): State<Database>) -> (StatusCode, &'static str) {
|
||||||
pub fn register_routes() -> Router<Database> {
|
pub fn register_routes() -> Router<Database> {
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
.route("/", get(root))
|
.route("/", get(root))
|
||||||
.nest("/user", user::register_routes())
|
.nest("/user", user::register_routes());
|
||||||
.nest("/files", files::register_routes());
|
|
||||||
|
|
||||||
Router::new().nest("/api", router)
|
Router::new().nest("/api", router)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,7 @@ pub mod login;
|
||||||
pub mod register;
|
pub mod register;
|
||||||
|
|
||||||
pub fn register_routes() -> Router<Database> {
|
pub fn register_routes() -> Router<Database> {
|
||||||
let sub_methods = Router::new();
|
|
||||||
// .route("/awards", method_router);
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/register", post(register::route))
|
.route("/register", post(register::route))
|
||||||
.route("/login", post(login::route))
|
.route("/login", post(login::route))
|
||||||
.nest("/{id}", sub_methods)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ use sqlx::{Pool, Postgres, postgres::PgPoolOptions};
|
||||||
|
|
||||||
pub mod tables;
|
pub mod tables;
|
||||||
|
|
||||||
pub type CurrDb = Postgres;
|
pub type CurrPool = Pool<Postgres>;
|
||||||
pub type CurrPool = Pool<CurrDb>;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct Award {
|
|
||||||
pub id: i64,
|
|
||||||
pub name: String,
|
|
||||||
pub description: String,
|
|
||||||
pub created_at: i64,
|
|
||||||
pub modified_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for Award {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "awards";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Award {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Award,
|
|
||||||
r#"
|
|
||||||
INSERT INTO awards (name, description, created_at, modified_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
self.created_at,
|
|
||||||
self.modified_at
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(Award, "SELECT * FROM awards WHERE id = $1", id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
|
|
||||||
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Award,
|
|
||||||
r#"
|
|
||||||
UPDATE awards SET
|
|
||||||
name = $2,
|
|
||||||
description = $3,
|
|
||||||
modified_at = $4
|
|
||||||
WHERE id = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.id,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
curr_time
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct Mission {
|
|
||||||
pub id: i64,
|
|
||||||
pub name: String,
|
|
||||||
pub description: String,
|
|
||||||
pub starting_at: i64,
|
|
||||||
pub estimated_length: i64,
|
|
||||||
pub created_at: i64,
|
|
||||||
pub modified_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for Mission {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "missions";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mission {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Mission,
|
|
||||||
r#"
|
|
||||||
INSERT INTO missions (name, description, created_at, modified_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
self.created_at,
|
|
||||||
self.modified_at
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(Mission, "SELECT * FROM missions WHERE id = $1", id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
|
|
||||||
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Mission,
|
|
||||||
r#"
|
|
||||||
UPDATE missions SET
|
|
||||||
name = $2,
|
|
||||||
description = $3,
|
|
||||||
modified_at = $4
|
|
||||||
WHERE id = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.id,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
curr_time
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
pub mod awards;
|
|
||||||
pub mod missions;
|
|
||||||
pub mod qualifications;
|
|
||||||
pub mod ranks;
|
|
||||||
pub mod trainings;
|
|
|
@ -1,70 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct Qualification {
|
|
||||||
pub id: i64,
|
|
||||||
pub name: String,
|
|
||||||
pub description: String,
|
|
||||||
pub created_at: i64,
|
|
||||||
pub modified_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for Qualification {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "qualifications";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Qualification {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Qualification,
|
|
||||||
r#"
|
|
||||||
INSERT INTO qualifications (name, description, created_at, modified_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
self.created_at,
|
|
||||||
self.modified_at
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Qualification,
|
|
||||||
"SELECT * FROM qualifications WHERE id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
|
|
||||||
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Qualification,
|
|
||||||
r#"
|
|
||||||
UPDATE qualifications SET
|
|
||||||
name = $2,
|
|
||||||
description = $3,
|
|
||||||
modified_at = $4
|
|
||||||
WHERE id = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.id,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
curr_time
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct Rank {
|
|
||||||
pub id: i64,
|
|
||||||
pub name: String,
|
|
||||||
pub description: String,
|
|
||||||
pub created_at: i64,
|
|
||||||
pub modified_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for Rank {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "ranks";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Rank {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Rank,
|
|
||||||
r#"
|
|
||||||
INSERT INTO ranks (name, description, created_at, modified_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
self.created_at,
|
|
||||||
self.modified_at
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(Rank, "SELECT * FROM ranks WHERE id = $1", id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
|
|
||||||
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Rank,
|
|
||||||
r#"
|
|
||||||
UPDATE ranks SET
|
|
||||||
name = $2,
|
|
||||||
description = $3,
|
|
||||||
modified_at = $4
|
|
||||||
WHERE id = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.id,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
curr_time
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct Training {
|
|
||||||
pub id: i64,
|
|
||||||
pub name: String,
|
|
||||||
pub description: String,
|
|
||||||
pub created_at: i64,
|
|
||||||
pub modified_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for Training {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "trainings";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Training {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Training,
|
|
||||||
r#"
|
|
||||||
INSERT INTO trainings (name, description, created_at, modified_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
self.created_at,
|
|
||||||
self.modified_at
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(Training, "SELECT * FROM trainings WHERE id = $1", id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn update(&self, pool: &CurrPool) -> anyhow::Result<Self> {
|
|
||||||
let curr_time = time::OffsetDateTime::now_utc().unix_timestamp();
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
Training,
|
|
||||||
r#"
|
|
||||||
UPDATE trainings SET
|
|
||||||
name = $2,
|
|
||||||
description = $3,
|
|
||||||
modified_at = $4
|
|
||||||
WHERE id = $1
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
self.id,
|
|
||||||
self.name,
|
|
||||||
self.description,
|
|
||||||
curr_time
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +1,2 @@
|
||||||
use std::{
|
|
||||||
error::Error,
|
|
||||||
marker::PhantomData,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
};
|
|
||||||
|
|
||||||
use sqlx::{Decode, Encode, QueryBuilder, Type, postgres::PgRow};
|
|
||||||
|
|
||||||
pub mod assignables;
|
|
||||||
pub mod attendance;
|
|
||||||
pub mod records;
|
|
||||||
pub mod sessions;
|
pub mod sessions;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
pub trait TableMeta<'a>: for<'r> sqlx::FromRow<'r, PgRow> {
|
|
||||||
type PrimaryKey: Encode<'a, super::CurrDb> + Type<super::CurrDb> + Clone;
|
|
||||||
const TABLE: &'static str;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct ForeignKey<'a, FK: TableMeta<'a>> {
|
|
||||||
id: FK::PrimaryKey,
|
|
||||||
_ft: PhantomData<FK>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, FK: TableMeta<'a> + Send + for<'r> sqlx::FromRow<'r, PgRow> + Unpin + 'a>
|
|
||||||
ForeignKey<'a, FK>
|
|
||||||
{
|
|
||||||
pub async fn extract(&self, db: &super::CurrPool) -> anyhow::Result<FK> {
|
|
||||||
let id = self.id.clone();
|
|
||||||
|
|
||||||
let res = QueryBuilder::new("")
|
|
||||||
.push(format!("SELECT * FROM {} WHERE id = ", FK::TABLE))
|
|
||||||
.push_bind(id)
|
|
||||||
.build_query_as::<FK>()
|
|
||||||
.fetch_one(db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, TM: TableMeta<'a>> Type<super::CurrDb> for ForeignKey<'a, TM> {
|
|
||||||
fn type_info() -> <super::CurrDb as sqlx::Database>::TypeInfo {
|
|
||||||
TM::PrimaryKey::type_info()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, TM: TableMeta<'a>> Decode<'a, super::CurrDb> for ForeignKey<'a, TM>
|
|
||||||
where
|
|
||||||
&'a str: Decode<'a, super::CurrDb>,
|
|
||||||
<TM as TableMeta<'a>>::PrimaryKey: sqlx::Decode<'a, super::CurrDb>,
|
|
||||||
{
|
|
||||||
fn decode(
|
|
||||||
value: <super::CurrDb as sqlx::Database>::ValueRef<'a>,
|
|
||||||
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>> {
|
|
||||||
<TM::PrimaryKey as Decode<super::CurrDb>>::decode(value);
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, TM: TableMeta<'a>> Deref for ForeignKey<'a, TM> {
|
|
||||||
type Target = TM::PrimaryKey;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, TM: TableMeta<'a>> DerefMut for ForeignKey<'a, TM> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, FK: TableMeta<'a, PrimaryKey = i64>> From<i64> for ForeignKey<'a, FK> {
|
|
||||||
fn from(value: FK::PrimaryKey) -> Self {
|
|
||||||
Self {
|
|
||||||
id: value,
|
|
||||||
_ft: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{
|
|
||||||
CurrPool,
|
|
||||||
tables::{ForeignKey, TableMeta, assignables::awards::Award, user::User},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct AwardRecord<'a> {
|
|
||||||
pub id: i64,
|
|
||||||
pub user_id: ForeignKey<'a, User>,
|
|
||||||
pub award_id: ForeignKey<'a, Award>,
|
|
||||||
pub author_id: ForeignKey<'a, User>,
|
|
||||||
pub created_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TableMeta<'a> for AwardRecord<'a> {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "records_awards";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AwardRecord<'_> {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
AwardRecord,
|
|
||||||
r#"
|
|
||||||
INSERT INTO records_awards (user_id, award_id, author_id, created_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
*self.user_id,
|
|
||||||
*self.award_id,
|
|
||||||
*self.author_id,
|
|
||||||
self.created_at,
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
self.author_id.extract(pool);
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
AwardRecord,
|
|
||||||
"SELECT * FROM records_awards WHERE id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_user_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
AwardRecord,
|
|
||||||
"SELECT * FROM records_awards WHERE user_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_author_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
AwardRecord,
|
|
||||||
"SELECT * FROM records_awards WHERE author_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_award_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
AwardRecord,
|
|
||||||
"SELECT * FROM records_awards WHERE award_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{
|
|
||||||
CurrPool,
|
|
||||||
tables::{ForeignKey, TableMeta, assignables::missions::Mission, user::User},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct MissionRecord<'a> {
|
|
||||||
pub id: i64,
|
|
||||||
pub user_id: ForeignKey<'a, User>,
|
|
||||||
pub mission_id: ForeignKey<'a, Mission>,
|
|
||||||
pub author_id: ForeignKey<'a, User>,
|
|
||||||
pub created_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for MissionRecord<'_> {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "records_missions";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MissionRecord<'_> {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
MissionRecord,
|
|
||||||
r#"
|
|
||||||
INSERT INTO records_missions (user_id, mission_id, author_id, created_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
*self.user_id,
|
|
||||||
*self.mission_id,
|
|
||||||
*self.author_id,
|
|
||||||
self.created_at,
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
MissionRecord,
|
|
||||||
"SELECT * FROM records_missions WHERE id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_user_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
MissionRecord,
|
|
||||||
"SELECT * FROM records_missions WHERE user_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_author_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
MissionRecord,
|
|
||||||
"SELECT * FROM records_missions WHERE author_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_mission_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
MissionRecord,
|
|
||||||
"SELECT * FROM records_missions WHERE mission_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
pub mod awards;
|
|
||||||
pub mod missions;
|
|
||||||
pub mod qualifications;
|
|
||||||
pub mod ranks;
|
|
||||||
pub mod trainings;
|
|
|
@ -1,82 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{
|
|
||||||
CurrPool,
|
|
||||||
tables::{ForeignKey, TableMeta, assignables::qualifications::Qualification, user::User},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct QualificationRecord<'a> {
|
|
||||||
pub id: i64,
|
|
||||||
pub user_id: ForeignKey<'a, User>,
|
|
||||||
pub author_id: ForeignKey<'a, User>,
|
|
||||||
pub qualification_id: ForeignKey<'a, Qualification>,
|
|
||||||
pub created_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TableMeta<'a> for QualificationRecord<'a> {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "records_qualifications";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> QualificationRecord<'a> {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
QualificationRecord,
|
|
||||||
r#"
|
|
||||||
INSERT INTO records_qualifications (user_id, qualification_id, author_id, created_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
*self.user_id,
|
|
||||||
*self.qualification_id,
|
|
||||||
*self.author_id,
|
|
||||||
self.created_at,
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
QualificationRecord,
|
|
||||||
"SELECT * FROM records_qualifications WHERE id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_user_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
QualificationRecord,
|
|
||||||
"SELECT * FROM records_qualifications WHERE user_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_author_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
QualificationRecord,
|
|
||||||
"SELECT * FROM records_qualifications WHERE author_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_qualification_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
QualificationRecord,
|
|
||||||
"SELECT * FROM records_qualifications WHERE qualification_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{
|
|
||||||
CurrPool,
|
|
||||||
tables::{ForeignKey, TableMeta, assignables::ranks::Rank, user::User},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct RankRecord<'a> {
|
|
||||||
pub id: i64,
|
|
||||||
pub user_id: ForeignKey<'a, User>,
|
|
||||||
pub rank_id: ForeignKey<'a, Rank>,
|
|
||||||
pub author_id: ForeignKey<'a, User>,
|
|
||||||
pub created_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TableMeta<'a> for RankRecord<'a> {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "records_ranks";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> RankRecord<'a> {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
RankRecord,
|
|
||||||
r#"
|
|
||||||
INSERT INTO records_ranks (user_id, rank_id, author_id, created_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
*self.user_id,
|
|
||||||
*self.rank_id,
|
|
||||||
*self.author_id,
|
|
||||||
self.created_at,
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(RankRecord, "SELECT * FROM records_ranks WHERE id = $1", id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_user_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
RankRecord,
|
|
||||||
"SELECT * FROM records_ranks WHERE user_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_author_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
RankRecord,
|
|
||||||
"SELECT * FROM records_ranks WHERE author_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_rank_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
RankRecord,
|
|
||||||
"SELECT * FROM records_ranks WHERE rank_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
use anyhow::Result;
|
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{
|
|
||||||
CurrPool,
|
|
||||||
tables::{ForeignKey, TableMeta, assignables::trainings::Training, user::User},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
pub struct TrainingRecord<'a> {
|
|
||||||
pub id: i64,
|
|
||||||
pub user_id: ForeignKey<'a, User>,
|
|
||||||
pub training_id: ForeignKey<'a, Training>,
|
|
||||||
pub author_id: ForeignKey<'a, User>,
|
|
||||||
pub created_at: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TableMeta<'a> for TrainingRecord<'a> {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "records_trainings";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TrainingRecord<'a> {
|
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
TrainingRecord,
|
|
||||||
r#"
|
|
||||||
INSERT INTO records_trainings (user_id, training_id, author_id, created_at)
|
|
||||||
VALUES ($1, $2, $3, $4)
|
|
||||||
RETURNING *
|
|
||||||
"#,
|
|
||||||
*self.user_id,
|
|
||||||
*self.training_id,
|
|
||||||
*self.author_id,
|
|
||||||
self.created_at,
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_id(pool: &CurrPool, id: i64) -> anyhow::Result<Self> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
TrainingRecord,
|
|
||||||
"SELECT * FROM records_trainings WHERE id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_user_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
TrainingRecord,
|
|
||||||
"SELECT * FROM records_trainings WHERE user_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_author_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
TrainingRecord,
|
|
||||||
"SELECT * FROM records_trainings WHERE author_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
pub async fn get_by_training_id(pool: &CurrPool, id: i64) -> anyhow::Result<Vec<Self>> {
|
|
||||||
let session = sqlx::query_as!(
|
|
||||||
TrainingRecord,
|
|
||||||
"SELECT * FROM records_trainings WHERE training_id = $1",
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.fetch_all(pool)
|
|
||||||
.await?;
|
|
||||||
Ok(session)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +1,14 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
use crate::db::CurrPool;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
pub user_id: i64,
|
pub user_id: i64,
|
||||||
pub session_key: String,
|
pub session_key: String,
|
||||||
pub expires: i64,
|
pub expires: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableMeta<'_> for Session {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "sessions";
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
pub async fn insert_new(&self, pool: &CurrPool) -> Result<Self> {
|
||||||
let session = sqlx::query_as!(
|
let session = sqlx::query_as!(
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use sqlx::prelude::FromRow;
|
|
||||||
|
|
||||||
use crate::db::{CurrPool, tables::TableMeta};
|
use crate::db::CurrPool;
|
||||||
#[derive(Debug, Default, Clone, FromRow)]
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
|
@ -11,12 +11,6 @@ pub struct User {
|
||||||
pub pw_hash: String,
|
pub pw_hash: String,
|
||||||
pub pw_salt: String,
|
pub pw_salt: String,
|
||||||
pub pfp_id: i64,
|
pub pfp_id: i64,
|
||||||
pub rank_id: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableMeta<'_> for User {
|
|
||||||
type PrimaryKey = i64;
|
|
||||||
const TABLE: &'static str = "users";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user