| | | 1 | | #include "report_handler.h" |
| | | 2 | | #include "../../database/report_service.h" |
| | | 3 | | #include "../../database/cJSON.h" |
| | | 4 | | #include <string.h> |
| | | 5 | | #include <stdlib.h> |
| | | 6 | | #include <stdio.h> |
| | | 7 | | |
| | | 8 | | // Original mock functions removed. Using real service implementations from database/report_service.c |
| | | 9 | | |
| | 2 | 10 | | void handle_report_request(HttpRequest *req, HttpResponse *res) { |
| | | 11 | | char *data; |
| | | 12 | | |
| | 2 | 13 | | if (strstr(req->path, "csv")) { |
| | | 14 | | // Return CSV |
| | 0 | 15 | | if (strstr(req->path, "maintenance")) { |
| | 0 | 16 | | data = generate_maintenance_csv_report(); |
| | | 17 | | } else { |
| | 0 | 18 | | data = generate_inventory_csv_report(); |
| | | 19 | | } |
| | 0 | 20 | | res->status_code = 200; |
| | 0 | 21 | | strcpy(res->content_type, "text/csv"); |
| | | 22 | | } else { |
| | | 23 | | // Return XML |
| | 2 | 24 | | if (strstr(req->path, "maintenance")) { |
| | 1 | 25 | | data = generate_maintenance_xml_report(); |
| | | 26 | | } else { |
| | 1 | 27 | | data = generate_inventory_xml_report(); |
| | | 28 | | } |
| | 2 | 29 | | res->status_code = 200; |
| | 2 | 30 | | strcpy(res->content_type, "application/xml"); |
| | | 31 | | } |
| | | 32 | | |
| | 2 | 33 | | strncpy(res->body, data, 8191); |
| | 2 | 34 | | res->body[8191] = '\0'; |
| | 2 | 35 | | free(data); |
| | 2 | 36 | | } |