Skip to content

Commit

Permalink
Make client task notes consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhwaja committed Oct 5, 2023
1 parent 5c790c2 commit 70a2069
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rtmilk"
version = "0.2.4"
version = "0.3.0"
description = "RTM API wrapper"
authors = ["Rehan Khwaja <[email protected]>"]
license = "MIT"
Expand Down
17 changes: 4 additions & 13 deletions src/rtmilk/_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rtmilk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/rtmilk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 70a2069

Please sign in to comment.