From 5ebaa6095ee48a3f70112e95737074cf9c6a0bd4 Mon Sep 17 00:00:00 2001 From: Son Nguyen Date: Mon, 9 Jun 2025 11:51:10 -0400 Subject: [PATCH] feat(api): fix backend API logic and add docs --- README.md | 11 ++++++++++- src/cases/service/case_service.py | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 169b73a..6b3bd0c 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,22 @@ Clone the repository if you haven't done so already, then follow these steps to To run the application locally, follow these steps: +> Note: Ensure you have activated your pipenv shell by running `pipenv shell`. + 1. Ensure all dependencies are installed using Pipenv. + ```bash + pipenv install + ``` 2. Start your Docker containers if the application requires any external services like databases. -3. Use the following command to run the application under the ``src``: +3. Use the following command to run the application under the ``src`` directory: ```shell flask run ``` Adjust the command based on your application's entry point if different. +4. Alternatively, run the following command to start the application, at the root path of the project if there is any port conflict on your machine: + ```shell + flask run --host=127.0.0.1 --port=5001 + ``` > **NOTE:** If your frontend is also running, ensure it is configured to communicate with this backend API. You may need to set the API URL in your frontend configuration. > Also, you might need to use CORS (Cross-Origin Resource Sharing) if your frontend and backend are served from different origins. You can use the `flask-cors` package to handle this: diff --git a/src/cases/service/case_service.py b/src/cases/service/case_service.py index a608d19..9712a8c 100644 --- a/src/cases/service/case_service.py +++ b/src/cases/service/case_service.py @@ -270,6 +270,8 @@ def get_page_configuration(self): def get_case_review(self, case_config_id): # pragma: no cover """ + A function that implements the business logic for the /case-reviews/{id} API endpoint. + Steps: 1) Load saved DisplayConfig for this case_config_id + user_email. 2) Build full unpruned case_details tree. 3) Prune under “BACKGROUND” according to CSV path_config. @@ -279,6 +281,9 @@ def get_case_review(self, case_config_id): # pragma: no cover b) Then, any "Adjusted CRC Risk" row (renaming it) c) If neither found, emit "N/A" 6) If CSV had no RISK ASSESSMENT entries at all, do not emit any CRC score node. + 7) Return Case object with pruned case_details and important_infos. + + This function relies on the Tree data structure, which is built by utils/csv_parser.py. """ # --- 1) Load configuration & verify access --- configuration = self.configuration_repository.get_configuration_by_id(case_config_id) @@ -406,7 +411,6 @@ def get_case_review(self, case_config_id): # pragma: no cover # 6) If neither csv_crc_score_leaf nor old_crc_toggle, we do not append any CRC score node. - # --- 7) Return the assembled Case object --- return Case( self.person.person_source_value, str(configuration.case_id),