/Yoga-Class-Refactored

A Refactored Yoga Application

Primary LanguageJava

About

  • Backend application demo using Spring Boot
  • Application to manage Yoga classes
  • Refactored of old version

Tech Stack

  • Docker
  • PostgreSQL & pgAdmin
  • Java & Spring boot
  • Dependencies used:
    • Spring Boot DevTools
    • Spring Web
    • JDBC API
    • Spring Data JPA
    • PostgreSQL Driver
    • Validation
    • Spring Boot Actuator

Installation

  1. Clone Repository and open project in IDE
  2. Set up database
  3. Run application

Setting up database

  1. Start docker daemon os unix based systems or docker desktop on windows based systems.
  2. Change directory to root of project using cd /yoga-class-refactor/ then run Docker compose using docker compose up
  3. Open pgAdmin
  4. Set master password for pgAdmin
  5. Add a new server in pgAdmin:
    • Set server name in general tab
    • Set Host name/address in connection tab (get the address using command docker inspect postgres_container | grep IPAddress)
    • Set username = mustafa & password = 123456789 in connection tab
  6. Create database with name yoga-class-app

API Documentation

  1. Open Swagger to test CRUD operations
  2. Create operation
  3. Read operation
  4. Update operation
  5. Delete operation

Creating

  • Enter body in POST request then execute

image

  • Sample #1 Body
{
    "firstName": "Ahmad",
    "lastName": "Al-Deeb",
    "phone": "01211223344",
    "email": "ahmad@yahoo.com",
    "nationality": "Egyptian",
    "dateOfBirth": "2012-12-12",
    "role": "STUDENT"
}
  • Expected Response for Sample #1

image

  • Sample #2 Body
{
    "firstName": "Andrew",
    "lastName": "Seif",
    "phone": "01266778899",
    "email": "andrew@gmail.com",
    "nationality": "Egyptian",
    "dateOfBirth": "2000-01-10",
    "role": "INSTRUCTOR"
}
  • Expected Response for Sample #2

image

  • View results in database using below query in pgAdmin
SELECT id, first_name, last_name, role, email, phone, date_of_birth, nationality, created_by, created_date, last_modified_by, last_modified_date
FROM public.yoga_user;
id first_name last_name role email phone date_of_birth nationality created_by created_date last_modified_by last_modified_date
c65d94c8-0646-4803-98d6-dffdf122c824 Ahmad Al-Deeb STUDENT ahmad@yahoo.com 01211223344 2012-12-12 02:00:00 Egyptian Test User 2024-04-05 11:51:35.289056 Test User 2024-04-05 11:51:35.289056
914a4c5d-9916-4a07-a626-edc35dcc1226 Andrew Seif INSTRUCTOR andrew@gmail.com 01266778899 2000-01-10 02:00:00 Egyptian Test User 2024-04-05 11:52:17.970292 Test User 2024-04-05 11:52:17.970292

Reading

Reading One Uesr

  • Copy one user's id and use it to execute GET request

image

  • Expected Response

image

Reading All Users

  • Just execute GET request

image

  • Expected Response

image

Updating

  • Copy one user's id and use it to execute PUT request
  • Updating lastName & Role fields
{
    "lastName": "Deeb",
    "role": "INSTRUCTOR"
}

image

  • Expected Response

image

  • View results in database using below query in pgAdmin
SELECT id, first_name, last_name, role, email, phone, date_of_birth, nationality, created_by, created_date, last_modified_by, last_modified_date
FROM public.yoga_user;
id first_name last_name role email phone date_of_birth nationality created_by created_date last_modified_by last_modified_date
914a4c5d-9916-4a07-a626-edc35dcc1226 Andrew Seif INSTRUCTOR andrew@gmail.com 01266778899 2000-01-10 02:00:00 Egyptian Test User 2024-04-05 11:52:17.970292 Test User 2024-04-05 11:52:17.970292
c65d94c8-0646-4803-98d6-dffdf122c824 Ahmad Deeb INSTRUCTOR ahmad@yahoo.com 01211223344 2012-12-12 02:00:00 Egyptian Test User 2024-04-05 11:51:35.289056 Test User 2024-04-05 11:56:21.676482

Deleting

  • Copy one user's id and use it to execute DELETE request

image

  • Expected Response

image

  • View results in database using below query in pgAdmin
SELECT id, first_name, last_name, role, email, phone, date_of_birth, nationality, created_by, created_date, last_modified_by, last_modified_date
FROM public.yoga_user;
id first_name last_name role email phone date_of_birth nationality created_by created_date last_modified_by last_modified_date
914a4c5d-9916-4a07-a626-edc35dcc1226 Andrew Seif INSTRUCTOR andrew@gmail.com 01266778899 2000-01-10 02:00:00 Egyptian Test User 2024-04-05 11:52:17.970292 Test User 2024-04-05 11:52:17.970292