Skip to content

Commit 85d4fab

Browse files
committed
added homogenization rules handler
1 parent 571ded8 commit 85d4fab

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

hyperleda/client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ def _request(
6363

6464
response = requests.request(method, f"{self.endpoint}{path}", **kwargs)
6565
if not response.ok:
66-
raise error.APIError.from_dict(response.json())
66+
try:
67+
msg = error.APIError.from_dict(response.json())
68+
except Exception:
69+
msg = error.APIError(response.status_code, response.text)
70+
raise msg
6771

6872
return response.json()
6973

@@ -156,3 +160,10 @@ def patch_table_schema(self, table_name: str, actions: list) -> None:
156160
"/admin/api/v1/table",
157161
dataclasses.asdict(model.PatchTableRequestSchema(table_name, actions)),
158162
)
163+
164+
def create_homogenization_rules(self, rules: list[model.HomogenizationRule]) -> None:
165+
_ = self._request(
166+
"POST",
167+
"/admin/api/v1/table/homogenization/rules",
168+
dataclasses.asdict(model.CreateHomogenizationRulesRequestSchema(rules)),
169+
)

hyperleda/model.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# generated by datamodel-codegen:
22
# filename: swagger.json
3-
# timestamp: 2025-02-02T15:14:49+00:00
3+
# timestamp: 2025-05-07T17:31:13+00:00
44

55
from __future__ import annotations
66

77
from dataclasses import dataclass
88
from enum import Enum
9-
from typing import Any, Optional
9+
from typing import Any
1010

1111

1212
@dataclass
@@ -41,6 +41,7 @@ class DataType(Enum):
4141
char = "char"
4242
short = "short"
4343
int = "int"
44+
long = "long"
4445
integer = "integer"
4546
smallint = "smallint"
4647
float = "float"
@@ -82,7 +83,7 @@ class CreateTableResponseSchema:
8283

8384
@dataclass
8485
class GetTableValidationRequestSchema:
85-
table_id: int
86+
table_name: str
8687

8788

8889
@dataclass
@@ -181,3 +182,28 @@ class TableStatusStatsRequestSchema:
181182
@dataclass
182183
class TableStatusStatsResponseSchema:
183184
processing: dict[str, int] | None = None
185+
186+
187+
class Catalog(Enum):
188+
icrs = "icrs"
189+
designation = "designation"
190+
redshift = "redshift"
191+
192+
193+
@dataclass
194+
class HomogenizationRule:
195+
catalog: Catalog
196+
parameter: str
197+
filters: dict[str, Any]
198+
key: str | None = None
199+
enrichment: dict[str, Any] | None = None
200+
201+
202+
@dataclass
203+
class CreateHomogenizationRulesRequestSchema:
204+
rules: list[HomogenizationRule]
205+
206+
207+
@dataclass
208+
class CreateHomogenizationRulesResponseSchema:
209+
pass

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build:
1313
# to use the model one needs to start the server on localhost:8080
1414
generate-model:
1515
mkdir -p hyperleda/gen
16-
curl localhost:8080/api/docs/swagger.json > hyperleda/gen/swagger.json
16+
curl http://localhost:8080/admin/api/docs/swagger.json > hyperleda/gen/swagger.json
1717
datamodel-codegen --input hyperleda/gen/swagger.json --output hyperleda/model.py --output-model-type dataclasses.dataclass --input-file-type openapi
1818
make fix
1919

0 commit comments

Comments
 (0)