Skip to content

Commit

Permalink
#15 adding model and test of bank fund
Browse files Browse the repository at this point in the history
  • Loading branch information
José Antonio Córdoba Gómez committed Dec 11, 2020
1 parent f250e47 commit a5608c2
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ entidad:
test:
- src/bankaccount/test_galvanic.rs
- src/bankcard/test_galvanic.rs
- src/bankfund/test.rs
- src/bankfund/test_galvanic.rs
- src/controller/test.rs
- src/paymentgroup/test.rs
- src/savinggroup/test.rs
Expand Down
2 changes: 1 addition & 1 deletion src/bankfund/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod model;
pub mod test;
pub mod test_galvanic;
111 changes: 97 additions & 14 deletions src/bankfund/model.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,105 @@
use chrono::{NaiveDateTime};

pub struct Fund{
id: String,
number: String,
amount: f64,
date_start: NaiveDateTime,
date_finish: NaiveDateTime,
status: bool
}
pub mod bankfund{
use chrono::{NaiveDateTime};
use std::fmt;
use serde::{Serialize,Deserialize};
use crate::utils::model::{Lib};

extern crate regex;
extern crate serde;
extern crate serde_json;

/// Bank Fund model
pub struct Fund{
/// Identification of the bank fund, it should be an identification intern of app that it's consistent with database identificator
id: String,

/// Amount invested
amount: f64,

impl Fund{
fn enable(){
/// Due Date when fund starts to be active
date_start: NaiveDateTime,

/// Due Date until fund is active
date_finish: NaiveDateTime,
/// Current Status of fund
status: bool
}

fn disable(){
impl Fund{

/// Allocate a Fund object and intializes it so that it represent the fund investment
/// Usage
/// let my_fund = Fund::new(id,amount,date_start,date_finish,status)
pub fn new(new_id: String, new_amount: f64, new_date_start: NaiveDateTime, new_date_finish:NaiveDateTime , new_status:bool) -> Fund{
Fund{
id: new_id,
amount: new_amount,
date_start: new_date_start,
date_finish: new_date_finish,
status : new_status
}
}

/// Getter (inmutable) for id private attribute
pub fn get_id(&self) -> &String{
&self.id
}

/// Getter (inmutable) for number private attribure.
pub fn get_amount(&self)-> &f64{
&self.amount
}

/// Muttable access for amount private attribute
pub fn set_amount(&mut self, amount: f64) -> &f64{
self.amount = amount;
&self.amount
}

/// Getter (inmutable) for date private attribure.
pub fn get_start_date(&self)-> &NaiveDateTime{
&self.date_start
}

/// Muttable access for date private attribute
pub fn set_start_date(&mut self, new_date: NaiveDateTime) -> &NaiveDateTime{
self.date_start = new_date;
&self.date_start
}

/// Getter (inmutable) for date private attribure.
pub fn get_finish_date(&self)-> &NaiveDateTime{
&self.date_finish
}

/// Muttable access for date private attribute
pub fn set_finish_date(&mut self, new_date: NaiveDateTime) -> &NaiveDateTime{
self.date_finish = new_date;
&self.date_finish
}

/// Inmutable access to check the status of the card
pub fn is_active(&self) -> bool {
self.status
}

/// Enables a card
fn enable(&mut self) {
self.status = true
}

/// Disables acard
fn disable(&mut self) {
self.status = false
}

}

/// The fmt method allows display all atributes of an Bank
impl fmt::Display for Fund{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {}, {}, {}, {})", self.id, self.amount, self.date_start, self.date_finish, self.status)
}
}

}
}
Empty file removed src/bankfund/test.rs
Empty file.
2 changes: 1 addition & 1 deletion src/controller/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::user::model::user::User;
use crate::bankaccount::model::bankaccount::*;
use std::collections::HashMap;
use crate::bankcard::model::bankcard::*;
use crate::bankfund::model::{Fund};
use crate::bankfund::model::bankfund::*;
use crate::savinggroup::model::{Savinggroup};
use crate::paymentgroup::model::{Paymentgroup};
use serde::{Serialize,Deserialize};
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate serde_json;

use crate::bankaccount::model::bankaccount::*;
use crate::bankcard::model::bankcard::*;
use crate::bankfund::model::{Fund};
use crate::bankfund::model::bankfund::*;
use crate::savinggroup::model::{Savinggroup};
use crate::paymentgroup::model::{Paymentgroup};
use crate::user::model::user::User;
Expand Down

0 comments on commit a5608c2

Please sign in to comment.