This API provides endpoints for managing vehicle registrations and related services in a car service platform. It includes JWT authentication for secure access.
To get started with this API, follow these steps:
- Clone this repository:
git clone https://github.com/your/repository.git cd repository-folder npm install
This API was created using Node.js, Express.js, MySQL, and Prisma ORM. It provides endpoints for user registration and login, as well as admin registration and login.
Registers a new user.
- Method: POST
- URL:
/api/auth/register
- Body:
- email (string, required): User's email address.
- password (string, required): User's password.
- first_name (string, required): User's first name.
- last_name (string, required): User's last name.
{
"email": "example_user@gmail.com",
"password": "password123",
"first_name": "example",
"last_name": "example",
"contact_no": "0123456789"
}
fetch("/api/auth/register", {
email: "example_user@gmail.com",
password: "password123",
first_name: "example",
last_name: "example",
contact_no: "0123456789",
})
- Status Code: 201
- Body:
Registers a new admin.
- Method: POST
- URL:
/api/auth/register/admin
- Body:
- secret (string, required): Secret key for admin registration.
- username (string, required): Admin's username.
- password (string, required): Admin's password.
{
"secret": "your secret",
"password": "password123",
"username": "example"
}
fetch("/api/auth/register", {
secret: "your secret",
password: "password123",
username: "example",
})
- Status Code: 201
- Body:
User login endpoint.
- Method: POST
- URL:
api/auth//login
- Body:
- email (string, required): User's email address.
- password (string, required): User's password.
{
"email": "example_user@gmail.com",
"password": "password123"
}
fetch("/api/auth/login", {
email: "example_user@gmail.com",
password: "password123",
})
- Status Code: 200
- Body:
Admin login endpoint.
- Method: POST
- URL:
api/auth/login/admin
- Body:
- username (string, required): Admin's username.
- password (string, required): Admin's password.
{
"username": "example_user",
"password": "password123"
}
fetch("/api/auth/login", {
username: "example_user",
password: "password123",
})
- Status Code: 200
- Body:
Retrieves vehicles belonging to a specific user.
id
: User ID (required)
Authorization
: Authorization header required.
- Code: 200 OK
- Content:
[ { ...vehicle data }, { ...vehicle data }, ...]
- Code: 401 Unauthorized
- Content: No user ID provided or invalid user ID.
Creates a new vehicle entry.
{
"userid": "<user id>",
"model": "Toyota",
"year": 2022,
"type": "SUV",
"number": "ABC1234"
}
Retrieves all services with associated users and vehicles.
- Code: 200 OK
- Content:
[ { ...service data, "user": { ...user data }, "vehicle": { ...vehicle data } }, ...]
Retrieves services associated with a specific user.
id
: User ID (required)
- Code: 200 OK
- Content:
[ { ...service data, "user": { ...user data }, "vehicle": { ...vehicle data } }, ...]
- Code: 400 Bad Request
- Content:
{ "msg": "Unauthorized!" }
Updates the status and total cost of a service.
{
"sid": "<service id>",
"status": "<new status>",
"total": "<new total>"
}
This contribution introduces new API routes and enhances the existing ones for better functionality and clarity. It adds routes for managing services, retrieving user-specific data, and updating service statuses. Additionally, it includes improvements in error handling and response messages.
Added routes for managing services (GET /services, GET /services/:id, PATCH /services/update, POST /services). Improved error handling and response messages for existing routes. Updated the README.md file with detailed documentation for the new routes using GitHub-flavored Markdown (GFM).
Clone the repository locally. Run the application using npm start. Test each API route using tools like Postman or cURL. Verify that the new routes function as expected and return the correct responses. Ensure that error handling works as intended for invalid requests or missing parameters.
This contribution addresses the issue #[issue_number] by implementing the required functionality and updating the documentation accordingly.
Include screenshots or GIFs demonstrating the usage of the new API routes if applicable.
Feel free to provide any additional information or instructions related to this contribution.