Package angry3vilbot.bankingapp
Class Api
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
angry3vilbot.bankingapp.Api
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
- Direct Known Subclasses:
CreateJar,Deposit,DepositJar,Login,Main,Send,SignUp,WithdrawJar
API class for the Banking Application.
This class handles the connection to the database and provides methods for user authentication,
sign up, deposit, withdraw, and other operations.
It uses JDBC to interact with a PostgreSQL database.
It also provides methods to create and manage jars, transactions, and deposit requests.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ConnectionTheConnectionobject that represents the connection to the database.private final StringThe URL of the database.private final StringThe password for the database connection.private PreparedStatementThePreparedStatementobject used to execute SQL queries.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidauthenticate(String login, char[] password) Checks the provided card number and password against the database.(package private) voidCreates a new jar for the user and saves it in the database.(package private) voiddeleteDepositRequest(int id) Deletes a deposit request from the database.(package private) voidDeposits money into the user's account using the Free Money feature.(package private) voiddeposit(BigDecimal payInfo, Double amount) Creates a deposit request for the user with thepayInfocard number and saves it in the database.(package private) voiddepositToJar(int id, double amount) Deposits money into a jar.(package private) voidfulfillDepositRequest(int id) Fulfills a deposit request by transferring money from the user's account to the target's account.(package private) DepositRequestgetDepositRequestData(int id) Retrieves the deposit request data for a given request ID.(package private) JargetJarData(int id) Retrieves the jar data for a given jar ID.(package private) TransactiongetTransactionData(int id) Retrieves the transaction data for a given transaction ID.(package private) voidsend(double amount, BigDecimal cardNumber, String name) Sends money from the user's account to another user's account.(package private) voidSigns up a new user by creating a new entry in the database.private voidStores the user data in theUserSession.(package private) voidupdate()Updates the user data in theUserSession.(package private) voidwithdrawFromJar(int id, double amount, boolean isBroken) Withdraws money from a jar.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
DATABASE_URL
The URL of the database. -
dbpassword
The password for the database connection. -
connection
TheConnectionobject that represents the connection to the database. -
pstat
ThePreparedStatementobject used to execute SQL queries.
-
-
Constructor Details
-
Api
public Api()
-
-
Method Details
-
authenticate
Checks the provided card number and password against the database. If the credentials are valid, it stores the user information in the UserSession.- Parameters:
login- the card number of the userpassword- the password of the user- Throws:
SQLException- if there is an error during the database operation
-
signUp
Signs up a new user by creating a new entry in the database. Generates a unique card number and stores the user information.- Parameters:
name- the name of the userpassword- the password of the user- Throws:
SQLException- if there is an error during the database operation
-
deposit
Creates a deposit request for the user with thepayInfocard number and saves it in the database.- Parameters:
payInfo- the card number of the user who receives the deposit requestamount- the amount of money to be deposited- Throws:
SQLException- if there is an error during the database operation
-
deposit
Deposits money into the user's account using the Free Money feature. This method adds the specified amount to the user's balance and creates a transaction for the operation.- Parameters:
amount- the amount of money to be deposited- Throws:
SQLException- if there is an error during the database operation
-
getTransactionData
Retrieves the transaction data for a given transaction ID. This method establishes a connection to the database, executes a query to get the transaction details, and creates aTransactionobject with the retrieved data.- Parameters:
id- the ID of the transaction to be retrieved- Returns:
- the
Transactionobject with the specified ID - Throws:
SQLException- if there is an error during the database operation
-
getDepositRequestData
Retrieves the deposit request data for a given request ID. This method establishes a connection to the database, executes a query to get the deposit request details, and creates aDepositRequestobject with the retrieved data.- Parameters:
id- the ID of the deposit request to be retrieved- Returns:
- the
DepositRequestobject with the specified ID - Throws:
SQLException- if there is an error during the database operation
-
getJarData
Retrieves the jar data for a given jar ID. This method establishes a connection to the database, executes a query to get the jar details, and creates aJarobject with the retrieved data.- Parameters:
id- the ID of the jar to be retrieved- Returns:
- the
Jarobject with the specified ID - Throws:
SQLException- if there is an error during the database operation
-
createJar
Creates a new jar for the user and saves it in the database. This method establishes a connection to the database, executes an insert query to create the jar, and updates the user's account by adding the new jar ID.- Parameters:
title- the title of the jargoal- the goal of the jar, null if there is no goal- Throws:
SQLException- if there is an error during the database operation
-
depositToJar
Deposits money into a jar. This method checks if the user has enough money to deposit. If they do, it subtracts the amount from the user's account, adds the amount to the jar, creates a transaction for the operation, and saves the transaction in the user's account.- Parameters:
id- the ID of the jar to be deposited intoamount- the amount of money to be deposited- Throws:
SQLException- if there is an error during the database operation
-
withdrawFromJar
Withdraws money from a jar. This method checks if the user has enough money in the jar to withdraw. If they do, it subtracts the amount from the jar, adds the amount to the user's account, creates a transaction for the operation, and saves the transaction in the user's account. If the user breaks the jar, it is deleted from the database.- Parameters:
id- the ID of the jar to withdraw fromamount- the amount of money to withdrawisBroken- true if the jar is being broken, false otherwise- Throws:
SQLException- if there is an error during the database operation
-
fulfillDepositRequest
Fulfills a deposit request by transferring money from the user's account to the target's account. This method checks if the user has enough money to fulfill the request. If they do, it subtracts the amount from the user's account, adds the amount to the target's account, creates transactions for both the user and the target, saves the transactions in their respective accounts, and deletes the request from the database.- Parameters:
id- the ID of the deposit request to be fulfilled- Throws:
SQLException- if there is an error during the database operation
-
deleteDepositRequest
Deletes a deposit request from the database. This method removes the request from the database and updates the user's account by removing the request ID.- Parameters:
id- the ID of the deposit request to be deleted- Throws:
SQLException- if there is an error during the database operation
-
send
Sends money from the user's account to another user's account. This method checks if the user has enough money to send. If they do, it subtracts the amount from the user's account, adds the amount to the target's account, creates transactions for both the user and the target, saves the transactions in their respective accounts, and updates the user data.- Parameters:
amount- the amount of money to be sentcardNumber- the card number of the target username- the name of the target user- Throws:
SQLException- if there is an error during the database operation
-
update
Updates the user data in theUserSession. This method retrieves the data of the current user from the database and stores it in theUserSession.- Throws:
SQLException- if there is an error during the database operation
-
storeUser
Stores the user data in theUserSession. Gets the transaction IDs, deposit request IDs, and jar IDs from theResultSet, and uses them to get the data needed to create the corresponding objects. It then stores a newUserobject in theUserSession.- Parameters:
resSet- theResultSetcontaining the user data- Throws:
SQLException- if there is an error during the database operation
-