Formatting code

This commit is contained in:
Benjamin Sherriff
2024-05-12 09:05:59 -04:00
parent c971c55aa3
commit 1de68f86ae
46 changed files with 1109 additions and 609 deletions

View File

@@ -22,9 +22,15 @@ lazy_static! {
let host = env::var("DATABASE_HOST").unwrap_or("localhost".to_string());
let name = env::var("DATABASE_NAME").expect("DATABASE_NAME is not set");
let port = env::var("DATABASE_PORT").unwrap_or("5432".to_string());
let url = format!("postgres://{}:{}@{}:{}/{}", username, password, host, port, name);
let url = format!(
"postgres://{}:{}@{}:{}/{}",
username, password, host, port, name
);
let manager = DieselConnectionManager::<PgConnection>::new(url);
DbPool::builder().test_on_check_out(true).build(manager).expect("Failed to create db pool")
DbPool::builder()
.test_on_check_out(true)
.build(manager)
.expect("Failed to create db pool")
};
static ref REDIS: RedisClient = {
let host = env::var("REDIS_HOST").unwrap_or("localhost".to_string());
@@ -38,21 +44,23 @@ lazy_static! {
let user = env::var("MINIO_ROOT_USER").expect("MINIO_ROOT_USER is not set");
let password = env::var("MINIO_ROOT_PASSWORD").expect("MINIO_ROOT_PASSWORD is not set");
let base_url = format!("http://{}:{}", url, port);
let region = Region::Custom {
region: "".to_string(),
endpoint: base_url,
};
let credentials = Credentials {
access_key: Some(user),
secret_key: Some(password),
security_token: None,
session_token: None,
expiration: None
expiration: None,
};
Bucket::new("siren", region.clone(), credentials.clone()).expect("Failed to create S3 Bucket").with_path_style()
Bucket::new("siren", region.clone(), credentials.clone())
.expect("Failed to create S3 Bucket")
.with_path_style()
};
}
@@ -64,12 +72,13 @@ pub async fn init() {
let mut pool: DbConnection = connection().expect("Failed to get db connection");
match pool.run_pending_migrations(MIGRATIONS) {
Ok(_) => info!("Database initialized"),
Err(err) => error!("Failed to initialize database; {}", err)
Err(err) => error!("Failed to initialize database; {}", err),
};
}
pub fn connection() -> Result<DbConnection, ServiceError> {
POOL.get()
POOL
.get()
.map_err(|e| ServiceError::new(500, format!("Failed getting db connection: {}", e)))
}
@@ -100,9 +109,11 @@ async fn create_bucket() {
secret_key: Some(password),
security_token: None,
session_token: None,
expiration: None
expiration: None,
};
let _ = Bucket::create_with_path_style("siren", region, credentials, BucketConfiguration::default()).await;
let _ =
Bucket::create_with_path_style("siren", region, credentials, BucketConfiguration::default())
.await;
}
pub async fn upload_file(path: &str, content: &[u8]) -> Result<ResponseData, ServiceError> {

View File

@@ -51,4 +51,4 @@ diesel::table! {
profile_picture -> Nullable<Text>,
verified -> Bool,
}
}
}