generated from OBJNULL/Dockerized-Rust
Created simple backend with hard-coded prices
This commit is contained in:
parent
9fbee2f2a3
commit
494b38a89b
1 changed files with 50 additions and 0 deletions
|
@ -0,0 +1,50 @@
|
|||
// Libraries
|
||||
use std::io::Result;
|
||||
|
||||
// Structures
|
||||
pub struct Backend {
|
||||
memberships: Vec<String>,
|
||||
}
|
||||
|
||||
// Implementations
|
||||
impl Backend {
|
||||
// Constructors
|
||||
/// Creates a new Backend
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `fetch` - Uses the **Internet** to fetch the latest prices for memberships.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rs
|
||||
/// let backend = Backend::new(true)?;
|
||||
/// ```
|
||||
pub fn new(fetch: bool) -> Result<Self> {
|
||||
// Did we want to fetch our prices?
|
||||
let memberships: Vec<String> = if fetch {
|
||||
// Use Internet to get prices
|
||||
unimplemented!("TODO: Implement online Membership Price Fetching");
|
||||
} else {
|
||||
// Manually creating our prices
|
||||
vec![
|
||||
"Super ($41.99)".to_string(),
|
||||
"Deluxe ($36.99)".to_string(),
|
||||
"Standard ($31.99)".to_string(),
|
||||
"Basic ($26.99)".to_string(),
|
||||
]
|
||||
};
|
||||
|
||||
// Return Self
|
||||
Ok(Self { memberships })
|
||||
}
|
||||
|
||||
// Functions
|
||||
/// Gets the list of current memberships
|
||||
///
|
||||
/// # Examples
|
||||
/// ```rs
|
||||
/// app.set_membership_names(backend.get_memberships());
|
||||
/// ```
|
||||
pub fn get_memberships(&self) -> Vec<String> {
|
||||
self.memberships.clone()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue