|
1 | | -import abc |
2 | 1 | from typing import List |
3 | 2 |
|
4 | | -from codeinsight_sdk.models import Project, ProjectInventory, ProjectInventoryItem, Report |
5 | | -from codeinsight_sdk.exceptions import CodeInsightError |
| 3 | +from ..models import Project, ProjectInventory, ProjectInventoryItem |
| 4 | +from ..handler import Handler |
6 | 5 |
|
7 | | -class Handler(abc.ABC): |
8 | | - def __init__(self, client): |
9 | | - self.client = client |
10 | | - self.cls = None |
11 | | - |
12 | | - @staticmethod |
13 | | - def create(client, cls): |
14 | | - k = cls.__name__ |
15 | | - handlers = {"Project": ProjectHandler, |
16 | | - "Report": ReportHandler |
17 | | - } |
18 | | - handler = handlers.get(k) |
19 | | - if handler is None: |
20 | | - raise ValueError(f"Handler not found for class '{k}'") |
21 | | - return handler(client) |
22 | | - |
23 | | - @abc.abstractmethod |
24 | | - def get(self): |
25 | | - pass |
| 6 | +from ..exceptions import CodeInsightError |
26 | 7 |
|
27 | 8 | class ProjectHandler(Handler): |
28 | 9 | def __init__(self, client): |
@@ -208,55 +189,3 @@ def upload_codebase(self, project_id:int, |
208 | 189 | content_type = "application/octet-stream" |
209 | 190 | resp = self.client.request("POST", url_part=path, params=params, data=code_file,content_type=content_type) |
210 | 191 | return resp.status_code |
211 | | - |
212 | | -class ReportHandler(Handler): |
213 | | - """ |
214 | | - A class that handles operations related to reports. |
215 | | -
|
216 | | - Args: |
217 | | - client (Client): The client object used for making API requests. |
218 | | -
|
219 | | - Attributes: |
220 | | - cls (Report): The class representing a report. |
221 | | -
|
222 | | - Methods: |
223 | | - get(id): Retrieves a report by its ID. |
224 | | - all(): Retrieves all reports. |
225 | | -
|
226 | | - """ |
227 | | - |
228 | | - def __init__(self, client): |
229 | | - super().__init__(client) |
230 | | - self.cls = Report |
231 | | - |
232 | | - def get(self, id:int): |
233 | | - """ |
234 | | - Retrieves a report by its ID. |
235 | | -
|
236 | | - Args: |
237 | | - id (int): The ID of the report to retrieve. |
238 | | -
|
239 | | - Returns: |
240 | | - Report: The report object. |
241 | | -
|
242 | | - """ |
243 | | - path = f"reports/{id}" |
244 | | - resp = self.client.request("GET", url_part=path) |
245 | | - report_data = resp.json()['data'] |
246 | | - report = self.cls.from_dict(report_data) |
247 | | - return report |
248 | | - |
249 | | - def all(self): |
250 | | - """ |
251 | | - Retrieves all reports. |
252 | | -
|
253 | | - Returns: |
254 | | - list: A list of report objects. |
255 | | -
|
256 | | - """ |
257 | | - path = "reports" |
258 | | - resp = self.client.request("GET", url_part=path) |
259 | | - reports = [] |
260 | | - for report_data in resp.json()['data']: |
261 | | - reports.append(self.cls.from_dict(report_data)) |
262 | | - return reports |
0 commit comments