Skip to content

Risspecct/Blog-Platform-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

21 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ Risspecct Blog Platform Backend

Java Spring Boot License Build

A secure, role-based blogging platform backend built with Spring Boot. Features include JWT authentication, user role hierarchy, and full CRUD operations for posts, comments, and likes.


๐Ÿš€ Features

  • Register & login with JWT authentication

  • Secure password hashing using BCrypt

  • Role-based access: VIEWER, AUTHOR, MOD, ADMIN

  • Users can:

    • Create, update, delete their posts
    • Comment on and like posts
    • View posts, comments, and own data
  • Moderators can delete any post or comment

  • Admins can manage users (ban, delete, assign roles)

  • Global exception handling with descriptive error messages

  • Clean DTO โ†” Entity mapping using MapStruct

  • Interactive Swagger UI for API testing and documentation


๐Ÿ“ Project Structure

risspecct-blog-platform-backend/
โ”œโ”€โ”€ Controllers/
โ”œโ”€โ”€ Entities/
โ”œโ”€โ”€ Dtos/
โ”œโ”€โ”€ Services/
โ”œโ”€โ”€ Repositories/
โ”œโ”€โ”€ Filters/
โ”œโ”€โ”€ Security/
โ”œโ”€โ”€ Exceptions/
โ”œโ”€โ”€ Mappers/
โ”œโ”€โ”€ Enums/
โ”œโ”€โ”€ postman/
โ”œโ”€โ”€ src/main/resources/

๐Ÿ” Roles & Permissions

Role Permissions
VIEWER View posts, comment, like
AUTHOR All of the above + create/edit/delete own posts
MOD All of the above + delete any post/comment
ADMIN Full access + manage users and assign roles

๐Ÿ“Œ API Endpoint Overview

โš–๏ธ Auth (/users)

  • POST /register โ€“ Register new user
  • POST /login โ€“ Authenticate and get JWT

๐Ÿ‘ค User (/users)

  • GET / โ€“ View own profile
  • PUT / โ€“ Update own profile
  • DELETE / โ€“ Delete own account
  • GET /comments โ€“ Get own comments
  • GET /all โ€“ (Admin) View all users

๐Ÿ“„ Posts (/posts)

  • POST / โ€“ (Author) Add post
  • GET /{id} โ€“ View specific post
  • PUT /{id} โ€“ (Author) Update own post
  • DELETE /{id} โ€“ (Author) Delete own post
  • GET /users/me/posts โ€“ View own posts
  • GET /users/{userId}/posts โ€“ View posts by user

๐Ÿ’ฌ Comments (/posts/{postId}/comments)

  • POST / โ€“ Add comment
  • GET / โ€“ Get all comments on a post
  • GET /{id} โ€“ Get single comment
  • PUT /{id} โ€“ Update own comment
  • DELETE /{id} โ€“ Delete own comment

โค๏ธ Likes (/posts/{postId})

  • POST /like โ€“ Like a post
  • GET /likes โ€“ Get like count
  • DELETE /like โ€“ Remove like

๐Ÿ›ก๏ธ Admin (/admin)

  • PUT /users/roles/{userId} โ€“ Assign roles
  • PUT /users/ban/{userId} โ€“ Ban/unban user
  • DELETE /users/delete/{userId} โ€“ Delete user

๐Ÿฉฐ Moderator (/mod)

  • DELETE /delete/posts/{postId} โ€“ Delete any post
  • DELETE /delete/comments/{commentId} โ€“ Delete any comment

๐Ÿ›ก๏ธ Security Highlights

  • Stateless JWT authentication
  • Role hierarchy: ADMIN > MOD > AUTHOR > VIEWER
  • @PreAuthorize annotations on secured routes
  • Custom exception handler for clean error responses

๐ŸŒฑ Tech Stack

  • Java 21
  • Spring Boot 3.4+
  • Spring Security
  • Spring Data JPA (Hibernate)
  • MySQL 8+
  • JWT (jjwt)
  • MapStruct
  • Lombok

๐Ÿ“š API Documentation

Use the โ€œAuthorizeโ€ button and provide Bearer <JWT> to test secured endpoints.


๐Ÿ› ๏ธ Setup & Run

Prerequisites

  • Java 21+
  • Maven
  • MySQL 8+

Steps

git clone https://github.com/your-username/risspecct-blog-platform-backend.git
cd risspecct-blog-platform-backend
cp src/main/resources/application.properties.example src/main/resources/application.properties
# edit DB and JWT settings in application.properties
./mvnw spring-boot:run

๐Ÿงช Testing

This project includes a comprehensive test suite for both the service and controller layers, using:

  • JUnit 5
  • Mockito
  • Spring Security Test

All tests run against an in-memory H2 database, ensuring they are:

  • Fast
  • Isolated
  • Do not affect your local MySQL data

Test Structure

โœ… Pure Unit Tests

@ExtendWith(MockitoExtension.class)
Used for service-layer testing to verify business logic without loading the Spring context.

๐ŸŒ Web Layer Slice Tests

@WebMvcTest
Used for controller-layer testing to verify:

  • Security rules (@PreAuthorize)
  • Role hierarchy
  • Request validation (@Valid)
  • Global exception handling

Running Tests

Action Command
Run all tests bash<br>./mvnw test
Build project without tests bash<br>./mvnw package -DskipTests

๐Ÿ”ฎ Postman Collection

Located at: postman/blog-platform-api.postman_collection.json

  1. Import into Postman
  2. Use /users/login to retrieve a JWT
  3. JWT auto-assigned to {{token}} for all requests

๐Ÿ“ƒ License

This project is licensed under the MIT License.


๐Ÿค Contributions

Pull requests are welcome. For major changes, please open an issue first to discuss what youโ€™d like to change.

About

A secure, role-based blogging backend built with Spring Boot, featuring JWT authentication, MapStruct, and global exception handling. Supports CRUD operations for posts, comments, and likes, with fine-grained role-based access control.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages