You've already forked AstralRinth
forked from didirus/AstralRinth
Tests (#719)
* computer switch * some fixes; github action * added pr to master * sqlx database setup * switched intial GHA test db * removed sqlx database setup * unfinished patch route * bug fixes + tests * more tests, more fixes, cargo fmt * merge fixes * more tests, full reorganization * fmt, clippy * sqlx-data * revs * removed comments * delete revs
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use crate::database::redis::RedisPool;
|
||||
|
||||
use super::ids::*;
|
||||
use super::DatabaseError;
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use futures::TryStreamExt;
|
||||
use redis::cmd;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const TAGS_NAMESPACE: &str = "tags";
|
||||
const DEFAULT_EXPIRY: i64 = 1800; // 30 minutes
|
||||
|
||||
pub struct ProjectType {
|
||||
pub id: ProjectTypeId,
|
||||
@@ -98,17 +98,12 @@ impl Category {
|
||||
Ok(result.map(|r| CategoryId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
) -> Result<Vec<Category>, DatabaseError>
|
||||
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<Category>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:category", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "category")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<Category>>(&x).ok());
|
||||
|
||||
@@ -137,12 +132,13 @@ impl Category {
|
||||
.try_collect::<Vec<Category>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:category", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"category",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
@@ -167,17 +163,12 @@ impl Loader {
|
||||
Ok(result.map(|r| LoaderId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
) -> Result<Vec<Loader>, DatabaseError>
|
||||
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<Loader>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:loader", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "loader")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<Loader>>(&x).ok());
|
||||
|
||||
@@ -212,12 +203,13 @@ impl Loader {
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:loader", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"loader",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
@@ -256,17 +248,12 @@ impl GameVersion {
|
||||
Ok(result.map(|r| GameVersionId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
) -> Result<Vec<GameVersion>, DatabaseError>
|
||||
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<GameVersion>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:game_version", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "game_version")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<GameVersion>>(&x).ok());
|
||||
|
||||
@@ -291,14 +278,14 @@ impl GameVersion {
|
||||
.try_collect::<Vec<GameVersion>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:game_version", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"game_version",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -306,7 +293,7 @@ impl GameVersion {
|
||||
version_type_option: Option<&str>,
|
||||
major_option: Option<bool>,
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
redis: &RedisPool,
|
||||
) -> Result<Vec<GameVersion>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
@@ -408,15 +395,13 @@ impl DonationPlatform {
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
redis: &RedisPool,
|
||||
) -> Result<Vec<DonationPlatform>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:donation_platform", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "donation_platform")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<DonationPlatform>>(&x).ok());
|
||||
|
||||
@@ -440,12 +425,13 @@ impl DonationPlatform {
|
||||
.try_collect::<Vec<DonationPlatform>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:donation_platform", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"donation_platform",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
@@ -470,17 +456,12 @@ impl ReportType {
|
||||
Ok(result.map(|r| ReportTypeId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
) -> Result<Vec<String>, DatabaseError>
|
||||
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<String>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:report_type", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "report_type")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<String>>(&x).ok());
|
||||
|
||||
@@ -498,12 +479,13 @@ impl ReportType {
|
||||
.try_collect::<Vec<String>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:report_type", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"report_type",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
@@ -528,17 +510,12 @@ impl ProjectType {
|
||||
Ok(result.map(|r| ProjectTypeId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
) -> Result<Vec<String>, DatabaseError>
|
||||
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<String>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:project_type", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "project_type")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<String>>(&x).ok());
|
||||
|
||||
@@ -556,12 +533,13 @@ impl ProjectType {
|
||||
.try_collect::<Vec<String>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:project_type", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"project_type",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
@@ -586,17 +564,12 @@ impl SideType {
|
||||
Ok(result.map(|r| SideTypeId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
redis: &deadpool_redis::Pool,
|
||||
) -> Result<Vec<String>, DatabaseError>
|
||||
pub async fn list<'a, E>(exec: E, redis: &RedisPool) -> Result<Vec<String>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let mut redis = redis.get().await?;
|
||||
let res = cmd("GET")
|
||||
.arg(format!("{}:side_type", TAGS_NAMESPACE))
|
||||
.query_async::<_, Option<String>>(&mut redis)
|
||||
let res = redis
|
||||
.get::<String, _>(TAGS_NAMESPACE, "side_type")
|
||||
.await?
|
||||
.and_then(|x| serde_json::from_str::<Vec<String>>(&x).ok());
|
||||
|
||||
@@ -614,12 +587,13 @@ impl SideType {
|
||||
.try_collect::<Vec<String>>()
|
||||
.await?;
|
||||
|
||||
cmd("SET")
|
||||
.arg(format!("{}:side_type", TAGS_NAMESPACE))
|
||||
.arg(serde_json::to_string(&result)?)
|
||||
.arg("EX")
|
||||
.arg(DEFAULT_EXPIRY)
|
||||
.query_async::<_, ()>(&mut redis)
|
||||
redis
|
||||
.set(
|
||||
TAGS_NAMESPACE,
|
||||
"side_type",
|
||||
serde_json::to_string(&result)?,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
|
||||
Reference in New Issue
Block a user