BlogEcho is a backend web application designed for managing blogs and user accounts, emphasizing robust authentication and authorization mechanisms.
BlogEcho provides a comprehensive platform for users to create, manage, and share blogs securely. Built using Java and Spring technologies, it ensures efficient data management and user interaction through RESTful APIs. The application integrates PostgreSQL for data storage and employs JWT (JSON Web Token) for secure user authentication.
- Blog Management: Allows users to create, update, retrieve, and delete blogs.
- User Management: Facilitates user registration, login, profile management, and deletion.
- Comment Management: Users can add, update, view, and delete comments on blogs.
- Authentication: Implements JWT-based authentication for secure user sessions.
- Validation: Utilizes Bean Validation (JSR 380) for input validation ensuring data integrity.
- Error Handling: Provides detailed error messages for validation errors, resource not found exceptions, and internal server errors.
- API Documentation: Utilizes Swagger (OpenAPI 3) for interactive API documentation and testing.
- Backend: Java, Spring Boot, Spring Security, Spring Data JPA
- Database: PostgreSQL
- Authentication: JWT (JSON Web Token)
- Validation: Bean Validation (JSR 380)
- API Documentation: Swagger (OpenAPI 3)
- Endpoint:
POST /api/blogs/create - Description: Creates a new blog with validated input data.
- Request Body:
BlogDto - Response: Returns a success message and created blog data.
- Endpoint:
PUT /api/blogs/update/{id} - Description: Updates an existing blog identified by
{id}. - Request Body:
BlogDto - Response: Returns a success message and updated blog data.
- Endpoint:
GET /api/blogs/{id} - Description: Retrieves a blog by its unique identifier
{id}. - Response: Returns blog details if found, or a "Not Found" message.
- Endpoint:
GET /api/blogs/all - Description: Retrieves a list of all blogs.
- Response: Returns a list of blog data.
- Endpoint:
DELETE /api/blogs/delete/{id} - Description: Deletes a blog identified by
{id}. - Response: Returns a success message upon successful deletion.
- Endpoint:
POST /api/user/create - Description: Registers a new user with optional OTP verification.
- Request Body:
UserDto - Response: Returns a success message and user data.
- Endpoint:
POST /api/user/login - Description: Authenticates a user and returns a JWT for accessing protected APIs.
- Request Body:
AuthenticationRequest - Response: Returns a JWT token for authenticated user sessions.
- Endpoint:
GET /api/user/all - Description: Retrieves a list of all registered users.
- Response: Returns a list of user data.
- Endpoint:
GET /api/user/id/{id} - Description: Retrieves user details by their unique identifier
{id}. - Response: Returns user details if found, or a "Not Found" message.
- Endpoint:
GET /api/user/username/{username} - Description: Retrieves user details by their username
{username}. - Response: Returns user details if found, or a "Not Found" message.
- Endpoint:
DELETE /api/user/delete/id/{id} - Description: Deletes a user identified by
{id}. - Response: Returns a success message upon successful deletion.
- Endpoint:
DELETE /api/user/delete/username/{username} - Description: Deletes users identified by
{username}. - Response: Returns a success message upon successful deletion.
- Endpoint:
POST /api/user/generate-otp - Description: Generates and sends an OTP to the user's registered email.
- Request Parameter:
email - Response: Returns a success message confirming OTP generation.
- Endpoint:
POST /api/user/verify-otp - Description: Verifies the OTP sent to the user's email for account activation.
- Request Body:
{ "email": "[email protected]", "otp_code": "123456" } - Response: Returns a success message upon successful OTP verification.
- Endpoint:
POST /api/comments/create - Description: Creates a new comment.
- Request Body:
{ "content": "This is a comment.", "authorId": 1, "blogId": 1 } - Response: Returns a success message and created comment data.
- Endpoint:
PUT /api/comments/update/{id} - Description: Updates an existing comment identified by
{id}. - Request Body:
{ "content": "This is an updated comment." } - Response: Returns a success message and updated comment data.
- Endpoint:
GET /api/comments/all - Description: Retrieves a list of all comments.
- Response: Returns a list of comment data.
- Endpoint:
GET /api/comments/{id} - Description: Retrieves a comment by its unique identifier
{id}. - Response: Returns comment details if found, or a "Not Found" message.
- Endpoint:
GET /api/comments/blog/{blogId} - Description: Retrieves comments by blog ID
{blogId}. - Response: Returns a list of comments for the specified blog.
- Endpoint:
GET /api/comments/author/{authorId} - Description: Retrieves comments by author ID
{authorId}. - Response: Returns a list of comments by the specified author.
- Endpoint:
DELETE /api/comments/delete/{id} - Description: Deletes a comment identified by
{id}. - Response: Returns a success message upon successful deletion.
The application provides detailed error handling for various scenarios, ensuring informative responses for validation errors, resource not found exceptions, and internal server errors. This helps in debugging and improving user experience.
- Database: Ensure PostgreSQL is installed and configured.
- Environment Variables: Set database credentials and JWT secret key.
- Build and Run: Use Maven or an IDE (e.g., IntelliJ IDEA, Eclipse) to build and run the Spring Boot application.
- Use tools like Postman or Swagger UI to interact with the APIs.
- Include proper authentication headers (JWT) for accessing protected APIs.
- Explore and test the functionality provided by each API endpoint.
- Suman Bisunkhe - Developer
This project is licensed under the MIT License. See the LICENSE file for details.