Skip to content

koushikbardhan2000/users-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

User Issue Management Backend (PHP) It covers setup, structure, API testing, and dependencies:


# πŸ› οΈ User Issue Management System (PHP Backend)

This is a backend system for managing issue calls submitted by users. It supports 3 roles:

- **Public Users**: Can submit new issue calls
- **Manager**: Can view, assign, and close calls
- **Support Engineer**: Can view and resolve assigned calls

JWT-based authentication is used for manager and engineer routes. Built using plain PHP + MySQL (via PDO).

Prerequisit

sudo apt update
sudo apt install php composer
php -v
composer -V
composer require firebase/php-jwt

βš™οΈ Setup Instructions

1. Install PHP & Composer (ignore if already done)

Make sure you have PHP 8+ and Composer installed. On WSL / Ubuntu:

sudo apt install php composer

2. Install JWT Library

Inside your project directory:

composer require firebase/php-jwt

3. Configure Database

  • Create a MySQL database called issue
  • Import the schema and demo data:
  • Run the db.sql file content on your DB query
-- Run this inside MySQL CLI or phpMyAdmin
SOURCE ./db.sql

Or copy SQL from the setup instructions provided earlier.

4. Update ./API/config.php

Edit your DB credentials and set a strong $jwt_secret (32+ chars):

$host = "localhost";
$user = "root";
$password = "";
$db_name = "issue";
$jwt_secret = "";

πŸš€ API Testing

πŸ”“ Public: Submit a Call

one-liner

curl -X POST http://localhost/users-issue/api/calls/create.php -H "Content-Type: application/json" -d '{"problem_type": "Login Problem", "user_name": "Jane Doe", "user_email": "[email protected]", "user_phone": "123-456-7890", "description": "Unable to log in since yesterday."}'

πŸ” Login to Get JWT

Manager:

curl -X POST http://localhost/users-issue/api/auth/manager_login.php -H "Content-Type: application/json" -d '{"email":"[email protected]","password":"managerPass123"}'

Engineer:

curl -X POST http://localhost/users-issue/api/auth/engineer_login.php -H "Content-Type: application/json" -d '{"email":"[email protected]","password":"password123"}'

You’ll get a token like:

{ "jwt": "eyJhbGciOi..." }

Use it in Authorization: Bearer header for protected requests.


πŸ” Protected API Examples

  • Remember to change the JWT code of the following or any JWT mention here to the freashly generated JWT of your own, this step is vital, else it will throw authentication error.

πŸ”Έ Manager: View Pending Calls

curl -X GET "http://localhost/users-issue/api/manager/calls_list.php?status=PENDING" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" -H "Content-Type: application/json"

πŸ”Έ Engineer: Resolve a Call

curl -X POST http://localhost/users-issue/api/engineer/resolve_call.php -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNjY3MjAsImV4cCI6MTc2ODA3MDMyMCwiZGF0YSI6eyJ1c2VyX2lkIjoiMiIsInJvbGUiOiJTVVBQT1JUX0VOR0lORUVSIn19.RSiLtL3p_WOOGO8vsqiGtjfvjWpc_Lf4fEp4GCx6jzE" -H "Content-Type: application/json" -d '{"call_id": 4,  "resolution_status": "RESOLVED", "issue_type": "Router Issue", "remarks": "Replaced router"}'

Manager Endpoints (Protected)

βœ… Get managers profile

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" http://localhost/users-issue/api/manager/profile_get.php

βœ… edit managers profile

curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" -d '{"name":"Jane Manager","email":"[email protected]","phone":"123-456-7890", "status": "ACTIVE"}' http://localhost/users-issue/api/manager/profile_put.php

βœ… Get pending calls

curl -X GET "http://localhost/users-issue/api/manager/calls_list.php?status=PENDING" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" -H "Content-Type: application/json"

βœ… get ongoing calls

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" "http://localhost/users-issue/api/manager/calls_list.php?status=ONGOING"

βœ… get closed calls

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" "http://localhost/users-issue/api/manager/calls_list.php?status=CLOSED"

βœ… get call details by call id

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" "http://localhost/users-issue/api/manager/call_details.php?id=4"

βœ… Assign engineers

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" -d '{"call_id":1,"engineer_id":2}' http://localhost/users-issue/api/manager/assign_engineer.php

βœ… close call

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" -d '{"call_id":4,"resolution":"Issue fixed","status":"CLOSED", "final_remark": "fixed by engineer id 2"}' http://localhost/users-issue/api/manager/close_call.php

βœ… get SE list

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" http://localhost/users-issue/api/manager/support_engineers.php

βœ… report by interval days

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" "http://localhost/users-issue/api/reports/calls_by_interval.php?days=30"

βœ… report by performance

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNzM2MzQsImV4cCI6MTc2ODA3NzIzNCwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.sVM60CeNTvQKOtb88b0tZ9CrIqhidnduUxQCWcbqrYc" http://localhost/users-issue/api/reports/engineer_performance.php

