Blog API

The Blog API is a Spring Boot application that provides RESTful endpoints for managing blog posts and user authentication.

Features

  • User Authentication: Users can register, login, and manage their profiles.
  • Blog Post Management: Authenticated users can create, read, update, and delete blog posts.
  • Role-Based Access Control (RBAC): Administrators have additional privileges, such as deleting posts.

Data Model

erDiagram
    USERS {
        id INT
        username VARCHAR
        email VARCHAR
        password VARCHAR
        role ENUM
    }

    POSTS {
        id INT 
        userId INT 
        title VARCHAR
        content TEXT
    }

    COMMENTS {
        id INT 
        postId INT 
        userId INT 
        content TEXT
    }

    USERS ||--o{ POSTS : "Creates"
    USERS ||--o{ COMMENTS : "Posts"
    COMMENTS ||--o{ POSTS : "Belongs to"

Loading

User Flow Diagram

graph TD;
    A[Register] -->|Success| B[Login];
    B -->|Success| C[Create Post];
    C -->|Success| D[Get All Posts];
    D -->|Success| E[Get Post by ID];
    E -->|Success| F[Update Post];
    F -->|Success| G[Delete Post];
    B -->|Success| H[Get User Profile];
    H -->|Success| I[Update User Profile];
    H -->|Success| J[Delete User Profile];
    C -->|Failure| K[Error];
    D -->|Failure| K[Error];
    E -->|Failure| K[Error];
    F -->|Failure| K[Error];
    G -->|Failure| K[Error];
    H -->|Failure| K[Error];
    I -->|Failure| K[Error];
    J -->|Failure| K[Error];
    K -->|Retry| B;

Loading

Auth Endpoints:

Register User

  • Method: POST
  • Endpoint: /api/v1/auth/signup
  • Description: Register a new user.
  • Request Body:
    {
        "username": "exampleUser",
        "email": "user@example.com",
        "password": "examplePassword",
        "role": "user"
    }
    

Login User

  • Method: POST
  • Endpoint: /api/v1/auth/signin
  • Description: Login a user.
  • Request Body:
    {
        "username": "exampleUser",
        "password": "examplePassword"
    }
  • Response:
{
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}
  • other endpoints can be found in the linked Swagger documentation page.

Technologies Used

  • Spring Boot
  • Spring Security
  • JWT Authentication
  • Docker
  • MySQL
  • Git

Prerequisites

Before running the application, make sure you have the following software installed on your machine:

Setup instructions

  1. Clone the repository: git clone git@github.com:Kalunge/CRESWAVE_CODE_TEST.git
  2. Navigate to the project repository: cd CRESWAVE_CODE_TEST
  3. Install dependencies mvn install
  4. Get MySQL DB up and running: docker-compose up -d
  5. Run the application: mvn spring-boot:run or run the BlogApiApplication class

Documentation

Link to Swagger Documentation: Link to the Swagger documentation for API reference.

Design Document

Design Document: Link to the design document for technical decisions explainer, and further improvements proposals.