-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinterface.py
More file actions
61 lines (49 loc) · 1.36 KB
/
interface.py
File metadata and controls
61 lines (49 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import Self, Optional
from abc import abstractmethod, ABC
from pydantic import (
BaseModel,
PrivateAttr,
ConfigDict,
)
class ApiBaseModel(BaseModel, ABC):
"""
Base class for all models in the API.
This class is used to define the common attributes and
methods that all models in the API should have.
"""
_id: Optional[str] = PrivateAttr(default=None)
model_config = ConfigDict(
use_enum_values=True,
validate_default=True,
validate_all_in_root=True,
validate_assignment=True,
ser_json_exclude_none=True,
)
def set_id(self, value):
self._id = value
def get_id(self):
return self._id
@property
@abstractmethod
def NAME(): # pylint: disable=invalid-name, no-method-argument
pass
@property
@abstractmethod
def METHODS(): # pylint: disable=invalid-name, no-method-argument
pass
@staticmethod
@abstractmethod
def UPDATED(): # pylint: disable=invalid-name
pass
@staticmethod
@abstractmethod
def DELETED(): # pylint: disable=invalid-name
pass
@staticmethod
@abstractmethod
def CREATED(model_id: str): # pylint: disable=invalid-name
pass
@staticmethod
@abstractmethod
def RETRIEVED(model_instance: type(Self)): # pylint: disable=invalid-name
pass