nuvyx-cards 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. nuvyx_cards-0.1.0/LICENSE +16 -0
  2. nuvyx_cards-0.1.0/PKG-INFO +44 -0
  3. nuvyx_cards-0.1.0/README.md +23 -0
  4. nuvyx_cards-0.1.0/pyproject.toml +36 -0
  5. nuvyx_cards-0.1.0/setup.cfg +4 -0
  6. nuvyx_cards-0.1.0/src/nuvyx/cards/__init__.py +0 -0
  7. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/action.py +153 -0
  8. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/action_id.py +11 -0
  9. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/actions.py +100 -0
  10. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/actions_repository.py +32 -0
  11. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/commands/create_action_command.py +32 -0
  12. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/models/action_track_request.py +8 -0
  13. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/models/action_update_request.py +12 -0
  14. nuvyx_cards-0.1.0/src/nuvyx/cards/actions/queries/actions_search_criteria.py +22 -0
  15. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/area.py +63 -0
  16. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/area_create_request.py +13 -0
  17. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/area_id.py +8 -0
  18. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/area_update_request.py +7 -0
  19. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/areas.py +64 -0
  20. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/areas_repository.py +27 -0
  21. nuvyx_cards-0.1.0/src/nuvyx/cards/areas/areas_search_criteria.py +11 -0
  22. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/card.py +77 -0
  23. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/card_create_request.py +13 -0
  24. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/card_id.py +11 -0
  25. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/card_update_request.py +12 -0
  26. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/cards.py +47 -0
  27. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/cards_repository.py +29 -0
  28. nuvyx_cards-0.1.0/src/nuvyx/cards/cards/cards_search_criteria.py +14 -0
  29. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebook.py +74 -0
  30. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebook_create_request.py +14 -0
  31. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebook_id.py +26 -0
  32. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebook_update_request.py +10 -0
  33. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebooks.py +49 -0
  34. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebooks_repository.py +30 -0
  35. nuvyx_cards-0.1.0/src/nuvyx/cards/notebooks/notebooks_search_criteria.py +11 -0
  36. nuvyx_cards-0.1.0/src/nuvyx/cards/users/user.py +29 -0
  37. nuvyx_cards-0.1.0/src/nuvyx/cards/users/user_id.py +5 -0
  38. nuvyx_cards-0.1.0/src/nuvyx/cards/users/users.py +11 -0
  39. nuvyx_cards-0.1.0/src/nuvyx/cards/users/users_repository.py +19 -0
  40. nuvyx_cards-0.1.0/src/nuvyx_cards.egg-info/PKG-INFO +44 -0
  41. nuvyx_cards-0.1.0/src/nuvyx_cards.egg-info/SOURCES.txt +42 -0
  42. nuvyx_cards-0.1.0/src/nuvyx_cards.egg-info/dependency_links.txt +1 -0
  43. nuvyx_cards-0.1.0/src/nuvyx_cards.egg-info/requires.txt +4 -0
  44. nuvyx_cards-0.1.0/src/nuvyx_cards.egg-info/top_level.txt +1 -0
