From a5608c2cc1213abf9889a9526dc0f1d716351e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20C=C3=B3rdoba=20G=C3=B3mez?= Date: Fri, 11 Dec 2020 22:27:54 +0100 Subject: [PATCH] #15 adding model and test of bank fund --- cc.yaml | 2 +- src/bankfund/mod.rs | 2 +- src/bankfund/model.rs | 111 +++++++++++++++++++++++++++++++++++----- src/bankfund/test.rs | 0 src/controller/model.rs | 2 +- src/main.rs | 2 +- 6 files changed, 101 insertions(+), 18 deletions(-) delete mode 100755 src/bankfund/test.rs diff --git a/cc.yaml b/cc.yaml index 4b124036c..5dabe510b 100644 --- a/cc.yaml +++ b/cc.yaml @@ -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 diff --git a/src/bankfund/mod.rs b/src/bankfund/mod.rs index 7d17ad0cb..bdcc1d4c3 100755 --- a/src/bankfund/mod.rs +++ b/src/bankfund/mod.rs @@ -1,2 +1,2 @@ pub mod model; -pub mod test; \ No newline at end of file +pub mod test_galvanic; \ No newline at end of file diff --git a/src/bankfund/model.rs b/src/bankfund/model.rs index e5ebdf4af..c54a2fc35 100755 --- a/src/bankfund/model.rs +++ b/src/bankfund/model.rs @@ -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) + } } -} \ No newline at end of file +} diff --git a/src/bankfund/test.rs b/src/bankfund/test.rs deleted file mode 100755 index e69de29bb..000000000 diff --git a/src/controller/model.rs b/src/controller/model.rs index b26624c15..96d76a2e9 100755 --- a/src/controller/model.rs +++ b/src/controller/model.rs @@ -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}; diff --git a/src/main.rs b/src/main.rs index 8b4015700..8eb649532 100755 --- a/src/main.rs +++ b/src/main.rs @@ -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;