Skip to content

Commit

Permalink
Shared - Store Account Data In Memory
Browse files Browse the repository at this point in the history
nlogozzo committed Feb 20, 2024
1 parent 67d60a8 commit 75684f6
Showing 8 changed files with 388 additions and 179 deletions.
21 changes: 7 additions & 14 deletions libdenaro/include/models/account.h
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ namespace Nickvision::Money::Shared::Models
bool isEncrypted() const;
/**
* @brief Logins to the account.
* @brief This method also loads the account's metadata into memory.
* @brief This method also loads the account's data into memory.
* @param password The password for the account. If unencrypted, this param must be an empty string
* @return True if successful, else false
*/
@@ -63,17 +63,17 @@ namespace Nickvision::Money::Shared::Models
* @brief Gets all the groups for the account.
* @return The account's groups
*/
std::unordered_map<int, Group> getGroups() const;
const std::unordered_map<int, Group>& getGroups() const;
/**
* @brief Gets all the tags for the account.
* @return The account's tags
*/
std::vector<std::string> getTags() const;
const std::vector<std::string>& getTags() const;
/**
* @brief Gets all the transactions for the account.
* @return The account's transactions
*/
std::unordered_map<int, Transaction> getTransactions() const;
const std::unordered_map<int, Transaction>& getTransactions() const;
/**
* @brief Gets the transaction reminders for the account.
* @brief Each reminder is a tuple of the following: (std::string TransactionDescription, double TransactionAmount, std::string When)
@@ -90,16 +90,6 @@ namespace Nickvision::Money::Shared::Models
* @return The next available transaction id
*/
int getNextAvailableTransactionId() const;
/**
* @brief Gets the number of groups in the account.
* @return The number of groups in the account
*/
size_t getNumberOfGroups() const;
/**
* @brief Gets the number of transactions in the account.
* @return The number of transactions in the account
*/
size_t getNumberOfTransactions() const;
/**
* @brief Gets the total income amount for the transactions given.
* @param transactionIds The ids of transactions to consider
@@ -270,6 +260,9 @@ namespace Nickvision::Money::Shared::Models
bool m_loggedIn;
mutable Database::SqlDatabase m_database;
AccountMetadata m_metadata;
std::unordered_map<int, Group> m_groups;
std::vector<std::string> m_tags;
std::unordered_map<int, Transaction> m_transactions;
};
}

10 changes: 8 additions & 2 deletions libdenaro/include/models/group.h
Original file line number Diff line number Diff line change
@@ -7,10 +7,16 @@
namespace Nickvision::Money::Shared::Models
{
/**
* @brief A model of a group for transactions.
* @brief A model of a group of transactions.
*/
class Group {
class Group
{
public:
/**
* @brief Constructs a Group.
* @brief This default constructor is required for the use of std::unordered_map. It should not be used by clients.
*/
Group();
/**
* @brief Constructs a Group.
* @param id The id of the group
30 changes: 15 additions & 15 deletions libdenaro/include/models/importresult.h
Original file line number Diff line number Diff line change
@@ -25,33 +25,33 @@ namespace Nickvision::Money::Shared::Models
* @brief Gets the list of new transaction ids from the import.
* @return The list of new transaction ids
*/
const std::vector<unsigned int>& getNewTransactionIds() const;
const std::vector<int>& getNewTransactionIds() const;
/**
* @brief Gets the list of new group ids from the import.
* @return The list of new group ids
*/
const std::vector<unsigned int>& getNewGroupIds() const;
const std::vector<int>& getNewGroupIds() const;
/**
* @brief Gets the list of new tags from the import.
* @return The list of new tags
*/
const std::vector<std::string>& getNewTags() const;
/**
* @brief Adds an id to the new transaction ids list.
* @brief This method will only add the id if it doesn't already exist in the list.
* @param id The id to add
* @brief Adds a transaction id to the new transaction ids list.
* @brief This method will only add the transaction id if it doesn't already exist in the list.
* @param id The transaction id to add
*/
void addTransactionId(unsigned int id);
void addTransaction(int id);
/**
* @brief Adds an id to the new group ids list.
* @brief This method will only add the id if it doesn't already exist in the list.
* @param id The id to add
* @brief Adds a group id to the new group ids list.
* @brief This method will only add the group id if it doesn't already exist in the list.
* @param id The group id to add
*/
void addGroupId(unsigned int id);
void addGroup(int id);
/**
* @brief Adds a list of tags to the new tags list.
* @brief This method will only add non-existing tags. Existing tags will be skipped over to avoid duplicates.
* @param tags The list of tags to add
* @brief Adds a list of tags to the new tags list.
* @brief This method will only add tags if they doesn't already exist in the list.
* @param tags The tags to add
*/
void addTags(const std::vector<std::string>& tags);
/**
@@ -61,8 +61,8 @@ namespace Nickvision::Money::Shared::Models
operator bool() const;

private:
std::vector<unsigned int> m_newTransactionIds;
std::vector<unsigned int> m_newGroupIds;
std::vector<int> m_newTransactions;
std::vector<int> m_newGroups;
std::vector<std::string> m_newTags;
};
}
11 changes: 11 additions & 0 deletions libdenaro/include/models/transaction.h
Original file line number Diff line number Diff line change
@@ -17,6 +17,11 @@ namespace Nickvision::Money::Shared::Models
class Transaction
{
public:
/**
* @brief Constructs a Transaction.
* @brief This default constructor is required for the use of std::unordered_map. It should not be used by clients.
*/
Transaction();
/**
* @brief Constructs a Transaction.
* @param id The id of the transaction
@@ -154,6 +159,12 @@ namespace Nickvision::Money::Shared::Models
* @return True if successful, else false if the tag does not exist in the transaction
*/
bool removeTag(const std::string& tag);
/**
* @brief Sets the tags of the transaction.
* @brief This method overwrites the current tags.
* @param tags The new transaction tags
*/
void setTags(const std::vector<std::string>& tags);
/**
* @brief Gets the notes of the transaction.
* @return The transaction notes
447 changes: 310 additions & 137 deletions libdenaro/src/models/account.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions libdenaro/src/models/group.cpp
Original file line number Diff line number Diff line change
@@ -2,6 +2,14 @@

namespace Nickvision::Money::Shared::Models
{
Group::Group()
: m_id{ -1 },
m_name{ "" },
m_description{ "" }
{

}

Group::Group(int id)
: m_id{ id },
m_name{ "" },
22 changes: 11 additions & 11 deletions libdenaro/src/models/importresult.cpp
Original file line number Diff line number Diff line change
@@ -5,37 +5,37 @@ namespace Nickvision::Money::Shared::Models
{
bool ImportResult::empty() const
{
return m_newTransactionIds.empty() && m_newGroupIds.empty() && m_newTags.empty();
return m_newTransactions.empty() && m_newGroups.empty() && m_newTags.empty();
}

const std::vector<unsigned int>& ImportResult::getNewTransactionIds() const
const std::vector<int>& ImportResult::getNewTransactionIds() const
{
return m_newTransactionIds;
return m_newTransactions;
}

const std::vector<unsigned int>& ImportResult::getNewGroupIds() const
const std::vector<int>& ImportResult::getNewGroupIds() const
{
return m_newGroupIds;
return m_newGroups;
}

const std::vector<std::string>& ImportResult::getNewTags() const
{
return m_newTags;
}

void ImportResult::addTransactionId(unsigned int id)
void ImportResult::addTransaction(int id)
{
if(std::find(m_newTransactionIds.begin(), m_newTransactionIds.end(), id) == m_newTransactionIds.end())
if(std::find(m_newTransactions.begin(), m_newTransactions.end(), id) == m_newTransactions.end())
{
m_newTransactionIds.push_back(id);
m_newTransactions.push_back(id);
}
}

void ImportResult::addGroupId(unsigned int id)
void ImportResult::addGroup(int id)
{
if(std::find(m_newGroupIds.begin(), m_newGroupIds.end(), id) == m_newGroupIds.end())
if(std::find(m_newGroups.begin(), m_newGroups.end(), id) == m_newGroups.end())
{
m_newGroupIds.push_back(id);
m_newGroups.push_back(id);
}
}

18 changes: 18 additions & 0 deletions libdenaro/src/models/transaction.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,19 @@

namespace Nickvision::Money::Shared::Models
{
Transaction::Transaction()
: m_id{ -1 },
m_date{ boost::gregorian::day_clock::local_day() },
m_type{ TransactionType::Income },
m_amount{ 0.0 },
m_groupId{ -1 },
m_useGroupColor{ true },
m_repeatInterval{ TransactionRepeatInterval::Never },
m_repeatFrom{ -1 }
{

}

Transaction::Transaction(int id)
: m_id{ id },
m_date{ boost::gregorian::day_clock::local_day() },
@@ -161,6 +174,11 @@ namespace Nickvision::Money::Shared::Models
return true;
}

void Transaction::setTags(const std::vector<std::string>& tags)
{
m_tags = tags;
}

const std::string& Transaction::getNotes() const
{
return m_notes;

0 comments on commit 75684f6

Please sign in to comment.