@@ -0,0 +1,16 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2026 Nuvyx
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
@@ -0,0 +1,44 @@
1
+ Metadata-Version: 2.4
2
+ Name: nuvyx-cards
3
+ Version: 0.1.0
4
+ Summary: A domain system for managing structured information through Cards, Actions, Relationships and Domains.
5
+ Author: diegorys
6
+ License-Expression: MIT
7
+ Keywords: nuvyx,cards
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest; extra == "dev"
19
+ Requires-Dist: mypy; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+
23
+ # Nuvyx CARDS
24
+
25
+ A domain system for managing structured information through cards, relationships and domains.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install nuvyx-cards
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```python
36
+ from nuvyx.cards.cards.card import Card
37
+
38
+ card = Card(
39
+ card_id="1234",
40
+ name="Test card",
41
+ type="test",
42
+ )
43
+ print(card)
44
+ ```
@@ -0,0 +1,23 @@
1
+
2
+ # Nuvyx CARDS
3
+
4
+ A domain system for managing structured information through cards, relationships and domains.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ pip install nuvyx-cards
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```python
15
+ from nuvyx.cards.cards.card import Card
16
+
17
+ card = Card(
18
+ card_id="1234",
19
+ name="Test card",
20
+ type="test",
21
+ )
22
+ print(card)
23
+ ```
@@ -0,0 +1,36 @@
1
+
2
+ [build-system]
3
+ requires = ["setuptools>=77", "wheel"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ name = "nuvyx-cards"
8
+ version = "0.1.0"
9
+ description = "A domain system for managing structured information through Cards, Actions, Relationships and Domains."
10
+ readme = "README.md"
11
+ requires-python = ">=3.10"
12
+ license = "MIT"
13
+ authors = [
14
+ { name = "diegorys" }
15
+ ]
16
+ keywords = ["nuvyx", "cards"]
17
+
18
+ classifiers = [
19
+ "Development Status :: 3 - Alpha",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ ]
26
+
27
+ [tool.setuptools.packages.find]
28
+ where = ["src"]
29
+ include = ["nuvyx.cards*"]
30
+ namespaces = true
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest",
35
+ "mypy",
36
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,153 @@
1
+ from typing import Any
2
+
3
+ from pydantic import BaseModel
4
+
5
+ from ..cards.card import Card
6
+ from ..notebooks.notebook import Notebook
7
+ from .action_id import ActionID
8
+
9
+
10
+ class Action(BaseModel):
11
+ def __init__(
12
+ self,
13
+ action_id: str,
14
+ name: str,
15
+ type: str,
16
+ created_at: str,
17
+ updated_at: str,
18
+ notebook: Notebook | None = None,
19
+ goal: str | None = None,
20
+ priority: str | None = None,
21
+ time_slot: str | None = None,
22
+ card: Card | None = None,
23
+ category: str | None = None,
24
+ status: str | None = None,
25
+ months: list[str] | None = None,
26
+ score: int | None = None,
27
+ date_start: str | None = None,
28
+ date_end: str | None = None,
29
+ ) -> None:
30
+ self._action_id = ActionID(value=action_id)
31
+ self._name = name
32
+ self._notebook = notebook
33
+ self._goal = goal
34
+ self._priority = priority
35
+ self._time_slot = time_slot
36
+ self._card = card
37
+ self._type = type
38
+ self._category = category
39
+ self._status = status
40
+ self._months = months
41
+ self._score = score if status == "Done" else None
42
+ self._date_start = date_start
43
+ self._date_end = date_end
44
+ self._created_at = created_at
45
+ self._updated_at = updated_at
46
+
47
+ def from_dict(self, data: dict[str, Any]) -> "Action":
48
+ return Action(
49
+ action_id=data["action_id"],
50
+ name=data["name"],
51
+ notebook=data["notebook"],
52
+ card=data["card"],
53
+ type=data["type"],
54
+ created_at=data["created_at"],
55
+ updated_at=data["updated_at"],
56
+ goal=data.get("goal"),
57
+ priority=data.get("priority"),
58
+ time_slot=data.get("time_slot"),
59
+ category=data.get("category"),
60
+ status=data.get("status"),
61
+ months=data.get("months"),
62
+ score=data.get("score"),
63
+ date_start=data.get("date_start"),
64
+ date_end=data.get("date_end"),
65
+ )
66
+
67
+ @property
68
+ def action_id(self) -> ActionID:
69
+ return self._action_id
70
+
71
+ @property
72
+ def name(self) -> str:
73
+ return self._name
74
+
75
+ @property
76
+ def created_at(self) -> str:
77
+ return self._created_at
78
+
79
+ @property
80
+ def updated_at(self) -> str:
81
+ return self._updated_at
82
+
83
+ @property
84
+ def notebook(self) -> Notebook | None:
85
+ return self._notebook
86
+
87
+ @property
88
+ def goal(self) -> str | None:
89
+ return self._goal
90
+
91
+ @property
92
+ def priority(self) -> str | None:
93
+ return self._priority
94
+
95
+ @property
96
+ def time_slot(self) -> str | None:
97
+ return self._time_slot
98
+
99
+ @property
100
+ def card(self) -> Card | None:
101
+ return self._card
102
+
103
+ @property
104
+ def type(self) -> str:
105
+ return self._type
106
+
107
+ @property
108
+ def category(self) -> str | None:
109
+ return self._category
110
+
111
+ @property
112
+ def status(self) -> str | None:
113
+ return self._status
114
+
115
+ @property
116
+ def months(self) -> list[str] | None:
117
+ return self._months
118
+
119
+ @property
120
+ def score(self) -> int | None:
121
+ return self._score
122
+
123
+ @property
124
+ def date_start(self) -> str | None:
125
+ return self._date_start
126
+
127
+ @property
128
+ def date_end(self) -> str | None:
129
+ return self._date_end
130
+
131
+ def to_dict(self) -> dict[str, Any]:
132
+ return {
133
+ "action_id": self._action_id.value,
134
+ "title": self._name,
135
+ "notebook": self._notebook.to_dict() if self._notebook else {},
136
+ "card": self._card.to_dict() if self._card else {},
137
+ "type": self._type,
138
+ "category": self._category,
139
+ "status": self._status,
140
+ "score": self._score,
141
+ "goal": self._goal,
142
+ "priority": self._priority,
143
+ "time_slot": self._time_slot,
144
+ "months": self._months,
145
+ "date_start": self._date_start,
146
+ "date_end": self._date_end,
147
+ }
148
+
149
+ def __str__(self) -> str:
150
+ return f"Action(id={self._action_id.value}, name={self._name})"
151
+
152
+ def __repr__(self) -> str:
153
+ return f"Action(id={self._action_id.value}, name={self._name})"
@@ -0,0 +1,11 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class ActionID(BaseModel):
5
+ value: str
6
+
7
+ def __str__(self) -> str:
8
+ return self.value
9
+
10
+ def __repr__(self) -> str:
11
+ return self.value
@@ -0,0 +1,100 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ from ..actions.action import Action
5
+ from ..actions.action_id import ActionID
6
+ from ..actions.actions_repository import ActionsRepository
7
+ from ..actions.commands.create_action_command import CreateActionCommand
8
+ from ..actions.models.action_track_request import ActionTrackRequest
9
+ from ..actions.models.action_update_request import ActionUpdateRequest
10
+ from ..actions.queries.actions_search_criteria import ActionsSearchCriteria
11
+ from ..users.user_id import UserID
12
+
13
+
14
+ class Actions:
15
+ def __init__(self, repository: ActionsRepository) -> None:
16
+ self._repository = repository
17
+
18
+ def read(self, user_id: UserID, criteria: ActionsSearchCriteria) -> list[Action]:
19
+ actions = self._repository.read(user_id, criteria)
20
+ return actions
21
+
22
+ def read_one(self, user_id: UserID, action_id: str) -> Action | None:
23
+ action_id_obj = ActionID(value=action_id)
24
+ return self._repository.read_one(user_id, action_id_obj)
25
+
26
+ def create(self, user_id: UserID, request: CreateActionCommand) -> ActionID:
27
+ # card = read_card(user_id, request.card_id) if request.card_id else None
28
+ # if card is None and request.card_id is not None:
29
+ # raise ValueError(f"Card with id {request.card_id} not found")
30
+ action = Action(
31
+ action_id=str(uuid4()),
32
+ name=request.name,
33
+ type=request.type,
34
+ created_at=datetime.now().isoformat(),
35
+ updated_at=datetime.now().isoformat(),
36
+ card=None, # TODO: handle card creation
37
+ category=request.category,
38
+ status=request.status,
39
+ months=request.months,
40
+ score=request.score,
41
+ date_start=request.date_start,
42
+ date_end=request.date_end,
43
+ goal=request.goal,
44
+ priority=request.priority,
45
+ time_slot=request.time_slot,
46
+ )
47
+ action_id = self._repository.create(user_id, action)
48
+ return action_id
49
+
50
+ def track(self, user_id: UserID, action_id: str, request: ActionTrackRequest) -> None:
51
+ # First, read the existing action
52
+ existing_action = self._repository.read_one(user_id, ActionID(value=action_id))
53
+ if not existing_action:
54
+ raise ValueError(f"Action with id {action_id} not found")
55
+
56
+ # Update the action with new values
57
+ track_action = Action(
58
+ action_id=existing_action.action_id.value,
59
+ name=existing_action.name,
60
+ type=existing_action.type,
61
+ created_at=existing_action.created_at,
62
+ updated_at=datetime.now().isoformat(),
63
+ notebook=existing_action.notebook, # TODO: handle notebook update
64
+ card=existing_action.card, # TODO: handle card update
65
+ category=existing_action.category,
66
+ status=request.status or existing_action.status,
67
+ score=request.score if request.score is not None else existing_action.score,
68
+ date_start=request.date_start or existing_action.date_start,
69
+ date_end=request.date_end or existing_action.date_end,
70
+ months=existing_action.months, # Not updating months for now
71
+ )
72
+ self._repository.track(user_id, track_action)
73
+
74
+ def update(self, user_id: UserID, action_id: str, request: ActionUpdateRequest) -> None:
75
+ # First, read the existing action
76
+ existing_action = self._repository.read_one(user_id, ActionID(value=action_id))
77
+ if not existing_action:
78
+ raise ValueError(f"Action with id {action_id} not found")
79
+
80
+ # Update the action with new values
81
+ updated_action = Action(
82
+ action_id=existing_action.action_id.value,
83
+ name=request.name or existing_action.name,
84
+ type=request.type or existing_action.type,
85
+ created_at=existing_action.created_at,
86
+ updated_at=datetime.now().isoformat(),
87
+ notebook=existing_action.notebook, # TODO: handle notebook update
88
+ card=existing_action.card, # TODO: handle card update
89
+ category=request.category if request.category is not None else existing_action.category,
90
+ status=request.status or existing_action.status,
91
+ score=request.score if request.score is not None else existing_action.score,
92
+ date_start=request.date_start or existing_action.date_start,
93
+ date_end=request.date_end or existing_action.date_end,
94
+ months=existing_action.months, # Not updating months for now
95
+ )
96
+ self._repository.update(user_id, updated_action)
97
+
98
+ def delete(self, user_id: UserID, action_id: str) -> None:
99
+ action_id_obj = ActionID(value=action_id)
100
+ self._repository.delete(user_id, action_id_obj)
@@ -0,0 +1,32 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from ..users.user_id import UserID
4
+ from .action import Action
5
+ from .action_id import ActionID
6
+ from .queries.actions_search_criteria import ActionsSearchCriteria
7
+
8
+
9
+ class ActionsRepository(ABC):
10
+ @abstractmethod
11
+ def create(self, user_id: UserID, action: Action) -> ActionID:
12
+ pass
13
+
14
+ @abstractmethod
15
+ def update(self, user_id: UserID, action: Action) -> None:
16
+ pass
17
+
18
+ @abstractmethod
19
+ def track(self, user_id: UserID, action: Action) -> None:
20
+ pass
21
+
22
+ @abstractmethod
23
+ def delete(self, user_id: UserID, action_id: ActionID) -> None:
24
+ pass
25
+
26
+ @abstractmethod
27
+ def read(self, user_id: UserID, criteria: ActionsSearchCriteria) -> list[Action]:
28
+ pass
29
+
30
+ @abstractmethod
31
+ def read_one(self, user_id: UserID, action_id: ActionID) -> Action | None:
32
+ pass
@@ -0,0 +1,32 @@
1
+ from dataclasses import dataclass
2
+ from datetime import datetime
3
+
4
+ from pydantic import BaseModel
5
+
6
+
7
+ @dataclass(frozen=True, slots=True)
8
+ class CreateActionCommand(BaseModel):
9
+ name: str
10
+ type: str
11
+ goal: str | None = None
12
+ category: str | None = None
13
+ card_id: str | None = None
14
+ priority: str | None = None
15
+ time_slot: str | None = None
16
+ date_start: str | None = None
17
+ date_end: str | None = None
18
+ status: str | None = None
19
+ score: int | None = None
20
+ months: list[str] | None = None
21
+ notebook_id: str | None = (
22
+ None # deprecated, notebook_id is associated to card_id, so it is not necessary to provide it anymore
23
+ )
24
+ item_id: str | None = (
25
+ None # deprecated, item_id is associated to card_id, so it is not necessary to provide it anymore
26
+ )
27
+ created_at: str = (
28
+ datetime.now().isoformat()
29
+ ) # deprecated, created_at is generated automatically and should not be provided by the user
30
+ updated_at: str = (
31
+ datetime.now().isoformat()
32
+ ) # deprecated, updated_at is generated automatically and should not be provided by the user
@@ -0,0 +1,8 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class ActionTrackRequest(BaseModel):
5
+ status: str | None = None
6
+ score: int | None = None
7
+ date_start: str | None = None
8
+ date_end: str | None = None
@@ -0,0 +1,12 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class ActionUpdateRequest(BaseModel):
5
+ name: str | None = None
6
+ type: str | None = None
7
+ status: str | None = None
8
+ category: str | None = None
9
+ score: int | None = None
10
+ notebook: str | None = None
11
+ date_start: str | None = None
12
+ date_end: str | None = None
@@ -0,0 +1,22 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class ActionsSearchCriteria(BaseModel):
5
+ sort: str | None = None
6
+ sort_direction: str | None = None
7
+ offset: int = 0
8
+ limit: int = 100
9
+ name: str | None = None
10
+ notebook: str | None = None
11
+ status: str | None = None
12
+ type: str | None = None
13
+ date_start: str | None = None
14
+ date_end: str | None = None
15
+ date_start_from: str | None = None
16
+ date_start_to: str | None = None
17
+ date_end_from: str | None = None
18
+ date_end_to: str | None = None
19
+ score: str | None = None
20
+ category: str | None = None
21
+ month: str | None = None
22
+ updated_after: str | None = None
@@ -0,0 +1,63 @@
1
+ from pydantic import BaseModel
2
+
3
+ from .area_id import AreaID
4
+
5
+
6
+ class Area(BaseModel):
7
+ def __init__(
8
+ self,
9
+ area_id: str,
10
+ user_id: str,
11
+ name: str,
12
+ icon: str,
13
+ color: str,
14
+ created_at: str,
15
+ updated_at: str,
16
+ ) -> None:
17
+ self._area_id = AreaID(value=area_id)
18
+ self._user_id = user_id
19
+ self._name = name
20
+ self._icon = icon
21
+ self._color = color
22
+ self._created_at = created_at
23
+ self._updated_at = updated_at
24
+
25
+ @property
26
+ def area_id(self) -> str:
27
+ return self._area_id.value
28
+
29
+ @property
30
+ def user_id(self) -> str:
31
+ return self._user_id
32
+
33
+ @property
34
+ def name(self) -> str:
35
+ return self._name
36
+
37
+ @property
38
+ def icon(self) -> str:
39
+ return self._icon
40
+
41
+ @property
42
+ def color(self) -> str:
43
+ return self._color
44
+
45
+ @property
46
+ def created_at(self) -> str:
47
+ return self._created_at
48
+
49
+ @property
50
+ def updated_at(self) -> str:
51
+ return self._updated_at
52
+
53
+ def to_dict(self) -> dict[str, str]:
54
+ return {
55
+ "area_id": self._area_id.value,
56
+ "user_id": self._user_id,
57
+ "name": self._name,
58
+ "icon": self._icon,
59
+ "color": self._color,
60
+ }
61
+
62
+ def __str__(self) -> str:
63
+ return f"Area(id={self._area_id.value}, name={self._name})"
@@ -0,0 +1,13 @@
1
+ from datetime import datetime
2
+ from uuid import uuid4
3
+
4
+ from pydantic import BaseModel
5
+
6
+
7
+ class AreaCreateRequest(BaseModel):
8
+ uuid: str = str(uuid4())
9
+ name: str
10
+ icon: str
11
+ color: str
12
+ created_at: str = datetime.now().isoformat()
13
+ updated_at: str = datetime.now().isoformat()
@@ -0,0 +1,8 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class AreaID(BaseModel):
5
+ value: str
6
+
7
+ def __str__(self) -> str:
8
+ return self.value
@@ -0,0 +1,7 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class AreaUpdateRequest(BaseModel):
5
+ name: str | None = None
6
+ icon: str | None = None
7
+ color: str | None = None
@@ -0,0 +1,64 @@
1
+ from datetime import datetime
2
+
3
+ from ..areas.area import Area
4
+ from ..areas.area_create_request import AreaCreateRequest
5
+ from ..areas.area_id import AreaID
6
+ from ..areas.area_update_request import AreaUpdateRequest
7
+ from ..areas.areas_repository import AreasRepository
8
+ from ..areas.areas_search_criteria import AreasSearchCriteria
9
+ from ..users.user_id import UserID
10
+
11
+
12
+ class Areas:
13
+ def __init__(self, repository: AreasRepository) -> None:
14
+ self._repository = repository
15
+
16
+ def read(self, user_id: UserID, criteria: AreasSearchCriteria) -> list[Area]:
17
+ criteria.user_id = user_id.value
18
+ return self._repository.read(criteria)
19
+
20
+ def read_one(self, user_id: UserID, area_id: str) -> Area | None:
21
+ area = self._repository.read_one(area_id=AreaID(value=area_id))
22
+ if area is None:
23
+ return area
24
+ if area.user_id != user_id.value:
25
+ raise ValueError("Forbidden access")
26
+ return area
27
+
28
+ def create(self, user_id: UserID, request: AreaCreateRequest) -> AreaID:
29
+ area = Area(
30
+ area_id=request.uuid,
31
+ user_id=user_id.value,
32
+ name=request.name,
33
+ icon=request.icon,
34
+ color=request.color,
35
+ created_at=request.created_at,
36
+ updated_at=request.updated_at,
37
+ )
38
+ return self._repository.create(area)
39
+
40
+ def update(self, user_id: UserID, area_id: str, request: AreaUpdateRequest) -> Area:
41
+ existing_area = self.read_one(user_id=user_id, area_id=area_id)
42
+ if existing_area is None:
43
+ raise ValueError(f"Area with id {area_id} not found")
44
+
45
+ updated_area = Area(
46
+ area_id=existing_area.area_id,
47
+ user_id=user_id.value,
48
+ name=request.name if request.name is not None else existing_area.name,
49
+ icon=request.icon if request.icon is not None else existing_area.icon,
50
+ color=request.color if request.color is not None else existing_area.color,
51
+ created_at=existing_area.created_at,
52
+ updated_at=datetime.now().isoformat(),
53
+ )
54
+ self._repository.update(area=updated_area)
55
+ return updated_area
56
+
57
+ def delete(self, user_id: UserID, area_id: str) -> None:
58
+ existing_area = self.read_one(user_id=user_id, area_id=area_id)
59
+ if existing_area is None:
60
+ raise ValueError(f"Area with id {area_id} not found")
61
+ if existing_area.user_id != user_id.value:
62
+ raise ValueError(f"User {user_id.value} is not the owner of area {area_id}")
63
+
64
+ self._repository.delete(area_id=AreaID(value=area_id))