The Blog API is a Spring Boot application that provides RESTful endpoints for managing blog posts and user authentication.
- 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.
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"
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;
- Method: POST
- Endpoint: /api/v1/auth/signup
- Description: Register a new user.
- Request Body:
{ "username": "exampleUser", "email": "user@example.com", "password": "examplePassword", "role": "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.
- Spring Boot
- Spring Security
- JWT Authentication
- Docker
- MySQL
- Git
Before running the application, make sure you have the following software installed on your machine:
- Clone the repository:
git clone git@github.com:Kalunge/CRESWAVE_CODE_TEST.git
- Navigate to the project repository:
cd CRESWAVE_CODE_TEST
- Install dependencies
mvn install
- Get MySQL DB up and running:
docker-compose up -d
- Run the application:
mvn spring-boot:run
or run theBlogApiApplication
class
Link to Swagger Documentation: Link to the Swagger documentation for API reference.
Design Document: Link to the design document for technical decisions explainer, and further improvements proposals.