Finance-Api 💻

TechnologiesGetting StartedAPI EndpointsContribute

An API that controls daily income and expenses from a user!

💻 Technologies

  • Java
  • Springboot
  • Mysql

🚀 Getting started

Prerequisites

  • Java Development Kit (JDK)

Setting Up the Project

  1. Clone the Repository

    git clone https://github.com/luizfiliperm/finance-api.git
  2. Make sure to create a MYSQL database and configure the path, login and password at the application.properties file

  3. Navigate to the project directory

    cd <project-directory>

Running the Project

  1. Build the project
     .\mvnw clean install
  2. Run the application
    .\mvnw spring-boot:run

📍API Endpoints

The route pattern is: [localhost:8080/finances/**]()
Route Description
POST auth/register Registers a new user. details
POST auth/login Authenticates a user. details
PUT /users Updates logged user information. details
DELETE /users Delete logged user. details
GET /wallet Retrieve wallet info. details
POST /wallet/incomes Add a new Income. details
GET /wallet/incomes Find All Incomes. details
DELETE /wallet/incomes/{id} Delete a Income By Id. details
PUT /wallet/incomes/{id} Update a Income By Id. details
POST wallet/categories Create a new category. details
GET wallet/categories Get All Categories. details
GET /categories/{id} Retrieve a category by Id. details
PUT /categories/{id} Update a category by Id. details
DELETE /categories/{id} Delete a category by Id. details
POST /wallet/expenses Add a new Expense. details
GET /wallet/expenses Find All Expenses. details
DELETE /wallet/expenses/{id} Delete an Expense By Id. details
PUT /wallet/expenses/{id} Update an Expense By Id. details
GET /admin/users Find All Users. details

🔒Auth Endpoints

Register

Registers a new user and returns the user data and the JWT Token

Request Body

Parameter Type Description Required
name string Name of the user Yes
email string Email address of the user Yes
password string Password for the user account Yes
personalInformation object Additional personal information Yes
personalInformation.phoneNumber string Phone number of the user Yes
personalInformation.birthDate string Birth date of the user Yes
personalInformation.nationality string Nationality of the user Yes

Login

Registers a new user and returns the user data and the JWT Token

  • URL: /auth/login
  • Method: POST
  • Authentication: Not required
Parameter Type Description Required
email string Email address of the user Yes
password string Password for the user account Yes

Response (same for register and login)

  • 200 OK
    • Content: JSON
    {
       "user": {
         "id": 1,
         "name": "user",
         "email": "luiz@example.com",
         "role": "ROLE_USER",
         "personalInformation": {
           "phoneNumber": "123456789",
           "birthDate": "17/04/2004",
           "nationality": "Brazilian"
         },
         "wallet": {
           "balance": 0
         }
       },
       "token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJsdWl6QGV4YW1wbGUuY29tIiwiaWF0IjoxNzEwMzI0MTMwLCJleHAiOjE3MTA0MTA1MzB9.DwKfj34-QXttfAqDtlRIuksuQ8loXIbI7R7O64MkJkA"
    }

Update User

Updates the logged User

  • URL: /users
  • Method: PUT
  • Authentication: Logged

Request Body

Parameter Type Description Required
name string Name of the user Yes
currentPassword string Current password for verification Yes
newPassword string New password for the user Yes
personalInformation object Additional personal information Yes
personalInformation.phoneNumber string Phone number of the user Yes
personalInformation.birthDate string Birth date of the user Yes
personalInformation.nationality string Nationality of the user Yes

Response

  • 200 OK
    • Content: Json
    {
       "id": 4,
       "name": "Luiz Filipe",
       "email": "luiz@example.com",
       "role": "ROLE_USER",
       "personalInformation": {
         "phoneNumber": "123456729",
         "birthDate": "17/04/2004",
         "nationality": "Brazilian"
       },
       "wallet": {
         "balance": 0.00
       }
     }

Delete Logged User

Deletes the currently logged-in user.

  • URL: /users
  • Method: DELETE
  • Authentication: Required

Request Body

This endpoint does not require a request body.

Responses

  • 204 No Content

Get Users Wallet

Retrieves the wallet balance of the currently logged-in user.

  • URL: /wallet
  • Method: GET
  • Authentication: Required

Request Body

This endpoint does not require a request body.

Responses

  • 200 OK
    • Content: JSON
    {
      "balance": 0.00
     }

💵Income Endpoints

Add Income to Wallet

Adds a new income to the wallet of the logged-in user.

Request Body

Parameter Type Description Required
name string Name of the income Yes
amount number Amount of the income Yes
incomeType string Type of income ('monthly' or 'sporadic') Yes
dateTime string Date and time of the income (format: dd/MM/yyyy HH:mm) Yes

Response

  • 200 OK
    • Content: Json
     {
       "id": 8,
       "name": "Monthly salary",
       "amount": 1330.50,
       "incomeType": "MONTHLY",
       "dateTime": "13/03/2024 11:00"
     }

Get Income List

Query Parameters

Parameter Type Description Required Default
pageNo number Page number for pagination No 0
pageSize number Number of items per page No 10
sortBy string Field to sort the results No dateTime
sortDir string Sorting direction ('asc' or 'desc') No desc

Response

  • 200 OK
    • Content: Json
     {
       "content": [
         {
           "id": 8,
           "name": "Monthly salary",
           "amount": 1330.50,
           "incomeType": "MONTHLY",
           "dateTime": "13/03/2024 11:00"
         }
       ],
       "pageNo": 0,
       "pageSize": 10,
       "totalElements": 1,
       "totalPages": 1,
       "last": true
     }

Delete Income

Deletes the specified income from the wallet of the logged-in user.

Path Parameters

Parameter Type Description Required
incomeId number ID of the income to delete Yes

Responses

  • 204 No Content

Update Income

Updates the details of the specified income in the wallet of the logged-in user.

Path Parameters

Parameter Type Description Required
IncomeId number ID of the income to update Yes

Request Body

Parameter Type Description Required
name string New name of the income Yes
amount number New amount of the income Yes
incomeType string New type of income ('monthly' or 'sporadic') Yes
dateTime string New date and time of the income (format: dd/MM/yyyy HH:mm) Yes

Response

  • 200 OK
    • Content: Json
     {
        "id": 9,
        "name": "Monthly salary",
        "amount": 1230.50,
        "incomeType": "MONTHLY",
        "dateTime": "11/03/2024 20:57"
     }

📕Category Endpoints

Add Category to Wallet

Request Body

Parameter Type Description Required
name string Name of the category Yes
description string Description of the category Yes

Responses

  • 200 OK
    • Content: Json
     {
       "id": 8,
       "name": "Games",
       "description": "Anything that I buy related to games"
     }

Get Category List

Retrieves a list of categories from the wallet of the logged-in user.

Query Parameters

Parameter Type Description Required Default
pageNo number Page number for pagination No 0
pageSize number Number of items per page No 10
sortBy string Field to sort the results No id
sortDir string Sorting direction ('asc' or 'desc') No asc

Response

  • 200 OK
    • Content: Json
    {
       "content": [
         {
           "id": 8,
           "name": "Games",
           "description": "Anything that I buy related to games"
         }
       ],
       "pageNo": 0,
       "pageSize": 10,
       "totalElements": 1,
       "totalPages": 1,
       "last": true
     }

Get Category by ID

Retrieves the details of a specific category from the wallet of the logged-in user.

Path Parameters

Parameter Type Description Required
categoryId number ID of the category Yes

Response

  • 200 OK
    • Content: Json
     {
       "id": 8,
       "name": "Games",
       "description": "Anything that I buy related to games"
     }

Update Category

Updates the details of a specific category in the wallet of the logged-in user.

Path Parameters

Parameter Type Description Required
categoryId number ID of the category Yes

Request Body

Parameter Type Description Required
name string New name of the category Yes
description string New description of the category Yes

Delete Category by Id

Deletes the specified category from the wallet of the logged-in user.

Path Parameters

Parameter Type Description Required
categoryId number ID of the category Yes

Response

  • 204 No Content

💸Expense Endpoints

Add expense to Wallet

Adds a new expense to the wallet of the logged-in user.

Request Body

Parameter Type Description Required
name string Name of the expense Yes
amount number Amount of the expense Yes
paymentMethod string Payment method ('Debit' or 'Credit') Yes
dateTime string Date and time of the expense (format: dd/MM/yyyy HH:mm) Yes
categoryId number ID of the category for the expense Yes

Responses

  • 200 OK
    • Content: Json
    {
       "id": 5,
       "name": "Dark souls 3",
       "amount": 180,
       "paymentMethod": "DEBIT",
       "dateTime": "12/03/2024 10:00",
       "category": {
         "id": 8,
         "name": "Games",
         "description": "Anything that I buy related to games"
       }
     } 

Get Expense List

Retrieves a list of expenses from the wallet of the logged-in user.

Query Parameters

Parameter Type Description Required Default
pageNo number Page number for pagination No 0
pageSize number Number of items per page No 10
sortBy string Field to sort the results No dateTime
sortDir string Sorting direction ('asc' or 'desc') No desc

Response

  • 200 OK
    • Content: Json
    {
       "content": [
         {
           "id": 5,
           "name": "Dark souls 3",
           "amount": 180.00,
           "paymentMethod": "DEBIT",
           "dateTime": "12/03/2024 10:00",
           "category": {
             "id": 8,
             "name": "Games",
             "description": "Anything that I buy related to games"
           }
         }
       ],
       "pageNo": 0,
       "pageSize": 10,
       "totalElements": 1,
       "totalPages": 1,
       "last": true
     }

Delete Expense

Deletes the specified expense from the wallet of the logged-in user.

Path parameters

Parameter Type Description Required
expenseId number ID of the expense Yes

Response

  • 204 No content

Update Expense

Updates the details of a specific expense in the wallet of the logged-in user.

Path Parameters

Parameter Type Description Required
expenseId number ID of the expense Yes

Request Body

Parameter Type Description Required
name string New name of the expense Yes
amount number New amount of the expense Yes
paymentMethod string New payment method ('Debit' or 'Credit') Yes
dateTime string New date and time of the expense (format: dd/MM/yyyy HH:mm) Yes
categoryId number New ID of the category for the expense Yes

Response

  • 200 OK
    • Content: Json
    {
       "id": 5,
       "name": "Dark souls 2",
       "amount": 180,
       "paymentMethod": "DEBIT",
       "dateTime": "12/03/2024 10:00",
       "category": {
         "id": 8,
         "name": "Games",
         "description": "Anything that I buy related to games"
       }
     }

🔐Admin endpoints

Get User List (Admin)

Retrieves a list of users with administrator privileges.

  • URL: /admin/users
  • Method: Get
  • Authentication: Required(ROLE_MANAGER)

Query Parameters

Parameter Type Description Required Default
pageNo number Page number for pagination No 0
pageSize number Number of items per page No 10
sortBy string Field to sort the results No id
sortDir string Sorting direction ('asc' or 'desc') No asc

Response

  • 200 OK
    • Content: Json
     {
       "content": [
         {
           "id": 1,
           "name": "Luiz Filipe",
           "email": "admin@example.com",
           "role": "ROLE_MANAGER",
           "personalInformation": {
             "phoneNumber": "123456729",
             "birthDate": "17/04/2004",
             "nationality": "Brazilian"
           },
           "wallet": {
             "balance": 3965.93
           }
         },
         {
           "id": 3,
           "name": "user",
           "email": "user@example.com",
           "role": "ROLE_USER",
           "personalInformation": {
             "phoneNumber": "123456789",
             "birthDate": "17/04/2004",
             "nationality": "Brazilian"
           },
           "wallet": {
             "balance": 0.00
           }
         },
         {
           "id": 4,
           "name": "Luiz Filipe",
           "email": "luiz@example.com",
           "role": "ROLE_USER",
           "personalInformation": {
             "phoneNumber": "123456729",
             "birthDate": "17/04/2004",
             "nationality": "Brazilian"
           },
           "wallet": {
             "balance": 1050.50
           }
         }
       ],
       "pageNo": 0,
       "pageSize": 3,
       "totalElements": 3,
       "totalPages": 1,
       "last": true
     }

📫 Contribute

Feel Free to contribute to our project! Follow these steps:

  1. git clone https://github.com/luizfiliperm/finance-api.git
  2. git checkout -b feature/NAME
  3. Make your changes and commits. Be sure to adhere to our contribution guidelines, if available.
  4. Push your branch to GitHub: git push origin feature/NAME
  5. Open a Pull Request explaining the problem solved or feature made, if exists, append screenshot of visual modifications and wait for the review!

Thank you for contributing!