Skip to content

Commit

Permalink
Merge branch 'main' into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
worldofjoni authored Aug 25, 2023
2 parents 04795c9 + aca08da commit 52d2f16
Show file tree
Hide file tree
Showing 39 changed files with 813 additions and 198 deletions.
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ FLICKR_API_KEY=
#MENSA_BASE_URL=https://www.sw-ka.de/de/hochschulgastronomie/speiseplan/
#CANTEENS=mensa_adenauerring,mensa_gottesaue,mensa_moltke,mensa_x1moltkestrasse,mensa_erzberger,mensa_tiefenbronner,mensa_holzgarten
#USER_AGENT=
#PARSE_WEEKS=


# --- graphql server ---
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mensa-app-backend"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = ["Alexander Albers <usvan@student.kit.edu>", "Peer Booken <uglrl@student.kit.edu>", "Elena Häußler <uqhnu@student.kit.edu>", "Alexander Kutschera <ubsbo@student.kit.edu>", "Jonatan Ziegler <udslu@student.kit.edu"]
description = "Backend application for providing and synchronizing meal plan data of the canteens of the Studierendenwerk Karlsruhe."
Expand Down
6 changes: 6 additions & 0 deletions backend/src/interface/admin_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ pub struct ImageReportInfo {
pub negative_rating_count: u32,
/// Image rank after which the images are sorted when shown to the user.
pub get_image_rank: f32,
/// Number of times this image would have to be reported to automatically get hidden (at the current date).
pub report_barrier: u32,
/// User that reported the image.
pub client_id: Uuid,
/// The age of the image in days
pub image_age: i64,
}
2 changes: 2 additions & 0 deletions backend/src/interface/persistent_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub trait MealplanManagementDataAccess: Send + Sync {
async fn get_similar_meal(
&self,
similar_name: &str,
meal_type: MealType,
allergens: &[Allergen],
additives: &[Additive],
) -> Result<Option<Uuid>>;
Expand All @@ -78,6 +79,7 @@ pub trait MealplanManagementDataAccess: Send + Sync {
async fn get_similar_side(
&self,
similar_name: &str,
meal_type: MealType,
allergens: &[Allergen],
additives: &[Additive],
) -> Result<Option<Uuid>>;
Expand Down
14 changes: 11 additions & 3 deletions backend/src/layer/data/database/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ use super::{
pub struct DatabaseInfo {
/// Connection string to database of format `postgres://<username>:<password>@<host>:<port>/<database>`.
pub connection: String,
/// Number of weeks, including the current we /get meal plan data for.
pub max_weeks_data: u32,
}

/// This class is responsible for instantiating the database access implementations classes.
pub struct DataAccessFactory {
pool: Pool<Postgres>,
pub max_weeks_data: u32,
}

const MAX_DB_CONNECTIONS: u32 = 20;
Expand All @@ -27,19 +30,22 @@ impl DataAccessFactory {
/// If wished, database migrations can be applied to create the wanted relations.
/// # Errors
/// if a migrations should, but could not run
/// if the connection to the database could not be established
pub async fn new(info: DatabaseInfo, should_migrate: bool) -> Result<Self> {
let pool = PgPoolOptions::new()
.max_connections(MAX_DB_CONNECTIONS)
.connect(&info.connection)
.await
.expect("cannot connect to database");
.await?;

if should_migrate {
sqlx::migrate!().run(&pool).await?;
info!("Successfully run database migrations");
}

Ok(Self { pool })
Ok(Self {
pool,
max_weeks_data: info.max_weeks_data,
})
}

/// Returns a object for accessing database requests for api commands.
Expand Down Expand Up @@ -71,6 +77,7 @@ impl DataAccessFactory {
pub fn get_request_data_access(&self) -> PersistentRequestData {
PersistentRequestData {
pool: self.pool.clone(),
max_weeks_data: self.max_weeks_data,
}
}
}
Expand All @@ -95,6 +102,7 @@ mod tests {

let info = DatabaseInfo {
connection: connection.clone(),
max_weeks_data: 4,
};
let factory = DataAccessFactory::new(info, true)
.await
Expand Down
Loading

0 comments on commit 52d2f16

Please sign in to comment.