Skip to content

DonAnthonny/first-task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Service Request API

A simple backend API for a Service Request system where users can authenticate, update their location and online status, and find nearby active service providers.


Features

  • User login with phone number and password (JWT authentication)
  • Service provider location and online status update
  • Fetch list of active nearby service providers based on geographic proximity

API Endpoints

1. User Login

POST /api/login

Request body:

{
  "phone": "09120000000",
  "password": "123456"
}

Response:

{
  "token": "JWT_AUTH_TOKEN"
}

2. Update Provider Location and Status

POST /api/provider/location/update

Headers:

Authorization: Bearer <JWT_AUTH_TOKEN>

Request body:

{
  "lat": 35.7001,
  "lng": 51.4099,
  "is_online": true
}

Response:

{
  "msg": "Location updated",
  "user": {
    "phone": "09120000000",
    "lat": 35.7001,
    "lng": 51.4099,
    "is_online": true
  }
}

3. Get Nearby Active Providers

GET /api/provider/nearby?lat=35.7021&lng=51.4031

Response example:

{
  "status": "success",
  "providers": [
    {
      "id": 12,
      "name": "Ali",
      "lat": 35.7010,
      "lng": 51.4040
    },
    {
      "id": 17,
      "name": "Sara",
      "lat": 35.7002,
      "lng": 51.4050
    }
  ]
}

Technologies Used

  • Node.js
  • Express.js
  • MongoDB with Mongoose
  • JSON Web Tokens (JWT) for authentication
  • Socket.io for optional real-time communication (optional task)

Setup and Installation

  1. Clone the repository:
    git clone <repo-url>
    cd <repo-folder>
  2. Install dependencies:
    npm install
  3. Create a .env file based on .env.example with your configuration (MongoDB URI, JWT secret, etc.)
  4. Start the server:
    npm start

Notes

  • Authentication middleware protects location update API; include the token in Authorization header.
  • Location search uses a simple bounding box based on latitude and longitude deltas.
  • Real-time notifications (via WebSocket) are optional and can be implemented for notifying providers about new service requests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors