diff --git a/pyproject.toml b/pyproject.toml index 6ed3263..4f7f80c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rtmilk" -version = "0.2.4" +version = "0.3.0" description = "RTM API wrapper" authors = ["Rehan Khwaja "] license = "MIT" diff --git a/src/rtmilk/_properties.py b/src/rtmilk/_properties.py index 6ee0e7c..1e82878 100644 --- a/src/rtmilk/_properties.py +++ b/src/rtmilk/_properties.py @@ -2,10 +2,11 @@ from datetime import date, datetime from logging import getLogger -from typing import Generic, Optional, TypeVar, Union +from typing import Generic, TypeVar from .api_sync import API from .api_async import APIAsync +from .models import Note _log = getLogger(__name__) _T = TypeVar('_T') @@ -27,17 +28,7 @@ def _LoadValue(self, value: _T): def value(self) -> _T: return self._value -class NotesProperty: - def __init__(self, task): - self._task = task - self._value = None - - def _LoadValue(self, value: list[str]): - self._value = value - - @property - def value(self) -> _T: - return self._value +class NotesProperty(_Property[list[Note]]): def Add(self, title: str, text: str): self._task._client.api.TasksNotesAdd( @@ -105,7 +96,7 @@ async def SetAsync(self, value: bool): taskseries_id=self._task._taskSeriesId, task_id=self._task._taskId) -class DateProperty(_Property[Optional[Union[date, datetime]]]): +class DateProperty(_Property[date | datetime | None]): def __init__(self, task, dateType): super().__init__(task) self._dateType = dateType diff --git a/src/rtmilk/client.py b/src/rtmilk/client.py index a047625..76d4c05 100644 --- a/src/rtmilk/client.py +++ b/src/rtmilk/client.py @@ -62,7 +62,7 @@ def _CreateFromTaskSeries(client, listId, taskSeries): result.startDate._LoadValue(task0.start.date() if task0.start is not None else None) # None means no change result.dueDate._LoadValue(task0.due.date() if task0.due is not None else None) # None means no change result.complete._LoadValue(task0.completed is not None) - result.notes._LoadValue(taskSeries.notes) + result.notes._LoadValue([] if isinstance(taskSeries.notes, list) else taskSeries.notes.note) result.createTime = taskSeries.created result.modifiedTime = taskSeries.modified diff --git a/src/rtmilk/models.py b/src/rtmilk/models.py index cbbe5b7..d2d6089 100644 --- a/src/rtmilk/models.py +++ b/src/rtmilk/models.py @@ -111,7 +111,7 @@ class Task(BaseModel): priority: PriorityEnum start: EmptyStrToNone[datetime] | None -class NotesResponsePayload(BaseModel): +class Note(BaseModel): id: str created: datetime modified: datetime @@ -124,10 +124,10 @@ class Transaction(BaseModel): class NotesResponse(OkStat): transaction: Transaction - note: NotesResponsePayload + note: Note class NotePayload(BaseModel): - note: list[NotesResponsePayload] + note: list[Note] class Tags(BaseModel): tag: list[str]