Spring Boot REST API for location-aware user management with MySQL persistence, JWT authentication, and external medical-store discovery integration.
This project demonstrates a compact Spring Boot API for a pharmacy-link style service. It focuses on secure user registration and login, stores user coordinates, and delegates nearby-store and medicine-based search to a separate store-finder service through inter-service communication.
- Spring Boot REST API setup
- Spring Data JPA repository pattern
- MySQL-backed persistence
- Spring Security with JWT authentication
- Stateless session handling with a custom JWT filter
- Method-level authorization with
@PreAuthorize - PBKDF2 password encoding with configured pepper, iterations, and hash width
- Public user registration and token-based login flow
- Role-backed
UserDetailsintegration - Coordinate-aware user registration using
xCoordinateandyCoordinate - Admin-only user listing endpoint
- Inter-service communication using
RestTemplate - External medical-store lookup by distance and medicine name
- Java 17
- Spring Boot 2.7
- Spring Web
- Spring Data JPA
- Spring Security
- Spring Validation
- MySQL
- Maven
- Lombok
- JJWT
PharmaLinkTemplate/
├── CHANGELOG.md
├── README.md
├── pom.xml
├── mvnw
├── mvnw.cmd
└── src/
└── main/
├── java/com/CN/PharmaLink/
│ ├── communicator/
│ ├── config/
│ ├── controller/
│ ├── dto/
│ ├── exceptions/
│ ├── jwt/
│ ├── model/
│ ├── repository/
│ ├── security/
│ ├── service/
│ └── PharmaLinkApplication.java
└── resources/
└── application.yml
- Open a terminal in the project root.
- Replace the placeholder MySQL values in
src/main/resources/application.yml. - Ensure the companion store-finder service is available on
http://localhost:8081. - Run
mvn test. - Run
mvn spring-boot:run. - Register a user with
POST /user/register. - Obtain a JWT with
POST /auth/login. - Use the lookup endpoints to retrieve nearby stores or stores carrying a medicine.
Available endpoints:
POST /auth/loginGET /userPOST /user/registerGET /user/getNearestStores/{userId}/{distance}/{token}GET /user/getStoresWithMedicine/{medicine}/{token}
Access notes:
/user/registerand/auth/loginare publicGET /useris restricted toADMIN- store-finder lookup calls are proxied to an external service by the provided communicator
- newly registered users are currently assigned the
ROLE_ADMINauthority by the provided service logic
Example request body for registration:
{
"username": "john",
"password": "john123",
"xcoordinate": 120,
"ycoordinate": 340
}Example request body for login:
{
"username": "john",
"password": "john123"
}- Demonstrates JWT-secured Spring Boot APIs with stateless request authentication
- Shows how PBKDF2 password encoding can be configured explicitly for stronger credential handling
- Uses stored user coordinates as the basis for location-aware pharmacy discovery
- Introduces inter-service communication through a dedicated
RestTemplatecommunicator
- Suggested repository description:
Spring Boot REST API for location-aware user management with MySQL persistence, JWT authentication, and external medical-store discovery integration. - Suggested topics:
java,java-17,spring-boot,spring-security,spring-data-jpa,mysql,rest-api,jwt,location-based-services,pharmacy,resttemplate,microservices,maven,learning-project,portfolio-project