Work

TEnmo

Java
Spring Boot
PostgreSQL
RESTful API

Peer-to-peer money transfer application allowing users to send, request, and approve money transfers. Front end is a command-line application communicating with a RESTful API server in the back end.

TEnmo ERD diagram

TEnmo is an online payment service for transferring “TE Bucks” between friends.

Use cases

  1. As a user of the system, I need to be able to register myself with a username and password. A new registered user starts with an initial balance of 1,000 TE Bucks.
  2. As a user of the system, I need to be able to log in using my registered username and password. Logging in returns an Authentication Token. I need to include this token with all my subsequent interactions with the system outside of registering and logging in.
  3. As an authenticated user of the system, I need to be able to see my Account Balance.
  4. As an authenticated user of the system, I need to be able to send a transfer of a specific amount of TE Bucks to a registered user.
    1. I should be able to choose from a list of users to send TE Bucks to.
    2. I must not be allowed to send money to myself.
    3. A transfer includes the User IDs of the from and to users and the amount of TE Bucks.
    4. The receiver’s account balance is increased by the amount of the transfer.
    5. The sender’s account balance is decreased by the amount of the transfer.
    6. I can’t send more TE Bucks than I have in my account.
    7. I can’t send a zero or negative amount.
    8. A Sending Transfer has an initial status of Approved.
  5. As an authenticated user of the system, I need to be able to see transfers I have sent or received.
  6. As an authenticated user of the system, I need to be able to retrieve the details of any transfer based upon the transfer ID.

Use cases 2

  1. As an authenticated user of the system, I need to be able to request a transfer of a specific amount of TE Bucks from another registered user.
    1. I should be able to choose from a list of users to request TE Bucks from.
    2. I must not be allowed to request money from myself.
    3. I can’t request a zero or negative amount.
    4. A transfer includes the User IDs of the from and to users and the amount of TE Bucks.
    5. A Request Transfer has an initial status of Pending.
    6. No account balance changes until the request is approved.
    7. The transfer request should appear in both users’ list of transfers (use case #5).
  2. As an authenticated user of the system, I need to be able to see my Pending transfers.
  3. As an authenticated user of the system, I need to be able to either approve or reject a Request Transfer.
    1. I can’t “approve” a given Request Transfer for more TE Bucks than I have in my account.
    2. The Request Transfer status is Approved if I approve, or Rejected if I reject the request.
    3. If the transfer is approved, the requester’s account balance is increased by the amount of the request.
    4. If the transfer is approved, the requestee’s account balance is decreased by the amount of the request.
    5. If the transfer is rejected, no account balance changes.

Command-line screens:

Use case 3: Current balance

Your current account balance is: $9999.99

Use case 4: Send TE Bucks

-------------------------------------------
Users
ID          Name
-------------------------------------------
313         Moses
54          Stephen
---------

Enter ID of user you are sending to (0 to cancel):
Enter amount:

Use case 5: View transfers

-------------------------------------------
Transfers
ID          From/To                 Amount
-------------------------------------------
23          From: Moses            $ 903.14
79          To:  Stephen           $  12.55
---------
Please enter transfer ID to view details (0 to cancel): "

Use case 6: Transfer details

--------------------------------------------
Transfer Details
--------------------------------------------
 Id: 23
 From: Moses
 To: Michael
 Type: Send
 Status: Approved
 Amount: $903.14

Use case 7: Requesting TE Bucks

-------------------------------------------
Users
ID          Name
-------------------------------------------
313         Moses
54          Stephen
---------

Enter ID of user you are requesting from (0 to cancel):
Enter amount:

Use case 8: Pending requests

-------------------------------------------
Pending Transfers
ID          To                     Amount
-------------------------------------------
88          Moses                 $ 142.56
147         Stephen               $  10.17
---------
Please enter transfer ID to approve/reject (0 to cancel): "

Use case 9: Approve or reject pending transfer

1: Approve
2: Reject
0: Don't approve or reject
---------
Please choose an option:

Database schema:

Database schema

tenmo_user table

Stores the login information for users of the system.

FieldDescription
user_idUnique identifier of the user
usernameString that identifies the name of the user; used as part of the login process
password_hashHashed version of the user’s password
roleName of the user’s role

account table

Stores the accounts of users in the system.

FieldDescription
account_idUnique identifier of the account
user_idForeign key to the users table; identifies user who owns account
balanceThe amount of TE Bucks currently in the account

transfer_type table

Stores the types of transfers that are possible.

FieldDescription
transfer_type_idUnique identifier of the transfer type
transfer_type_descString description of the transfer type

There are two types of transfers:

transfer_type_idtransfer_type_descPurpose
1RequestIdentifies transfer where a user requests money from another user
2SendIdentifies transfer where a user sends money to another user

transfer_status table

Stores the statuses of transfers that are possible.

FieldDescription
transfer_status_idUnique identifier of the transfer status
transfer_status_descString description of the transfer status

There are three statuses of transfers:

transfer_status_idtransfer_status_descPurpose
1PendingIdentifies transfer that hasn’t occurred yet and requires approval from the other user
2ApprovedIdentifies transfer that has been approved and occurred
3RejectedIdentifies transfer that wasn’t approved

transfer table

Stores the transfers of TE Bucks.

FieldDescription
transfer_idUnique identifier of the transfer
transfer_type_idForeign key to the transfer_types table; identifies type of transfer
transfer_status_idForeign key to the transfer_statuses table; identifies status of transfer
account_fromForeign key to the accounts table; identifies the account that the funds are being taken from
account_toForeign key to the accounts table; identifies the account that the funds are going to
amountAmount of the transfer

Note: there are two check constraints in the DDL that creates the transfer table. Refer to tenmo.sql for these constraints.

Database setup:

database/tenmo.sql script available to set up the Postgres database called tenmo.

Datasource

Datasource configured in /src/resources/application.properties.

# datasource connection properties
spring.datasource.url=jdbc:postgresql://localhost:5432/tenmo
spring.datasource.name=tenmo
spring.datasource.username=postgres
spring.datasource.password=postgres1

JdbcTemplate

Refer to /src/main/java/com/techelevator/dao to see JdbcUserDao. This is an example of how to get an instance of JdbcTemplate in your DAOs. If you declare a field of type JdbcTemplate and add it as an argument to the constructor, Spring automatically injects an instance for you:

@Service
public class JdbcUserDao implements UserDao {

    private JdbcTemplate jdbcTemplate;

    public JdbcUserDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
}

Testing:

DAO integration tests

com.techelevator.dao.BaseDaoTests acts as a base class for any DAO integration test. It initializes a Datasource for testing and manages rollback of database changes between tests.

com.techelevator.dao.JdbUserDaoTests is an example for writing your own DAO integration tests.

When testing, a copy of the real database is used. The schema and data for the test database are defined in /src/test/resources/test-data.sql. The schema in this file matches the schema defined in database/tenmo.sql.

Authentication:

The user registration and authentication functionality for the system have been implemented. After successful authentication, an instance of AuthenticatedUser is stored in the currentUser member variable of App. The user’s authorization token—meaning JWT—can be accessed from App as currentUser.getToken().

References to “authenticated user” are requests that includes the token as a header. Other information about the current user can be referenced by using the User object retrieved from currentUser.getUser().

View GitHub Repository: TEnmo