You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Star0 (0)You must be signed in to star a repository
About
Spring Boot REST API for a secondhand marketplace — user auth (JWT), ads/listings, chat/messaging, favorites, ratings, and category/city management, backed by SQLite
A secondhand goods marketplace backend built with Spring Boot 3.5.4 and Java, featuring JWT-based stateless authentication and a SQLite database. Users can list, browse, search, favorite, message about, and rate advertisements, with an admin role for moderation.
Tech Stack
Spring Boot (Web, Security, Validation)
Spring Security + JWT (jjwt) for stateless authentication
SQLite (sqlite-jdbc + Hibernate Community SQLite Dialect)
Maven
Getting Started
mvn spring-boot:run
The application uses a SQLite database file (secondhand.db), which is initialized at startup via DatabaseInitializer.
Authentication
Authentication is handled via JWT. The token must be sent in the Authorization header on protected requests.
The following endpoints are publicly accessible without a token:
POST /api/users/register
POST /api/users/login
GET /api/categories
GET /api/cities
All other endpoints require a valid JWT (anyRequest().authenticated() in SecurityConfig).
Admin-only actions are enforced inside each controller by checking the authenticated user's role (role == ADMIN), on top of the base authentication requirement.
📌 API Reference
1. User — /api/users (UserController)
Method
Endpoint
Description
Access
POST
/api/users/register
Registers a new user (username, password, phone, email, fullName) and returns a JWT
Public
POST
/api/users/login
Logs in with username/password and returns a JWT
Public
GET
/api/users/me
Returns the profile of the currently authenticated user
Returns all advertisements posted by a specific user
Authenticated*
POST
/api/ads
Creates a new advertisement (title, description, price, negotiable, categoryId, cityId, imagePaths)
Authenticated
PUT
/api/ads/{id}
Updates an advertisement
Authenticated (owner)
DELETE
/api/ads/{id}
Deletes an advertisement owned by the requester
Authenticated (owner)
POST
/api/ads/{id}/sold
Marks an advertisement as sold
Owner of the ad only
POST
/api/ads/{id}/approve
Approves a pending advertisement
Admin only
POST
/api/ads/{id}/reject
Rejects an advertisement (optional reason in the request body)
Admin only
GET
/api/ads/pending
Returns advertisements awaiting approval
Admin only
GET
/api/ads/search
Searches advertisements with filters (keyword, categoryId, cityId, minPrice, maxPrice)
Authenticated**
GET
/api/ads/admin/all
Returns all advertisements, including inactive/pending ones
Admin only
DELETE
/api/ads/{id}/admin
Deletes any advertisement (admin override)
Admin only
GET
/api/ads/admin/search
Searches advertisements for the admin panel (same filters as above)
Admin only
* These endpoints are not explicitly permitAll in SecurityConfig, so they require a valid token under the anyRequest().authenticated() rule, even though the controller logic itself doesn't check for a specific role.
** The principal is injected but currently unused for filtering results.
This README was written by directly inspecting the controller and security-config source code, and covers every endpoint currently exposed by the API.
About
Spring Boot REST API for a secondhand marketplace — user auth (JWT), ads/listings, chat/messaging, favorites, ratings, and category/city management, backed by SQLite