Skip to content

Commit 35193a9

Browse files
committed
Put now portal fields in API
1 parent 56fbfac commit 35193a9

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

oc4ids_datastore_api/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class DatasetSQLModel(SQLModel, table=True):
1313
license_url: str | None
1414
license_title: str | None
1515
license_title_short: str | None
16+
portal_title: str | None
17+
portal_url: str | None
1618
json_url: str | None
1719
csv_url: str | None
1820
xlsx_url: str | None

oc4ids_datastore_api/schemas.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class License(BaseModel):
1414
title_short: str | None
1515

1616

17+
class Portal(BaseModel):
18+
url: str | None
19+
title: str | None
20+
21+
1722
class Download(BaseModel):
1823
format: str
1924
url: str
@@ -24,4 +29,5 @@ class Dataset(BaseModel):
2429
source_url: str
2530
publisher: Publisher
2631
license: License
32+
portal: Portal
2733
downloads: list[Download]

oc4ids_datastore_api/services.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from oc4ids_datastore_api.database import fetch_all_datasets
22
from oc4ids_datastore_api.models import DatasetSQLModel
3-
from oc4ids_datastore_api.schemas import Dataset, Download, License, Publisher
3+
from oc4ids_datastore_api.schemas import Dataset, Download, License, Portal, Publisher
44

55

66
def _transform_dataset(dataset: DatasetSQLModel) -> Dataset:
@@ -23,6 +23,10 @@ def _transform_dataset(dataset: DatasetSQLModel) -> Dataset:
2323
title=dataset.license_title,
2424
title_short=dataset.license_title_short,
2525
),
26+
portal=Portal(
27+
url=dataset.portal_url,
28+
title=dataset.portal_title,
29+
),
2630
downloads=downloads,
2731
)
2832

tests/test_services.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pytest_mock import MockerFixture
44

55
from oc4ids_datastore_api.models import DatasetSQLModel
6-
from oc4ids_datastore_api.schemas import Dataset, Download, License, Publisher
6+
from oc4ids_datastore_api.schemas import Dataset, Download, License, Portal, Publisher
77
from oc4ids_datastore_api.services import get_all_datasets
88

99

@@ -20,6 +20,8 @@ def test_get_all_datasets(mocker: MockerFixture) -> None:
2020
license_url="https://license.com",
2121
license_title="License",
2222
license_title_short="L",
23+
portal_url="https://portal.com",
24+
portal_title="Portal",
2325
json_url="https://downloads/test_dataset.json",
2426
csv_url="https://downloads/test_dataset.csv",
2527
xlsx_url="https://downloads/test_dataset.xlsx",
@@ -34,6 +36,7 @@ def test_get_all_datasets(mocker: MockerFixture) -> None:
3436
source_url="https://test-dataset.json",
3537
publisher=Publisher(name="test_publisher", country="ab"),
3638
license=License(title="License", title_short="L", url="https://license.com"),
39+
portal=Portal(title="Portal", url="https://portal.com"),
3740
downloads=[
3841
Download(format="json", url="https://downloads/test_dataset.json"),
3942
Download(format="csv", url="https://downloads/test_dataset.csv"),
@@ -69,6 +72,7 @@ def test_get_all_datasets_missing_download_formats(mocker: MockerFixture) -> Non
6972
source_url="https://test-dataset.json",
7073
publisher=Publisher(name="test_publisher", country=None),
7174
license=License(title="License", title_short="L", url="https://license.com"),
75+
portal=Portal(title=None, url=None),
7276
downloads=[
7377
Download(format="json", url="https://downloads/test_dataset.json"),
7478
],

0 commit comments

Comments
 (0)