| | | 1 | | #include "router.h" |
| | | 2 | | #include "handlers/machine_handler.h" |
| | | 3 | | #include "handlers/inventory_handler.h" |
| | | 4 | | #include "handlers/auth_handler.h" |
| | | 5 | | #include "handlers/maintenance_handler.h" |
| | | 6 | | #include "handlers/report_handler.h" |
| | | 7 | | #include "handlers/fault_handler.h" |
| | | 8 | | #include "../database/alert_service.h" |
| | | 9 | | #include <string.h> |
| | | 10 | | #include <stdio.h> |
| | | 11 | | #include <stdlib.h> |
| | | 12 | | |
| | | 13 | | |
| | | 14 | | |
| | 22 | 15 | | void handle_route(HttpRequest *req, HttpResponse *res) { |
| | | 16 | | // Default 404 |
| | 22 | 17 | | res->status_code = 404; |
| | 22 | 18 | | strcpy(res->content_type, "application/json"); |
| | 22 | 19 | | strcpy(res->body, "{\"error\": \"Route not found\"}"); |
| | | 20 | | |
| | 22 | 21 | | if (strstr(req->path, "/api/machines")) { |
| | 5 | 22 | | handle_machine_request(req, res); |
| | 17 | 23 | | } else if (strstr(req->path, "/api/inventory")) { |
| | 4 | 24 | | handle_inventory_request(req, res); |
| | 13 | 25 | | } else if (strstr(req->path, "/api/login")) { |
| | 1 | 26 | | handle_auth_request(req, res); |
| | 12 | 27 | | } else if (strstr(req->path, "/api/maintenance")) { |
| | 3 | 28 | | handle_maintenance_request(req, res); |
| | 9 | 29 | | } else if (strstr(req->path, "/api/reports")) { |
| | 2 | 30 | | handle_report_request(req, res); |
| | 7 | 31 | | } else if (strstr(req->path, "/api/faults")) { |
| | 3 | 32 | | handle_fault_request(req, res); |
| | 4 | 33 | | } else if (strstr(req->path, "/api/alerts")) { |
| | 1 | 34 | | res->status_code = 200; |
| | 1 | 35 | | strcpy(res->content_type, "application/json"); |
| | 1 | 36 | | char *json = alert_service_serialize_alerts(); |
| | 1 | 37 | | strncpy(res->body, json, 8191); |
| | 1 | 38 | | res->body[8191] = '\0'; |
| | 1 | 39 | | free(json); |
| | | 40 | | } |
| | 22 | 41 | | } |