diff --git a/dapodik/__init__.py b/dapodik/__init__.py index 70f758a..6ef61ac 100644 --- a/dapodik/__init__.py +++ b/dapodik/__init__.py @@ -8,6 +8,7 @@ from .auth import BaseAuth from .rest import BaseRest +from .customrest import BaseCustomrest from .validasi import BaseValidasi from .peserta_didik import BasePesertaDidik from .gtk import BaseGtk @@ -19,6 +20,7 @@ __all__ = [ "BaseAuth", + "BaseCustomrest", "BaseGtk", "BasePesertaDidik", "BaseRest", diff --git a/dapodik/customrest/__init__.py b/dapodik/customrest/__init__.py index e69de29..717f128 100644 --- a/dapodik/customrest/__init__.py +++ b/dapodik/customrest/__init__.py @@ -0,0 +1,5 @@ +from .wilayah import Wilayah + +from .base import BaseCustomrest + +__all__ = ["BaseCustomrest", "Wilayah"] diff --git a/dapodik/customrest/base.py b/dapodik/customrest/base.py new file mode 100644 index 0000000..cfa6268 --- /dev/null +++ b/dapodik/customrest/base.py @@ -0,0 +1,22 @@ +from typing import List + +from dapodik.base import BaseDapodik +from dapodik.utils.helper import cached + +from . import Wilayah + + +class BaseCustomrest(BaseDapodik): + @cached("kecamatan") + def kecamatan( + self, query: str, page: int = 1, start: int = 0, limit: int = 50 + ) -> List[Wilayah]: + return self._get_rest( + "kecamatan", + List[Wilayah], + page, + start, + limit, + query=self._query(query=query), + prefix="customrest/", + ) diff --git a/dapodik/customrest/wilayah.py b/dapodik/customrest/wilayah.py new file mode 100644 index 0000000..778e2e9 --- /dev/null +++ b/dapodik/customrest/wilayah.py @@ -0,0 +1,29 @@ +import attr +from datetime import datetime +from typing import Optional + + +@attr.dataclass(frozen=True, slots=True) +class Wilayah: + kode_wilayah: str + nama: str + id_level_wilayah: int + mst_kode_wilayah: str + negara_id: str + asal_wilayah: str + kode_bps: str + kode_dagri: str + kode_keu: str + id_prov: Optional[int] + id_kabkota: Optional[int] + id_kec: Optional[int] + a_desa: int + a_kelurahan: int + a_35: int + a_urban: int + kategori_desa_id: Optional[int] + create_date: datetime + last_update: datetime + expired_date: Optional[datetime] + last_sync: datetime + nama_kabupaten: str diff --git a/dapodik/dapodik.py b/dapodik/dapodik.py index 7252ba1..abce842 100644 --- a/dapodik/dapodik.py +++ b/dapodik/dapodik.py @@ -2,6 +2,7 @@ from . import BaseAuth from . import BaseRest +from . import BaseCustomrest from . import BaseValidasi from . import BasePesertaDidik from . import BaseGtk @@ -14,6 +15,7 @@ class Dapodik( BaseAuth, BaseRest, + BaseCustomrest, BaseValidasi, BasePesertaDidik, BaseGtk, diff --git a/tests/test_customrest.py b/tests/test_customrest.py new file mode 100644 index 0000000..448b897 --- /dev/null +++ b/tests/test_customrest.py @@ -0,0 +1,13 @@ +import attr + +from dapodik.base import BaseDapodik +from dapodik.customrest import BaseCustomrest +from dapodik.customrest import Wilayah + + +def test_base_customresr(): + assert issubclass(BaseCustomrest, BaseDapodik) + + +def test_member(): + assert attr.has(Wilayah)