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

Transaction manager header file. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>

Go to the source code of this file.

Macros

#define MAX_TRANSACTION_NAME_LENGTH   50
 Maximum transaction name length.
 
#define MAX_TRANSACTION_DATE_LENGTH   11
 Maximum transaction date length.
 
#define MAX_TRANSACTION_TOKEN_LENGTH   12
 Maximum transaction token length.
 

Typedefs

typedef enum TransactionType TransactionType
 

Enumerations

enum  TransactionType { SELL , BUY }
 Transaction type enum. More...
 

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.
 
void freeTransaction (void)
 Free transaction list from memory.
 

Detailed Description

Transaction manager header file.

This file contains the declarations of the functions and structures 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.h.

Macro Definition Documentation

◆ MAX_TRANSACTION_DATE_LENGTH

#define MAX_TRANSACTION_DATE_LENGTH   11

Maximum transaction date length.

This macro defines the maximum length of the transaction date.

Definition at line 54 of file transaction_manager.h.

◆ MAX_TRANSACTION_NAME_LENGTH

#define MAX_TRANSACTION_NAME_LENGTH   50

Maximum transaction name length.

This macro defines the maximum length of the transaction name.

Definition at line 47 of file transaction_manager.h.

◆ MAX_TRANSACTION_TOKEN_LENGTH

#define MAX_TRANSACTION_TOKEN_LENGTH   12

Maximum transaction token length.

This macro defines the maximum length of the transaction token.

Definition at line 61 of file transaction_manager.h.

Enumeration Type Documentation

◆ TransactionType

Transaction type enum.

This enum defines the transaction type.

Enumerator
SELL 

Sell transaction type

BUY 

Buy transaction type

Definition at line 68 of file transaction_manager.h.

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.

◆ freeTransaction()

void freeTransaction ( void )

Free transaction list from memory.

◆ 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.