The theme of the work is arbitrary. At least two persistent entities bound by at least the OneToMany/ManyToOne association must be used in the data part. Business logic must be accessible by REST service. For the service, create a client in any technology.
If the contact examination is resumed and the requirement to maintain 2m distances is lifted, the semester papers will be presented during the contact examination. Otherwise, the semester papers will be handed over electrically and must contain:
- Source codes
- Presentation video to the extent in which the work would be presented by contact (about 5 min):
- topic of work
- sample use
- application architecture i.e. description of individual components (presentation, business, communication, etc.)
- brief description of used libraries
- Executable shape (uber / fat jar) or build and run instructions
This project is a simple banking application developed using the Spring Boot framework. The "Bank Application" project provides a convenient way to manage financial transactions and user accounts.
The purpose of this documentation is to provide a complete description of the functionality, architecture and important aspects of the Bank Application project. Here you will find detailed information about the various components of the project, their interaction and settings.
The main features of the "Bank Application" project include:
-
User management: The application provides the ability to register and authenticate users. Each user has a unique account with personal information and login details.
-
Financial transactions: Users can perform various financial transactions, such as transferring funds, paying bills, viewing transaction history, and others. The application ensures the security and integrity of data during operations.
-
Database integration: The DemoBank project uses a database to store user data, transaction history and other important information. MySQL is used as a DBMS.
-
Web interface: The application provides a user-friendly web interface that allows users to interact with the functionality of the project through a convenient user interface.
This documentation contains a description of each component of the project, its functionality, usage and configuration. You will also find code examples to better understand how to use the various features of the project.
The architecture of the "Bank Application" project is based on the Spring Boot framework and follows the principles of the MVC (Model-View-Controller) architectural pattern. It is divided into several layers, each of which performs certain functions and is responsible for specific aspects of the application. Here is an overview of the main architecture layers of the "Bank Application" project:
-
View layer (View): This layer contains the components responsible for presenting data and interacting with the user. In the "Bank Application" project, the presentation is carried out using a web interface implemented using HTML, CSS and JavaScript. It allows users to interact with the application and perform various actions such as registering, logging in, performing transactions, and viewing information.
-
Controller layer (Controller): Controllers are intermediaries between the view and the model layer. They process requests from users, perform appropriate actions, and pass data to the view. In the Bank Application project, the controllers are implemented using Spring MVC annotations and handle various HTTP requests, such as user registration, transaction execution, and data retrieval.
-
Model layer (Model): The model represents the business logic of the application and the data required for its operation. In the Bank Application project, the model consists of classes representing database entities such as user and transaction. They represent the structure and relationships between data, and provide methods for interacting with the database, including reading, writing, and updating data.
-
Data Access Layer: This layer is responsible for interacting with the database and performing read and write operations. In the "Bank Application" project, the data access layer is implemented using Spring Data JPA, which provides convenient facilities for working with the database, such as CRUD operations (Create, Read, Update, Delete) and annotation-based queries.
-
Configuration layer: The "Bank Application" project also has a configuration layer where various application settings are configured, including database connection, server properties, and others. These settings are usually stored in the
application.properties
file and are loaded when the application starts. -
Services layer: Services are intermediate components between controllers and the data access layer. They implement the business logic of the application, coordinate the execution of operations, and ensure code reuse. In the "Bank Application" project, services can be used to perform operations with users, transactions and other entities.
The architecture of the "Bank Application" project strives for separation of concerns and modularity, which makes it easier to maintain, test and extend the application. It also takes advantage of the Spring Boot framework for automatic configuration and dependency management, making it easier to develop and deploy your application.
The main functions of the "Bank Application" project include:
-
User registration:
- Allows users to create a new account in the system.
- Requests user information such as name, email address, and password.
- Checks the uniqueness of the email address and stores the user's data in the database.
-
Login:
- Allows registered users to log into their account.
- Checks if the combination of email address and password is correct.
- Gives authorized users access to the functionality of the application.
-
Viewing user information:
- Allows users to view their personal information such as name, address and other details provided during registration.
-
Execution of transactions:
- Allows users to carry out financial transactions such as transferring funds between accounts.
- Requests information about the account of the sender and recipient, as well as the amount of the transfer.
- Checks the availability of funds in the sender's account and updates the account balance after a successful transaction.
-
Transaction history:
- Allows users to view the history of completed transactions.
- Displays information about each transaction, including the date, the account of the sender and recipient, and the amount.
-
Account Management:
- Allows users to change their personal information such as address, password and other data.
- Provides the ability to remove a user account from the system.
-
Security and Authentication:
- Keeps user data secure with password encryption and other security measures.
- Implements an authentication and authorization mechanism to protect sensitive information and ensure transaction security.
-
Notices:
- Provides functionality to send notifications to users, such as via email, when certain events occur, such as a successful transaction or account data change.
-
Handling errors and exceptions:
- Provides error and exception handling to prevent crashes and ensure application stability.
- Sends appropriate error messages to users and provides information for diagnosing and fixing problems.
This AppConfig
file is the configuration class for the web controller application in the Spring Framework. It performs several tasks to set up a web application:
- It is annotated with
@Configuration
which tells Spring that this class provides the configuration for the Spring container. - It is annotated with
@ComponentScan
, indicating the base packages that Spring should scan to detect and register components (classes annotated with@Component
,@Controller
,@Service
, etc.). - It extends the
WebMvcConfigurationSupport
class, which allows you to customize the MVC configuration of the web application.
Within the AppConfig
class, the following methods are defined:
-
addResourceHandlers(ResourceHandlerRegistry registry)
: This method adds resource handlers that are responsible for serving static resources (eg CSS files, images, JavaScript files). This specifies the paths through which the resources will be available and the corresponding locations of the resources in the project. -
viewResolver()
: This method creates and sets up anInternalResourceViewResolver
which determines which JSP files will be used as views to display the data. It specifies the prefix and suffix for the location of the JSP files and usesJstlView
to display. -
addInterceptors(InterceptorRegistry registry)
: This method addsAppInterceptor
to the interceptor registry. Interceptors provide the ability to be embedded in the processing of HTTP requests and responses. In this case,AppInterceptor
will only apply to URLs starting with/app/
.
Thus, AppConfig
performs configuration tasks related to resources, views, and hooks for a Spring-based web application.
This MailConfig
file is a configuration class for configuring the sending of email in the Spring Framework. It defines a bean (component) that provides settings for sending email via JavaMailSender.
The MailConfig
class is defined in the com.demo_bank.config
package. The following method is defined inside the class:
-
getMailConfig()
: This method is a bean and returns an instance of theJavaMailSenderImpl
class that is used to send email. Inside the method, the following actions are performed:- An instance of
JavaMailSenderImpl
is created. - JavaMail properties are set via the
Properties
object. Here you can specify various settings for the protocol for sending mail, authentication and debugging. - Mailbox credentials such as host, port, username and password are set.
After all the settings are done, the generated
JavaMailSenderImpl
is returned as a bean that can be used to send email in the application. - An instance of
Thus, this MailConfig
defines the configuration for sending email, including protocol settings, credentials, and JavaMail properties. This allows the application to use JavaMailSenderImpl
to send emails.
This AdvisorController
file is an advisor controller in the Spring Framework. It performs certain tasks related to the request handling aspects of the application.
The AdvisorController
class is defined in the com.demo_bank.controler_advisor
package. The following method is defined inside the class:
-
getUserDefaults()
: This method is annotated with@ModelAttribute
to tell Spring that its result should be added to the model on every HTTP request. Here the method returns a new object of typeUser
.- The
User
object represents the user data model. - The
getUserDefaults()
method is used to provide default values for theUser
object in the model. This means that every time an HTTP request is processed, aUser
object will be added to the model with the given name"registerUser"
.
The purpose of this method may vary depending on the context of the application. It can be used, for example, to provide an empty
User
object when displaying a user registration form, to populate the fields with default values. - The
Thus, AdvisorController
is an aspect controller and its getUserDefaults()
method is used to add a User
object with the given name to the model on each HTTP request.
This AccountController
file is a web application controller in the Spring Framework. It is responsible for handling requests related to the management of bank accounts.
The AccountController
class is defined in the com.demo_bank.controllers
package. The following method is defined inside the class:
-
createAccount()
: This method is annotated with@PostMapping
and handles an HTTP POST request on the path/account/create_account
. It takes the following parameters from the request:account_name
: The name of the new bank account.account_type
: The type of the new bank account.redirectAttributes
: TheRedirectAttributes
object used to add the attributes to be passed in the redirect.session
: AnHttpSession
object representing the current user session.
Inside the method, the following actions are performed:
- Check for empty strings for
accountName
andaccountType
. If one of them is empty, then an error attribute is added and redirected to/app/dashboard
. - Getting the
User
object from the current session. - Generating a unique account number using
GenAccountNumber.generateAccountNumber()
. - Create a new bank account using
accountRepository.createBankAccount()
, passing in the user id, account number, name and account type. - Adding a success attribute and redirecting to
/app/dashboard
.
Thus, AccountController
provides the functionality to create a new bank account. It processes the POST request, validates the parameters, gets the user data from the session, generates a unique account number, and creates a new bank account in the database using accountRepository
.
This AppController
file is a web application controller in the Spring Framework. It is responsible for handling requests related to the functionality of the application, such as displaying the control panel, payment history, and transaction history.
The AppController
class is defined in the com.demo_bank.controllers
package. The following methods are defined inside the class:
-
getDashboard()
: This method handles a GET request to/app/dashboard
path and returns a model and a View to display the app's dashboard. Inside the method, the following actions are performed:- Getting the
User
object from the current session. - Getting a list of user's bank accounts with
accountRepository.getUserAccountsById()
. - Getting the total balance of a user's accounts with
accountRepository.getTotalBalance()
. - Create a
ModelAndView
object for the "dashboard" view. - Set model attributes for user account list and total balance.
- Return model and view.
- Getting the
-
getPaymentHistory()
: This method processes a GET request on the path/app/payment_history
and returns a model and a View to display the payment history. Inside the method, the following actions are performed:- Getting the
User
object from the current session. - Getting a list of user's payment history records using
paymentHistoryRepository.getPaymentRecordsById()
. - Create a
ModelAndView
object to represent "paymentHistory". - Setting the model attribute for the list of payment history records.
- Return model and view.
- Getting the
-
getTransactHistory()
: This method handles a GET request to/app/transact_history
and returns a Model and View to display the transaction history. Inside the method, the following actions are performed:- Getting the
User
object from the current session. - Getting a list of user's transaction history records with
transactHistoryRepository.getTransactionRecordsById()
. - Create a
ModelAndView
object to represent "transactHistory". - Setting the model attribute for the list of transaction history records.
- Return model and view.
- Getting the
So AppController
provides functionality to display control panel, payment history and transaction history. It processes the corresponding GET requests, receives the necessary data from the database using the appropriate repositories and passes it to the model for display in views.
This AuthController
file is the web application's authentication (authorization) controller in the Spring Framework. It is responsible for handling requests related to the process of logging in (login) and logging out (logout).
The AuthController
class is defined in the com.demo_bank.controllers
package. The following methods are defined inside the class:
-
getLogin()
: This method processes a GET request on the/login
path and returns a model and a View to display the login page. Inside the method, the following actions are performed:- Create a
ModelAndView
object for the "login" view. - Generating an authentication token with
Token.generateToken()
. - Set model attributes for token and page title.
- Return model and view.
- Create a
-
login()
: This method handles the POST request to the/login
path and performs the user authentication process. Inside the method, the following actions are performed:- Validation of input fields and form data.
- Checking if there is a user with the specified email address in the database.
- Compare the entered password with the hashed password from the database using
BCrypt.checkpw()
. - Checking the verification status of the user account.
- Retrieving user data from the database using
userRepository.getUserDetails()
. - Setting session attributes for the authenticated user and token.
- Redirect to the dashboard page.
-
logout()
: This method handles the GET request on the/logout
path and performs the user logout process. Inside the method, the following actions are performed:- Clearing the current session by calling
session.invalidate()
. - Add "logged_out" attribute to flash attributes (
RedirectAttributes
) to indicate successful logout. - Redirect to the login page.
- Clearing the current session by calling
Thus, AuthController
provides the functionality of user authentication, validation of user data, session management and redirects to the appropriate pages depending on the results of authentication or logout.
This IndexController
file is the controller for the main pages of a web application in the Spring Framework. It is responsible for handling requests related to the main page, error page, and account verification page.
The IndexController
class is defined in the com.demo_bank.controllers
package. The following methods are defined inside the class:
-
getIndex()
: This method handles a GET request on the path/
(root path) and returns the model and view (View) to display the main page. Inside the method, the following actions are performed:- Create a
ModelAndView
object for the "index" view. - Setting the model attribute for the page title.
- Return model and view.
- Create a
-
getError()
: This method handles a GET request on the path/error
and returns a model and a View to display the error page. Inside the method, the following actions are performed:- Create a
ModelAndView
object to represent "error". - Setting the model attribute for the page title.
- Return model and view.
- Create a
-
getVerify()
: This method handles the GET request on the/verify
path and is responsible for verifying the user account. Inside the method, the following actions are performed:- Creation of a
ModelAndView
object for the view that will display the result of the account verification. - Checking the passed token and verification code against the database using
userRepository.checkToken()
. - If the token is not valid, then an error page is returned with an expired session message.
- If the token is valid, then the
userRepository.verifyAccount()
method is called to update and verify the user account in the database. - The login page is returned with a message that the account was successfully verified.
- Creation of a
Thus, IndexController
is responsible for handling requests for the main page, error page, and account verification page. It sets the appropriate model and view attributes for displaying information on pages and performs the necessary actions to process queries and interact with the database.
This RegisterController
file is the controller for registering web application users in the Spring Framework. It is responsible for handling requests related to the registration of new users.
The RegisterController
class is defined in the com.demo_bank.controllers
package. The following methods are defined inside the class:
-
getRegister()
: This method processes a GET request on the path/register
and returns a model and a View to display the registration page. Inside the method, the following actions are performed:- Create a
ModelAndView
object for the "register" view. - Setting the model attribute for the page title.
- Return model and view.
- Create a
-
register()
: This method handles the POST request to/register
and registers a new user. Inside the method, the following actions are performed:- Create a
ModelAndView
object for the "register" view. - Check for validation errors (if any) and password matches.
- Token generation using
Token.generateToken()
. - Random code generation using the
Random
class. - Formation of the body of the e-mail using an HTML template.
- Password hashing using
BCrypt
. - Registering a user using
userRepository.registerUser()
, passing in the appropriate data (first name, last name, email, hashed password, token and code). - Sending email notification using
MailMessenger.htmlEmailMessenger()
. - Set model attribute to report successful registration.
- Return model and view.
- Create a
Thus, the RegisterController
is responsible for handling requests for the registration page and executing the process of registering a new user. It performs validations, generates tokens and codes, hashes passwords, registers the user in the database, and sends email notifications.
The TransactController
file is the web application controller and contains the request handlers associated with user transactions. It is responsible for processing deposits, funds transfers, cash withdrawals and payments.
Here is a brief description of each method in TransactController
:
-
Method
deposit
: Handles a request to make a deposit. It accepts parametersdeposit_amount
(deposit amount) andaccount_id
(account ID). Checks for errors and blanks, then updates the user's account balance, adds a transaction record, and redirects the user to the dashboard page (/app/dashboard
). -
Method
transfer
: Handles a request to transfer funds. It accepts parameterstransfer_from
(identifier of the account from which the transfer is made),transfer_to
(identifier of the account to which the transfer is made) andtransfer_amount
(transfer amount). Checks for errors and empty values, and also checks that there are enough funds in the account to complete the transfer. It then updates the balances of both accounts, adds a transaction record, and redirects the user to the dashboard page. -
Method
withdraw
: Processes the request for cash withdrawal. It acceptswithdrawal_amount
(withdrawal amount) andaccount_id
(account ID) parameters. Checks for errors and empty values, and also checks that there are enough funds in the account to complete the withdrawal. If all checks are successful, updates the account balance, adds a transaction record, and redirects the user to the control panel page. -
Method
payment
: Processes the request to make a payment. It accepts the parametersbeneficiary
(beneficiary),account_number
(account number of the beneficiary),account_id
(user account identifier),reference
(reference to the payment), andpayment_amount
(payment amount). Checks for errors and empty values, and also checks for sufficient funds in the account to complete the payment. If all checks pass, updates the account balance, adds a payment record and a transaction record, and redirects the user to the control panel page.
The controller uses several repositories (AccountRepository
, PaymentRepository
, TransactRepository
) that provide access to data and perform database operations. It also uses HttpSession
to get information about the current user, and RedirectAttributes
to add attributes that will be available after the user is redirected.
The GenAccountNumber
file contains a helper class for generating a random account number in a banking application.
The generateAccountNumber
method is static and returns an integer value. It uses the random number generator from the Random
class to generate a random number. This random number is then multiplied by the bound
value, which is 1000 in this case. This generates a random number between 0 and 999,000 (not including 999,000). This number is assigned to the accountNumber
variable, which is then returned as the result of the method execution.
Thus, calling the generateAccountNumber
method allows you to get a randomly generated account number in a banking application.
This HTML
file is a helper class for generating an HTML email template. It contains a htmlEmailTemplate
static method that takes two parameters: token
(token) of type String
and code
(code) of type int
.
The htmlEmailTemplate
method generates and returns a string representing an HTML email template. The template includes styling and markup to display the content of the email, including the company name, welcome text, and a button to verify your account.
The url
variable is created in the method, which contains the URL for verifying the account, including the token
and code
parameters.
Then an HTML template is formed that contains all the necessary content of the letter. The template includes CSS styles for styling email elements such as the background, font, and button.
Finally, the generated HTML template is stored in the emailTemplate
variable and returned as the result of the method execution.
Thus, calling the htmlEmailTemplate
method allows you to get a ready-made HTML template for creating an email containing a link to verify your account.
This Token
file is a helper class for generating tokens. It contains a static generateToken
method that returns a string representing the generated token.
The generateToken
method uses the UUID
class from the java.util
package to generate a unique identifier (token). The method calls the randomUUID()
static method, which creates a new UUID
object using random numbers. The toString()
method is then called to get the string representation of the generated token.
The resulting token is stored in the token
variable and returned as the result of the method execution.
Thus, calling the generateToken
method allows you to get a randomly generated unique token that can be used for various purposes, such as authentication, authorization, or object identification.
This AppInterceptor
file is the application's request interceptor. It implements the HandlerInterceptor
interface, which allows you to intercept and process requests before and after they are processed by controllers.
The AppInterceptor
class is also annotated with @Component
to indicate that it is a Spring Framework managed bean and will be automatically detected and used in the application.
The methods inside the AppInterceptor
class do the following:
-
preHandle
: This method is called before the request is processed by the controller. It checks the request URI and takes some action if the URI starts with/app
. Here are the following steps:- Getting the current session with
HttpServletRequest
. - Extracting a token from session attributes.
- Extracting the user object from session attributes.
- Checking for the presence of a token and a user object in the session.
- If the token or user object is not present, it redirects to the login page (
/login
).
- Getting the current session with
-
postHandle
: This method is called after the request has been processed by the controller, but before the result is returned to the client. In this case, the method simply prints a message to the console. -
afterCompletion
: This method is called when the request is completed and the result is returned to the client. In this case, the method also simply prints a message to the console.
Thus, AppInterceptor
is used to intercept requests related to /app
and check for the presence of authentication data in the session. If the data is missing, the user is redirected to the login page.
The MailMessenger
file is the class responsible for sending HTML emails via email. It contains the htmlEmailMessenger
method, which sends an HTML email.
Here is how this class works:
htmlEmailMessenger
: This method accepts the parameters needed to send the email, such as sender (from
), recipient address (toMail
), subject (subject
), and body (body
).JavaMailSender
: Inside the method, aJavaMailSender
object is created, which is the Spring Framework interface for sending email. The object is derived from theMailConfig
class, which provides the settings for sending mail.- Create
MimeMessage
: AMimeMessage
object is created, which is the message to be sent via email. - Create a
MimeMessageHelper
: AMimeMessageHelper
object is created that makes it easy to create a message and add various attributes to it. It binds toMimeMessage
to help customize the message. - Setting message attributes: The
htmlMessage
method is used to set message attributes such as recipient address (toMail
), sender address (from
), message subject (subject
) and body of the message (body
). The third argument to thesetText
method sets thetrue
flag to indicate that the body of the email is HTML. - Sending a message: The
send
method of theJavaMailSender
object is called to send the email.
Thus, the MailMessenger
class provides a convenient way to send HTML emails using the configuration provided by the MailConfig
class.
The Account
file represents a model class that represents a user's account in the system. It contains various fields and methods for accessing and setting the values of these fields. Here is an overview of the class functions:
-
@Entity
annotation: This annotation specifies that theAccount
class is the entity that will be mapped to the database. -
Class fields:
account_id
: Unique account identifier (field@Id
).user_id
: ID of the user associated with this account.account_number
: Account number.account_name
: Account name.account_type
: Account type.balance
: The balance of the account, represented by theBigDecimal
object for monetary precision.created_at
: Date and time the account was created.updated_at
: The date and time the account was last updated.
-
Access methods (getters and setters): For each field of the
Account
class, access methods are defined for getting and setting field values.- Getters (
get...()
): Methods that return field values. - Setters (
set...()
): Methods that set field values.
- Getters (
The Account
class provides a structure for storing user account information and provides access to this information through accessor methods. It is also used in connection with a database, where each Account
class object represents an account entry in a table.
The Payment
file represents a model class that represents payment information in the system. It contains various fields and methods for accessing and setting the values of these fields. Here is an overview of the class functions:
-
@Entity
annotation: This annotation specifies that thePayment
class is the entity that will be mapped to the database. -
Class fields:
payment_id
: Unique payment identifier (field@Id
).account_id
: Identifier of the account associated with this payment.beneficiary
: The name of the payee.beneficiary_acc_no
: The account number of the payee.amount
: Payment amount.reference_no
: Payment reference number.status
: Payment status.reason_code
: Payment reason code.created_at
: Date and time the payment was created.
-
Access methods (getters and setters): For each field of the
Payment
class, access methods are defined for getting and setting field values.- Getters (
get...()
): Methods that return field values. - Setters (
set...()
): Methods that set field values.
- Getters (
The Payment
class provides a structure for storing payment information and provides access to this information through accessor methods. It is also used in connection with a database, where each Payment
class object represents a payment entry in the table.
The PaymentHistory
file represents a model class that represents information about the history of payments in the system. It contains various fields and methods for accessing and setting the values of these fields. Here is an overview of the class functions:
-
@Entity
annotation: This annotation specifies that thePaymentHistory
class is the entity that will be mapped to the database. -
@Table(name = "v_payments")
annotation: This annotation points to the name of the table in the database to which thePaymentHistory
class will refer. -
Class fields:
payment_id
: Unique payment identifier (field@Id
).account_id
: Identifier of the account associated with this payment.user_id
: Identifier of the user associated with this payment.beneficiary
: The name of the payee.beneficiary_acc_no
: The account number of the payee.amount
: Payment amount.status
: Payment status.reference_no
: Payment reference number.reason_code
: Payment reason code.created_at
: Date and time the payment was created.
-
Access methods (getters and setters): For each field of the
PaymentHistory
class, access methods are defined for getting and setting field values.- Getters (
get...()
): Methods that return field values. - Setters (
set...()
): Methods that set field values.
- Getters (
The PaymentHistory
class provides a structure for storing payment history information and provides access to this information through accessor methods. It is also used in connection with a database, where each PaymentHistory
object represents a payment history entry in the v_payments
table.
The Transact
file represents a model class that describes a transaction in the banking system. It contains various fields and methods for accessing and setting the values of these fields. Here is an overview of the class functions:
-
@Entity
annotation: This annotation specifies that theTransact
class is an entity that will be mapped to the database. -
Class fields:
transaction_id
: Unique transaction ID (@Id
field).account_id
: ID of the account associated with this transaction.transaction_type
: Transaction type, e.g. "purchase", "transfer funds", etc.amount
: Amount of the transaction.source
: The source of the transaction, e.g. "internal account", "external account", etc.status
: Transaction status.reason_code
: Transaction reason code.created_at
: Date and time the transaction was created.
-
Access methods (getters and setters): For each field of the
Transact
class, access methods are defined for getting and setting field values.- Getters (
get...()
): Methods that return field values. - Setters (
set...()
): Methods that set field values.
- Getters (
The Transact
class provides a structure for storing information about transactions in the banking system and provides access to this information through accessor methods. It is also used in connection with a database, where each object of class Transact
represents a record of a transaction.
The TransactionHistory
file represents a model class that describes the history of transactions in the banking system. It contains various fields and methods for accessing and setting the values of these fields. Here is an overview of the class functions:
-
@Entity
annotation: This annotation specifies that theTransactionHistory
class is the entity that will be mapped to the database. -
@Table(name = "v_transaction_history")
annotation: This annotation specifies the name of the table in the database that theTransactionHistory
class is associated with. -
Class fields:
transaction_id
: Unique transaction ID (@Id
field).account_id
: ID of the account associated with this transaction.user_id
: ID of the user associated with this transaction.transaction_type
: Transaction type, e.g. "purchase", "transfer funds", etc.amount
: Amount of the transaction.source
: The source of the transaction, e.g. "internal account", "external account", etc.status
: Transaction status.reason_code
: Transaction reason code.created_at
: Date and time the transaction was created.
-
Access methods (getters and setters): For each field of the
TransactionHistory
class, access methods are defined for getting and setting field values.- Getters (
get...()
): Methods that return field values. - Setters (
set...()
): Methods that set field values.
- Getters (
The TransactionHistory
class provides a structure for storing the history of transactions in the banking system and provides access to this information through accessor methods. It is also used in connection with a database, where each TransactionHistory
object represents a transaction history record.
The User
file represents a model class that describes users in the banking system. It contains various fields and methods for accessing and setting the values of these fields. Here is an overview of the class functions:
-
@Entity
annotation: This annotation specifies that theUser
class is the entity that will be mapped to the database. -
Class fields:
user_id
: Unique user ID (field@Id
).first_name
: Username.last_name
: Last name of the user.email
: The user's email address (must match the email format).password
: User password.token
: User token.code
: User code.verified
: Flag indicating whether the user has been verified.verified_at
: The date the user was verified.created_at
: Date and time the user was created.updated_at
: The date and time the user information was last updated.
-
Annotations for validation:
@NotEmpty
: The field cannot be empty.@Size
: Limit on the length of the field value.@Email
: The field must match the email format.@Pattern
: The field must match the given regular expression.
-
Access methods (getters and setters): For each field of the
User
class, access methods are defined for getting and setting field values.- Getters (
get...()
): Methods that return field values. - Setters (
set...()
): Methods that set field values.
- Getters (
The User
class provides a structure for storing information about users in the banking system and provides access to this information through access methods. It is also used in connection with a database, where each User
object represents a user record.
The AccountRepository
file is a repository interface that defines methods for interacting with the database for the Account
entity. Here is an overview of the functions defined in the interface:
-
Annotation
@Repository
: Indicates that the interface is a repository component that provides access to data. -
CrudRepository<Account, Integer>
interface: Extends theCrudRepository
interface and defines basic methods for creating, reading, updating, and deleting records in the database for theAccount
entity. TheAccount
andInteger
parameter types indicate the entity type and the primary key type. -
Request methods:
getUserAccountsById(int user_id)
: Execute a database query to get a list of user bank accounts with the givenuser_id
.getTotalBalance(int user_id)
: Executes a database query to get the total balance of all user accounts with the givenuser_id
.getAccountBalance(int user_id, int account_id)
: Executes a database query to get the balance of a specific user account givenuser_id
andaccount_id
.changeAccountBalanceById(double new_balance, int account_id)
: Updates the balance of the given account by itsaccount_id
in the database.createBankAccount(int user_id, String account_number, String account_name, String account_type)
: Creates a new bank account for a user with the givenuser_id
,account_number
,account_name
andaccount_type
in the database.
-
Annotations:
@Query
: Specifies a database query using SQL or JPQL.@Modifying
: Indicates that the query modifies data in the database.@Param
: Used to bind method parameters to query parameters.
-
Annotation
@Transactional
: Indicates that the method should be executed within a transaction, which ensures data consistency when performing multiple operations.
The AccountRepository
interface provides an abstraction for performing various operations on the Account
entity data in the database, such as getting account information, updating balances, creating new accounts, and other operations. This interface allows you to interact with the database without requiring you to write SQL queries manually, but instead using annotated query methods.
The PaymentHistoryRepository
file is a repository interface that defines methods for interacting with the database for the PaymentHistory
entity. Here is an overview of the functions defined in the interface:
-
Annotation
@Repository
: Indicates that the interface is a repository component that provides access to data. -
CrudRepository<PaymentHistory, Integer>
interface: Extends theCrudRepository
interface and defines the basic methods for creating, reading, updating, and deleting records in the database for thePaymentHistory
entity. ThePaymentHistory
andInteger
parameter types indicate the entity type and the primary key type. -
Request methods:
getPaymentRecordsById(int user_id)
: Query the database to get a list of payment records for the user with the givenuser_id
.
-
Annotation
@Query
: Defines a database query using SQL or JPQL. -
@Param
annotation: Used to bind method parameters to query parameters.
The PaymentHistoryRepository
interface provides an abstraction for performing operations on the data of the PaymentHistory
entity in the database, such as getting payment records for a specific user. This interface allows you to interact with the database using an annotated query method rather than manually writing SQL queries.
The PaymentRepository
file is a repository interface that defines methods for interacting with the database for the Payment
entity. Here is an overview of the functions defined in the interface:
-
Annotation
@Repository
: Indicates that the interface is a repository component that provides access to data. -
CrudRepository<Payment, Integer>
interface: Extends theCrudRepository
interface and defines the basic methods for creating, reading, updating and deleting records in the database for thePayment
entity. ThePayment
andInteger
parameter types indicate the entity type and the primary key type. -
Request methods:
makePayment(...)
: Inserts a new payment record into the database with the given parameters, such asaccount_id
,beneficiary
,beneficiary_acc_no
,amount
,reference_no
,status
,reason_code
,created_at
.
-
Annotation
@Query
: Defines a database query using SQL or JPQL. -
Annotation
@Modifying
: Indicates that the method performs a modification request, such as inserting, updating, or deleting data. -
Annotation
@Param
: Used to bind method parameters to query parameters. -
Annotation
@Transactional
: Indicates that the method is executed within a transaction.
The PaymentRepository
interface provides an abstraction for performing operations on the data of the Payment
entity in the database, such as creating a new payment. This interface allows you to interact with the database using an annotated query method rather than manually writing SQL queries.
The TransactHistoryRepository
file is a repository interface that defines methods for interacting with the database for the TransactionHistory
entity. Here is an overview of the functions defined in the interface:
-
Annotation
@Repository
: Indicates that the interface is a repository component that provides access to data. -
CrudRepository<TransactionHistory, Integer>
interface: Extends theCrudRepository
interface and defines the basic methods for creating, reading, updating, and deleting records in the database for theTransactionHistory
entity. TheTransactionHistory
andInteger
parameter types indicate the entity type and the primary key type. -
Request methods:
getTransactionRecordsById(...)
: Fetches records from the database that match the specifieduser_id
and returns a list ofTransactionHistory
objects.
-
Annotation
@Query
: Defines a database query using SQL or JPQL. -
@Param
annotation: Used to bind method parameters to query parameters.
The TransactHistoryRepository
interface provides an abstraction for performing operations on the data of the TransactionHistory
entity in the database, such as getting the transaction history records for a particular user_id
. This interface allows you to interact with the database using an annotated query method rather than manually writing SQL queries.
The TransactRepository
file is a repository interface that defines methods for interacting with the database for the Transact
entity. Here is an overview of the functions defined in the interface:
-
Annotation
@Repository
: Indicates that the interface is a repository component that provides access to data. -
CrudRepository<Transact, Integer>
interface: Extends theCrudRepository
interface and defines the basic methods for creating, reading, updating, and deleting records in the database for theTransact
entity. TheTransact
andInteger
parameter types indicate the entity type and the primary key type. -
Request methods:
logTransaction(...)
: Inserts a new transaction record into thetransaction_history
table of the database. The method uses the@Modifying
,@Transactional
and@Query
annotations to define the SQL query to be executed. Method parameters are associated with query parameters using the@Param
annotation.
-
Annotation
@Modifying
: Indicates that the method performs a modifying operation (such as inserting, updating, or deleting data) on the database. -
Annotation
@Transactional
: Indicates that the method should be executed within a database transaction. -
Annotation
@Query
: Defines a database query using SQL or JPQL. -
@Param
annotation: Used to bind method parameters to query parameters.
The TransactRepository
interface provides an abstraction for performing operations on the data of the Transact
entity in the database, such as registering a new transaction in the transaction history. This interface allows you to interact with the database using an annotated query method rather than manually writing SQL queries.
The UserRepository
file is a repository interface that defines methods for interacting with the database for the User
entity. Here is an overview of the functions defined in the interface:
-
Annotation
@Repository
: Indicates that the interface is a repository component that provides access to data. -
CrudRepository<User, Integer>
interface: Extends theCrudRepository
interface and defines basic methods for creating, reading, updating, and deleting records in the database for theUser
entity. TheUser
andInteger
parameter types indicate the entity type and the primary key type. -
Request methods:
getUserEmail(...)
: Returns the user's email at the given email address.getUserPassword(...)
: Returns the password of the user at the given email address.isVerified(...)
: Returns a flag indicating whether the user has been verified for the given email address.getUserDetails(...)
: Returns the user information (all fields) for the given email address.registerUser(...)
: Registers a new user by inserting a new record into theusers
table of the database.verifyAccount(...)
: Verifies a user account by updating the appropriate fields in theusers
table.checkToken(...)
: Checks if the user's token exists in the database.
-
Annotation
@Modifying
: Indicates that the method performs a modifying operation (such as inserting, updating, or deleting data) on the database. -
Annotation
@Transactional
: Indicates that the method should be executed within a database transaction. -
Annotation
@Query
: Defines a database query using SQL or JPQL. -
@Param
annotation: Used to bind method parameters to query parameters.
The UserRepository
interface provides an abstraction for performing operations on the data of the User
entity in the database, such as getting user information, registering a new user, verifying an account, and other operations. This interface allows you to interact with the database using annotated query methods rather than manually writing SQL queries.
The RestAuthApiController
file is a REST API controller for user authentication. Here is an overview of its features:
-
Annotation
@RestController
: Indicates that the class is a REST API controller that processes HTTP requests and returns data in JSON format. -
Annotation
@RequestMapping("/api/auth")
: Sets the base path for all endpoints in this controller, which means that endpoints will be available at/api/auth
. -
@Autowired
annotation: Used to automatically wire (inject) theUserRepository
dependency into the controller. -
Field
private UserRepository userRepository
: TheUserRepository
repository that will be used to access user data. -
Method
validateUserEmail(...)
: Handles a GET request along the path/api/auth/login
. Accepts anemail
variable from the path and returns aResponseEntity
which contains the response and HTTP status.- Gets the user's email address by calling the
getUserEmail(...)
method of theUserRepository
repository. - Initializes the
userPassword
variable asnull
. - Checks if the received email address is valid.
- If the email address is valid, calls the
getUserPassword(...)
method of theUserRepository
repository to get the user's password. - Returns
ResponseEntity
with user password and HTTP statusHttpStatus.OK
. - If the email address is invalid, returns a
ResponseEntity
with a "User Not Found" message and an HTTP status ofHttpStatus.NOT_FOUND
.
- Gets the user's email address by calling the
This controller handles requests for user authentication at /api/auth/login
. It validates the user's email address and returns the corresponding password if the email address exists in the database. If the email address is not found, a "User Not Found" message is returned.
The RestTransactApiController
file is the REST API controller for transactions. At the moment it does not contain any methods or logic, only annotations and a class declaration. Here is a brief description of its functionality:
-
Annotation
@RestController
: Indicates that the class is a REST API controller that processes HTTP requests and returns data in JSON format. -
Annotation
@RequestMapping("/api/transact")
: Sets the base path for all endpoints in this controller, which means that endpoints will be available at/api/transact
.
This controller provides the basis for implementing transaction related functionality in the system. Later, you can add methods to this controller to handle transaction related requests, such as creating a transaction, getting transaction history, etc.
The DemoBankApplication
file represents the main Spring Boot application class. It contains the entry point to the application and the configuration to run the web server application. Here is a brief description of its functionality:
-
Annotation
@SpringBootApplication
: Denotes the main class of a Spring Boot application. She performs several roles:@Configuration
: Declares a class as a configuration source that allows you to define beans and other application settings.@EnableAutoConfiguration
: Automatically configures the application based on dependencies and classes in the classpath.@ComponentScan
: Scans packages to find and register components, services, and other Spring classes.
-
The
DemoBankApplication
class inherits fromSpringBootServletInitializer
, which allows you to use dependency injection and configure Spring Boot for a web application. -
configure()
method: Overrides theconfigure()
method fromSpringBootServletInitializer
to configure the application for deployment to the web server. It specifies thatDemoBankApplication
is the main class to deploy. -
Method
main()
: Entry point to the application. Runs a Spring Boot application withSpringApplication.run(DemoBankApplication.class, args)
.
The general function of DemoBankApplication
is to initialize and run a Spring Boot application to execute business logic and provide web services.
The application.properties
file contains the configuration parameters for the Spring Boot application. Here is a brief description of each line in the file:
-
spring.jpa.hibernate.ddl-auto=update
: This property determines how Hibernate will handle the database schema. The "update" value tells Hibernate to update the database schema as needed. -
spring.datasource.url=jdbc:mysql://localhost:3306/demo_bank
: Specifies the URL of the MySQL database to connect to. In this case, the local host (localhost) and port 3306 is used, with the demo_bank database. -
spring.datasource.username=root
: The username to connect to the MySQL database. -
spring.datasource.password=test
: Password to connect to the MySQL database. -
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
: Specifies the JDBC driver that will be used to connect to the MySQL database. -
spring.jpa.show-sql=true
: Specifies that Hibernate should output SQL queries to the console for debugging and analysis. -
server.address=127.0.0.1
: The IP address where the web server will run. -
server.port=8070
: The port on which the web server will run. -
server.error.whitelabel.enabled=false
: Disables the standard error page provided by Spring Boot and allows you to handle errors yourself.
The application.properties
file plays an important role in configuring the database connection, server configuration, and other parameters of a Spring Boot application.
The pom.xml
file is the main Maven project file and contains information about the project and its dependencies. Here is a brief description of each section of the file:
-
<modelVersion>4.0.0</modelVersion>
: Specifies the version of the POM. -
<parent>
: Specifies the parent project, in this casespring-boot-starter-parent
, which provides configuration and dependencies for the project. -
<groupId>com.demo_bank</groupId>
: The unique ID of the project group. -
<artifactId>DemoBank</artifactId>
: Artifact (project) ID. -
<name>DemoBank</name>
: Project name. -
<description>Easy Way Bank Application</description>
: Description of the project. -
<packaging>jar</packaging>
: Specifies the packaging format for creating an executable JAR file. -
<properties>
: Specifies the properties of the project, in this casejava.version
specifies the version of Java. -
<dependencies>
: Specifies project dependencies. Various dependencies are listed here, such asspring-boot-starter-data-jpa
,spring-boot-starter-mail
,spring-boot-starter-web
,mysql-connector-j
,spring- boot-starter-test
, and others. These dependencies allow you to use different functionality and libraries in your project. -
<build>
: Specifies the project's build configuration. In this case, thespring-boot-maven-plugin
plugin is used, which allows you to create an executable JAR file.
The pom.xml
file plays an important role in project dependency management, building, and configuration. Maven uses this file to define dependencies, build tasks, and other project settings.
The Bank Application project uses a database to store and manage data related to users, transactions, and other entities. The project uses MySQL as its database management system (DBMS).
Working with the database in the project is carried out using Spring Data JPA, which provides an abstraction for working with databases through the Java Persistence API (JPA). JPA allows developers to perform data operations such as save, update, delete, and read using an object-oriented approach rather than writing SQL queries by hand.
The project defines entities such as users (User) and transactions (Transaction) that correspond to tables in the database. Each entity is represented as a Java class with annotations that define mapping to a database table and relationships between tables.
To interact with the database, the project uses a repository (UserRepository), which extends the CrudRepository interface from Spring Data JPA. The repository provides methods to perform various data operations such as saving, searching, updating, and deleting. It also allows you to define custom queries using Query annotations.
Database settings such as URL, username, and password are specified in the application.properties file. Spring Boot automatically configures the database connection based on these settings when the application starts.
Working with the database in the "Bank Application" project allows you to save and retrieve data related to users and transactions, ensuring the integrity and constant access to information.
In the "Bank Application" project, error and exception handling is carried out using the mechanisms provided by the Spring Boot framework. Here are some ways to handle errors and exceptions in this project:
-
Global exception handler:
- A project can define a global exception handler that catches all unhandled exceptions in the application.
- A global exception handler can be implemented using the
@ControllerAdvice
annotation, which allows you to define a class that handles exceptions.
-
Specific exception handlers:
- You can define specific exception handlers to handle specific types of exceptions.
- This allows more precise and flexible handling of exceptions that may occur in different parts of the application.
-
Custom error messages:
- In the project, you can configure custom error messages that will be returned to clients when errors occur.
- This helps to improve the user experience and provide clear information about problems encountered.
-
Logging exceptions:
- An important aspect of error and exception handling is the logging of exceptions for subsequent diagnosis and troubleshooting.
- Exception logging can be configured in the project to write information about exceptions, including stack traces, to application logs.
-
Handling data validation errors:
- In the project, you can use the built-in data validation mechanisms provided by Spring to check the correctness of the data entered by the user.
- When validation errors occur, appropriate error messages can be returned indicating incorrect or invalid data.
All these error and exception handling mechanisms allow you to more reliably and safely manage possible errors in the "Bank Application" project. They help prevent crashes, ensure the stability of the application, and provide useful information to the user and developers when problems arise.
The "Bank Application" project uses the following libraries:
-
Spring Boot:
- Spring Boot is the main library on which the whole project is based.
- It provides a wide range of functionality for web application development, including dependency management, auto-configuration, database integration, and more.
- Spring Boot simplifies application development by providing a convenient and intuitive way to set up and run applications.
-
Spring Data JPA:
- Spring Data JPA provides an abstraction for working with databases through JPA (Java Persistence API).
- It simplifies database interaction by providing the ability to perform CRUD (Create, Read, Update, Delete) operations and execute queries using annotations or named methods of repository interfaces.
-
Spring Web:
- Spring Web provides functionality for developing web applications, including RESTful API support.
- It provides convenient tools for creating controllers, handling requests, passing data between client and server, and handling exceptions and errors.
-
MySQL Connector/J:
- MySQL Connector/J is the official JDBC (Java Database Connectivity) driver for working with the MySQL database.
- It provides the ability to connect to a MySQL database and perform operations on the data.
-
Spring Boot Starter Mail:
- Spring Boot Starter Mail provides mail service integration for sending emails.
- It allows you to configure email settings and send notifications or emails to users on certain events.
-
Spring Boot Starter Test:
- Spring Boot Starter Test provides tools for writing and running tests in a project.
- It includes various modules for unit testing, integration testing and REST API testing.
-
Hibernate Validator:
- Hibernate Validator is an implementation of the Bean Validation specification for data validation.
- It allows you to define validation rules for objects annotated with special annotations and check them for compliance with specified conditions.
-
Spring Security Crypto:
- Spring Security Crypto provides functionality to encrypt and hash data in a project.
- It allows you to ensure the security of user data, including passwords and other sensitive information.
These libraries are essential components of the "Bank Application" project and provide the necessary functionality to develop, test, and secure the application.