CrimsonCare
CrimsonCare is a C project designed to provide a robust solution for blood management.
 
Loading...
Searching...
No Matches
transaction_manager.c File Reference

Transaction manager source file. More...

Go to the source code of this file.

Functions

logTransaction

Log transaction to file

This function logs a transaction to the file resources/db/transactions.log.

Parameters
[in]typeTransaction type
[in]nameHospital name
[in]bloodIdBlood group id
[in]quantityBlood quantity
[in]dateTransaction date
[in]tokenTransaction token
Returns
True if transaction is logged, False otherwise
Note
The file path 'resources/db' is relative to the project root directory. Make sure that the folder exists also to run the program from the root directory.
Precondition
type is either BUY or SELL
name is not empty and valid
bloodId is a valid blood group id
quantity is greater than 0
date is a valid date
Postcondition
The transaction is logged to the file resources/db/transactions.log.
Exceptions
Ifthe file `resources/db/transactions.log` cannot be opened, an error message is displayed.
Ifthe type is not BUY or SELL, an error message is displayed.
Ifthe name is empty or invalid, an error message is displayed.
Ifthe bloodId is not a valid blood group id, an error message is displayed.
Ifthe quantity is less than or equal to 0, an error message is displayed.
Ifthe date is not a valid date, an error message is displayed.
bool logTransaction (TransactionType type, const char *name, uint32_t bloodId, uint32_t quantity, const char *date, const char *token)
 
addTransaction

Add transaction

This function adds a transaction to the transactionHead linkedlist.

Parameters
[in]typeTransaction type
[in]nameHospital name
[in]bloodIdBlood group id
[in]quantityBlood quantity
Returns
True if transaction is added, False otherwise
Note
For SELL transaction, the user is asked to enter the date of donation, and a token is generated for the transaction.
Precondition
name is not empty and valid
type is either BUY or SELL
quantity is greater than 0
bloodId is a valid blood group id
Postcondition
The transaction is logged to the file resources/db/transactions.log through logTransaction function.
Exceptions
Ifthe name is empty or invalid, an error message is displayed.
Ifthe type is not BUY or SELL, an error message is displayed.
Ifthe quantity is less than or equal to 0, an error message is displayed.
Ifthe bloodId is not a valid blood group id, an error message is displayed.
ForBUY transaction, if the name is not a valid hospital code, an error message is displayed.
ForSELL transaction, if the input date is not a valid date, an error message is displayed.
bool addTransaction (TransactionType type, const char *name, uint32_t bloodId, uint32_t quantity)
 
void displayTransactions (void)
 Display all transactions.
 

Detailed Description

Transaction manager source file.

This file contains the implementation of the functions for the transaction manager module.

Author
CrimsonCare Team
Date
2025-01-18

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file transaction_manager.c.

Function Documentation

◆ addTransaction()

bool addTransaction ( TransactionType type,
const char * name,
uint32_t bloodId,
uint32_t quantity )

Definition at line 141 of file transaction_manager.c.

◆ displayTransactions()

void displayTransactions ( void )

Display all transactions.

This function displays all transactions from the file resources/db/transactions.log.

Precondition
The file resources/db/transactions.log exists.
Postcondition
All transactions are displayed.
Exceptions
Ifthe file `resources/db/transactions.log` cannot be opened, an error message is displayed.

Definition at line 222 of file transaction_manager.c.

◆ logTransaction()

bool logTransaction ( TransactionType type,
const char * name,
uint32_t bloodId,
uint32_t quantity,
const char * date,
const char * token )

Definition at line 68 of file transaction_manager.c.