| @@ 108-139 (lines=32) @@ | ||
| 105 | resp.status = falcon.HTTP_200 |
|
| 106 | _ = id_ |
|
| 107 | ||
| 108 | @staticmethod |
|
| 109 | def on_get(req, resp, id_): |
|
| 110 | """ |
|
| 111 | Handle GET requests to retrieve a specific menu by ID |
|
| 112 | ||
| 113 | Retrieves a single menu with its metadata including: |
|
| 114 | - Menu ID and name |
|
| 115 | - Route path |
|
| 116 | - Parent menu ID |
|
| 117 | - Hidden status |
|
| 118 | ||
| 119 | Args: |
|
| 120 | req: Falcon request object |
|
| 121 | resp: Falcon response object |
|
| 122 | id_: Menu ID to retrieve |
|
| 123 | """ |
|
| 124 | # Check authentication method (API key or session) |
|
| 125 | if 'API-KEY' not in req.headers or \ |
|
| 126 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 127 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 128 | access_control(req) |
|
| 129 | else: |
|
| 130 | api_key_control(req) |
|
| 131 | ||
| 132 | if not id_.isdigit() or int(id_) <= 0: |
|
| 133 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 134 | description='API.INVALID_MENU_ID') |
|
| 135 | ||
| 136 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 137 | cursor = cnx.cursor() |
|
| 138 | ||
| 139 | # Query to retrieve specific menu by ID |
|
| 140 | query = (" SELECT id, name, route, parent_menu_id, is_hidden " |
|
| 141 | " FROM tbl_menus " |
|
| 142 | " WHERE id= %s ") |
|
| @@ 500-537 (lines=38) @@ | ||
| 497 | resp.status = falcon.HTTP_200 |
|
| 498 | _ = id_ |
|
| 499 | ||
| 500 | @staticmethod |
|
| 501 | def on_get(req, resp, id_): |
|
| 502 | """Handles GET requests""" |
|
| 503 | if 'API-KEY' not in req.headers or \ |
|
| 504 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 505 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 506 | access_control(req) |
|
| 507 | else: |
|
| 508 | api_key_control(req) |
|
| 509 | if not id_.isdigit() or int(id_) <= 0: |
|
| 510 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 511 | description='API.INVALID_COST_CENTER_ID') |
|
| 512 | ||
| 513 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 514 | cursor = cnx.cursor() |
|
| 515 | ||
| 516 | query = (" SELECT t.id, t.name, t.uuid, " |
|
| 517 | " t.tariff_type, t.unit_of_price " |
|
| 518 | " FROM tbl_tariffs t, tbl_cost_centers_tariffs ct " |
|
| 519 | " WHERE t.id = ct.tariff_id AND ct.cost_center_id = %s " |
|
| 520 | " ORDER BY t.name ") |
|
| 521 | cursor.execute(query, (id_,)) |
|
| 522 | rows = cursor.fetchall() |
|
| 523 | ||
| 524 | cursor.close() |
|
| 525 | cnx.close() |
|
| 526 | ||
| 527 | result = list() |
|
| 528 | if rows is not None and len(rows) > 0: |
|
| 529 | for row in rows: |
|
| 530 | meta_result = {"id": row[0], |
|
| 531 | "name": row[1], |
|
| 532 | "uuid": row[2], |
|
| 533 | "tariff_type": row[3], |
|
| 534 | "unit_of_price": row[4]} |
|
| 535 | result.append(meta_result) |
|
| 536 | ||
| 537 | resp.text = json.dumps(result) |
|
| 538 | ||
| 539 | @staticmethod |
|
| 540 | @user_logger |
|
| @@ 318-351 (lines=34) @@ | ||
| 315 | resp.status = falcon.HTTP_200 |
|
| 316 | _ = id_ |
|
| 317 | ||
| 318 | @staticmethod |
|
| 319 | def on_get(req, resp, id_): |
|
| 320 | if 'API-KEY' not in req.headers or \ |
|
| 321 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 322 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 323 | access_control(req) |
|
| 324 | else: |
|
| 325 | api_key_control(req) |
|
| 326 | if not id_.isdigit() or int(id_) <= 0: |
|
| 327 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 328 | description='API.INVALID_NON_WORKING_DAY_ID') |
|
| 329 | ||
| 330 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 331 | cursor = cnx.cursor() |
|
| 332 | ||
| 333 | cursor.execute(" SELECT id, working_calendar_id, date_local, description" |
|
| 334 | " FROM tbl_working_calendars_non_working_days " |
|
| 335 | " WHERE working_calendar_id = %s " |
|
| 336 | " ORDER BY date_local DESC ", (id_,)) |
|
| 337 | rows_date_local = cursor.fetchall() |
|
| 338 | ||
| 339 | meta_result = list() |
|
| 340 | if rows_date_local is not None and len(rows_date_local) > 0: |
|
| 341 | for row in rows_date_local: |
|
| 342 | date_local_dict = {'id': row[0], |
|
| 343 | 'working_calendar_id': row[1], |
|
| 344 | 'date_local': row[2].isoformat()[0:10], |
|
| 345 | 'description': row[3]} |
|
| 346 | meta_result.append(date_local_dict) |
|
| 347 | ||
| 348 | cursor.close() |
|
| 349 | cnx.close() |
|
| 350 | ||
| 351 | resp.text = json.dumps(meta_result) |
|
| 352 | ||
| 353 | @staticmethod |
|
| 354 | def on_post(req, resp, id_): |
|