Skip to content

prince-shakyaa/RideShare_Springboot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RideShare Backend

A mini Ride Sharing backend built with Spring Boot, MongoDB, and JWT Authentication.

Technologies Used

  • Spring Boot 3.2.0
  • MongoDB
  • JWT Authentication
  • BCrypt Password Encoding
  • Jakarta Validation

Folder Structure

src/
 ├── main/
 │    ├── java/
 │    │     └── org/example/rideshare/
 │    │           ├── model/
 │    │           ├── repository/
 │    │           ├── service/
 │    │           ├── controller/
 │    │           ├── config/
 │    │           ├── dto/
 │    │           ├── exception/
 │    │           └── util/
 │    └── resources/
 │            └── application.properties

Entities

User

  • id : String
  • username : String
  • password : String (BCrypt encoded)
  • role : String (ROLE_USER / ROLE_DRIVER)

Ride

  • id : String
  • userId : String (Passenger FK)
  • driverId : String (Driver FK)
  • pickupLocation : String
  • dropLocation : String
  • status : String (REQUESTED / ACCEPTED / COMPLETED)
  • createdAt : Date

API Endpoints

Authentication (Public)

Register

POST /api/auth/register
Content-Type: application/json

{
  "username": "john",
  "password": "1234",
  "role": "ROLE_USER"
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "username": "john",
  "password": "1234"
}

Response:
{
  "token": "eyJhbGc...",
  "username": "john",
  "role": "ROLE_USER"
}

User Endpoints (Requires Authentication)

Request a Ride

POST /api/v1/rides
Authorization: Bearer <token>
Content-Type: application/json

{
  "pickupLocation": "Koramangala",
  "dropLocation": "Indiranagar"
}

Get My Rides

GET /api/v1/user/rides
Authorization: Bearer <token>

Driver Endpoints (Requires ROLE_DRIVER)

View Pending Ride Requests

GET /api/v1/driver/rides/requests
Authorization: Bearer <token>

Accept a Ride

POST /api/v1/driver/rides/{rideId}/accept
Authorization: Bearer <token>

Complete Ride (Both User/Driver)

POST /api/v1/rides/{rideId}/complete
Authorization: Bearer <token>

Setup Instructions

  1. Install MongoDB and start the service:
mongod
  1. Build the project:
mvn clean install
  1. Run the application:
mvn spring-boot:run

The application will start on http://localhost:8081

Testing with cURL

Register User

curl -X POST http://localhost:8081/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234","role":"ROLE_USER"}'

Register Driver

curl -X POST http://localhost:8081/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"driver1","password":"abcd","role":"ROLE_DRIVER"}'

Login

curl -X POST http://localhost:8081/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234"}'

Create Ride

curl -X POST http://localhost:8081/api/v1/rides \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"pickupLocation":"A","dropLocation":"B"}'

View Pending Requests (Driver)

curl -X GET http://localhost:8081/api/v1/driver/rides/requests \
-H "Authorization: Bearer <token>"

Accept Ride (Driver)

curl -X POST http://localhost:8081/api/v1/driver/rides/{rideId}/accept \
-H "Authorization: Bearer <token>"

Complete Ride

curl -X POST http://localhost:8081/api/v1/rides/{rideId}/complete \
-H "Authorization: Bearer <token>"

Get My Rides

curl -X GET http://localhost:8081/api/v1/user/rides \
-H "Authorization: Bearer <token>"

Features Implemented

  • ✅ User Registration with BCrypt password encoding
  • ✅ JWT-based Authentication
  • ✅ Role-based Authorization (ROLE_USER, ROLE_DRIVER)
  • ✅ Request a Ride (Passenger)
  • ✅ View Pending Ride Requests (Driver)
  • ✅ Accept Ride (Driver)
  • ✅ Complete Ride
  • ✅ User Gets Their Own Rides
  • ✅ Input Validation with Jakarta Validation
  • ✅ Global Exception Handling
  • ✅ Clean Architecture (Controller → Service → Repository)

Authors

Built with 💚 by Prince Shakya

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages