| @@ 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 ") |
|
| @@ 490-527 (lines=38) @@ | ||
| 487 | resp.status = falcon.HTTP_200 |
|
| 488 | _ = id_ |
|
| 489 | ||
| 490 | @staticmethod |
|
| 491 | def on_get(req, resp, id_): |
|
| 492 | """Handles GET requests""" |
|
| 493 | if 'API-KEY' not in req.headers or \ |
|
| 494 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 495 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 496 | access_control(req) |
|
| 497 | else: |
|
| 498 | api_key_control(req) |
|
| 499 | if not id_.isdigit() or int(id_) <= 0: |
|
| 500 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 501 | description='API.INVALID_COST_CENTER_ID') |
|
| 502 | ||
| 503 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 504 | cursor = cnx.cursor() |
|
| 505 | ||
| 506 | query = (" SELECT t.id, t.name, t.uuid, " |
|
| 507 | " t.tariff_type, t.unit_of_price " |
|
| 508 | " FROM tbl_tariffs t, tbl_cost_centers_tariffs ct " |
|
| 509 | " WHERE t.id = ct.tariff_id AND ct.cost_center_id = %s " |
|
| 510 | " ORDER BY t.name ") |
|
| 511 | cursor.execute(query, (id_,)) |
|
| 512 | rows = cursor.fetchall() |
|
| 513 | ||
| 514 | cursor.close() |
|
| 515 | cnx.close() |
|
| 516 | ||
| 517 | result = list() |
|
| 518 | if rows is not None and len(rows) > 0: |
|
| 519 | for row in rows: |
|
| 520 | meta_result = {"id": row[0], |
|
| 521 | "name": row[1], |
|
| 522 | "uuid": row[2], |
|
| 523 | "tariff_type": row[3], |
|
| 524 | "unit_of_price": row[4]} |
|
| 525 | result.append(meta_result) |
|
| 526 | ||
| 527 | resp.text = json.dumps(result) |
|
| 528 | ||
| 529 | @staticmethod |
|
| 530 | @user_logger |
|
| @@ 303-336 (lines=34) @@ | ||
| 300 | resp.status = falcon.HTTP_200 |
|
| 301 | _ = id_ |
|
| 302 | ||
| 303 | @staticmethod |
|
| 304 | def on_get(req, resp, id_): |
|
| 305 | if 'API-KEY' not in req.headers or \ |
|
| 306 | not isinstance(req.headers['API-KEY'], str) or \ |
|
| 307 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
| 308 | access_control(req) |
|
| 309 | else: |
|
| 310 | api_key_control(req) |
|
| 311 | if not id_.isdigit() or int(id_) <= 0: |
|
| 312 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 313 | description='API.INVALID_NON_WORKING_DAY_ID') |
|
| 314 | ||
| 315 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 316 | cursor = cnx.cursor() |
|
| 317 | ||
| 318 | cursor.execute(" SELECT id, working_calendar_id, date_local, description" |
|
| 319 | " FROM tbl_working_calendars_non_working_days " |
|
| 320 | " WHERE working_calendar_id = %s " |
|
| 321 | " ORDER BY date_local DESC ", (id_,)) |
|
| 322 | rows_date_local = cursor.fetchall() |
|
| 323 | ||
| 324 | meta_result = list() |
|
| 325 | if rows_date_local is not None and len(rows_date_local) > 0: |
|
| 326 | for row in rows_date_local: |
|
| 327 | date_local_dict = {'id': row[0], |
|
| 328 | 'working_calendar_id': row[1], |
|
| 329 | 'date_local': row[2].isoformat()[0:10], |
|
| 330 | 'description': row[3]} |
|
| 331 | meta_result.append(date_local_dict) |
|
| 332 | ||
| 333 | cursor.close() |
|
| 334 | cnx.close() |
|
| 335 | ||
| 336 | resp.text = json.dumps(meta_result) |
|
| 337 | ||
| 338 | @staticmethod |
|
| 339 | def on_post(req, resp, id_): |
|