βœ… GET: Get SE details

curl -X GET -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgxMTEwMzYsImV4cCI6MTc2ODExNDYzNiwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.VYkzD1qekFR61Ak6RDnAI4wRGCi-laVUGxRp9ZZ751k" -H "Content-Type: application/json" http://localhost/users-issue/api/manager/support_engineer_crud.php

βœ… POST: Add Engineer

curl -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgxMTEwMzYsImV4cCI6MTc2ODExNDYzNiwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.VYkzD1qekFR61Ak6RDnAI4wRGCi-laVUGxRp9ZZ751k" -H "Content-Type: application/json" -d '{"name":"Rahul Das","email":"[email protected]","phone":"1234567890","password":"pass123"}' http://localhost/users-issue/api/manager/support_engineer_crud.php

βœ… PUT: Update Engineer

curl -X PUT -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgxMTEwMzYsImV4cCI6MTc2ODExNDYzNiwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.VYkzD1qekFR61Ak6RDnAI4wRGCi-laVUGxRp9ZZ751k" -H "Content-Type: application/json" -d '{"id":5,"name":"Rahul Das","email":"[email protected]","phone":"0001112222","status":"ACTIVE"}' http://localhost/users-issue/api/manager/support_engineer_crud.php

βœ… DELETE: Delete Engineer

curl -X DELETE -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgxMTEwMzYsImV4cCI6MTc2ODExNDYzNiwiZGF0YSI6eyJ1c2VyX2lkIjoiMSIsInJvbGUiOiJNQU5BR0VSIn19.VYkzD1qekFR61Ak6RDnAI4wRGCi-laVUGxRp9ZZ751k" -H "Content-Type: application/j" -d "id=5" http://localhost/users-issue/api/manager/support_engineer_crud.php

Engineer Endpoints (Protected)

βœ… Get engineer profile

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNjY3MjAsImV4cCI6MTc2ODA3MDMyMCwiZGF0YSI6eyJ1c2VyX2lkIjoiMiIsInJvbGUiOiJTVVBQT1JUX0VOR0lORUVSIn19.RSiLtL3p_WOOGO8vsqiGtjfvjWpc_Lf4fEp4GCx6jzE" http://localhost/users-issue/api/engineer/profile_get.php

βœ… Edit profile

curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNjY3MjAsImV4cCI6MTc2ODA3MDMyMCwiZGF0YSI6eyJ1c2VyX2lkIjoiMiIsInJvbGUiOiJTVVBQT1JUX0VOR0lORUVSIn19.RSiLtL3p_WOOGO8vsqiGtjfvjWpc_Lf4fEp4GCx6jzE" -d '{"name":"Eve Engineer","email":"[email protected]","phone":"987-654-3210", "status": "ACTIVE"}' http://localhost/users-issue/api/engineer/profile_put.php

βœ… Get ongoing calls

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNjY3MjAsImV4cCI6MTc2ODA3MDMyMCwiZGF0YSI6eyJ1c2VyX2lkIjoiMiIsInJvbGUiOiJTVVBQT1JUX0VOR0lORUVSIn19.RSiLtL3p_WOOGO8vsqiGtjfvjWpc_Lf4fEp4GCx6jzE" "http://localhost/users-issue/api/engineer/calls_list.php?status=ONGOING"

βœ… get closed calls

curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNjY3MjAsImV4cCI6MTc2ODA3MDMyMCwiZGF0YSI6eyJ1c2VyX2lkIjoiMiIsInJvbGUiOiJTVVBQT1JUX0VOR0lORUVSIn19.RSiLtL3p_WOOGO8vsqiGtjfvjWpc_Lf4fEp4GCx6jzE" "http://localhost/users-issue/api/engineer/calls_list.php?status=CLOSED"

βœ… Resolve call

curl -X POST http://localhost/users-issue/api/engineer/resolve_call.php -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjgwNjY3MjAsImV4cCI6MTc2ODA3MDMyMCwiZGF0YSI6eyJ1c2VyX2lkIjoiMiIsInJvbGUiOiJTVVBQT1JUX0VOR0lORUVSIn19.RSiLtL3p_WOOGO8vsqiGtjfvjWpc_Lf4fEp4GCx6jzE" -H "Content-Type: application/json" -d '{"call_id": 4,  "resolution_status": "RESOLVED", "issue_type": "Router Issue", "remarks": "Replaced router"}'

βœ… Status Codes

Code Meaning
200 OK / Success
201 Created (for new call)
400 Bad Request
401 Unauthorized (invalid JWT)
403 Forbidden (wrong role)
404 Not Found (call/user)
500 Internal Server Error

πŸ“Œ Notes

  • Use Postman or curl for testing
  • All input/output is in JSON
  • Manager and engineer data is stored in a shared users table
  • Use your own strong secrets for JWT
  • Each role has separate login + dashboard logic

πŸ”§ To-Do (Future Improvements)

  • Refresh tokens
  • Email notifications to users

πŸ“« Reach Me At:


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages