/book-fellow-backend-spring

A social media platform designed for book enthusiasts, it allows users to write detailed reviews and track the reading activities of others in the community.

Primary LanguageJavaMIT LicenseMIT

Book Fellow App

A Spring Boot-powered social media platform for book lovers, enabling users to write reviews, curate favorite lists, and follow the reading activities of fellow readers.

Built With

Development

Create an .env file in the root directory of the project and add the following environment variables:

SPRING_PROFILES_ACTIVE=dev
POSTGRES_DB=<database_name>
POSTGRES_USER=<database_user>
POSTGRES_PASSWORD=<database_user_password>
DEV_SERVER_PORT=8080
DEV_DATASOURCE_URL=jdbc:postgresql://localhost:5432/<database_name>
DEV_DATASOURCE_USERNAME=<database_user>
DEV_DATASOURCE_PASSWORD=<database_user_password>
JWT_SECRET=<jwt_secret_key>

Getting Started Locally

  1. Initialize the PostgreSQL database:

    docker compose up -d
  2. Build and run the application:

    ./gradlew build
    ./gradlew bootRun
  3. [Optional] Prune the database:

    docker compose down -v

The application setup includes an initial admin user with credentials:

username: admin@test.com
password: adminpassword

API Quickstart

Base URL:

http://localhost:8080/api/v1

The following endpoints are available post-deployment:

  • Sign Up: /auth/signup
  • Sign In: /auth/signin
  • Refresh Token: /auth/refresh
  • Sample Admin Endpoint: /admin (requires 'ADMIN' role)
  • Sample User Endpoint: /user (requires 'USER' role)

Use the JWT token returned by the /auth/signin endpoint to access the /admin and /user endpoints.

Authenticate by providing the JWT obtained from /auth/signin. Refresh tokens can be acquired via /auth/refresh.

Detailed Authentication Workflow

Endpoints for authentication services:

  • POST /auth/signup: Register a new user.

    {
    "firstName": "<firstName>",
    "lastName": "<lastName>",
    "email": "<email>",
    "password": "<password>"
    }
  • POST /auth/signin: Login and receive an access token.

    {
    "email": "<email>",
    "password": "<password>"
    }

    Response:

    {
    "token": "<token>",
    "refreshToken": "<refreshToken>"
    }
  • POST /auth/refresh: Refresh an access token.

    {
      "token": "<refreshToken>"
    }

    Response:

    {
    "token": "<token>",
    "refreshToken": "<refreshToken>"
    }

API Reference

Access the OpenAPI documentation at:

http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config`

Testing

For unit testing, run the following command:

./gradlew test

For API testing, a Postman collection is provided: Postman Collection

Ensure that the following environment variables are set: Environment

Pre-request scripts are provided to automate the process of obtaining a JWT token and refreshing it.

License

This project is licensed under the MIT License.