|
3 | 3 | The `models` module provides core data structures and types used throughout the application, following clean |
4 | 4 | architecture principles. |
5 | 5 |
|
6 | | -## DTOs (Data Transfer Objects) |
7 | | - |
8 | | -### Base DTOs |
9 | | - |
10 | | -Base classes for all DTOs with common functionality. |
| 6 | +## Quick Start |
11 | 7 |
|
12 | 8 | ```python |
13 | 9 | from archipy.models.dtos.base_dtos import BaseDTO |
14 | | -from pydantic import BaseModel |
| 10 | +from archipy.models.entities.sqlalchemy.base_entities import BaseEntity |
15 | 11 |
|
| 12 | +# Create a DTO |
16 | 13 | class UserDTO(BaseDTO): |
17 | 14 | id: str |
18 | 15 | username: str |
19 | 16 | email: str |
20 | | - created_at: datetime |
21 | | -``` |
22 | | - |
23 | | -::: archipy.models.dtos.base_dtos |
24 | | -options: |
25 | | -show_root_heading: true |
26 | | -show_source: true |
27 | | - |
28 | | -### Protobuf DTOs |
29 | 17 |
|
30 | | -Base class for DTOs that can be converted to and from Google Protocol Buffer messages. |
31 | | - |
32 | | -```python |
33 | | -from archipy.models.dtos.base_protobuf_dto import BaseProtobufDTO |
34 | | -from google.protobuf.message import Message |
35 | | - |
36 | | -class UserProtobufDTO(BaseProtobufDTO): |
37 | | - _proto_class = UserProto # Your protobuf message class |
38 | | - |
39 | | - id: str |
| 18 | +# Create an entity |
| 19 | +class User(BaseEntity): |
| 20 | + __tablename__ = "users" |
40 | 21 | username: str |
41 | 22 | email: str |
42 | | - |
43 | | -# Convert from protobuf to DTO |
44 | | -user_dto = UserProtobufDTO.from_proto(protobuf_message) |
45 | | - |
46 | | -# Convert DTO to protobuf |
47 | | -protobuf_message = user_dto.to_proto() |
48 | 23 | ``` |
49 | 24 |
|
50 | | -::: archipy.models.dtos.base_protobuf_dto |
51 | | -options: |
52 | | -show_root_heading: true |
53 | | -show_source: true |
54 | | - |
55 | | -### Email DTOs |
56 | | - |
57 | | -DTOs for email-related operations. |
58 | | - |
59 | | -```python |
60 | | -from archipy.models.dtos.email_dtos import EmailAttachmentDTO |
| 25 | +## Core Components |
61 | 26 |
|
62 | | -attachment = EmailAttachmentDTO( |
63 | | - filename="document.pdf", |
64 | | - content_type="application/pdf", |
65 | | - content=b"..." |
66 | | -) |
67 | | -``` |
68 | | - |
69 | | -::: archipy.models.dtos.email_dtos |
70 | | -options: |
71 | | -show_root_heading: true |
72 | | -show_source: true |
| 27 | +### DTOs (Data Transfer Objects) |
73 | 28 |
|
74 | | -### Error DTOs |
| 29 | +**Base DTOs** - Base classes for all DTOs with common functionality |
| 30 | +**Protobuf DTOs** - DTOs that can be converted to/from Google Protocol Buffer messages |
| 31 | +**Email DTOs** - DTOs for email-related operations |
| 32 | +**Error DTOs** - Standardized error response format |
| 33 | +**Pagination DTO** - Handles pagination parameters for queries |
| 34 | +**Range DTOs** - Handles range-based queries (integer, date, datetime) |
| 35 | +**Search Input DTO** - Standardized search input format |
| 36 | +**Sort DTO** - Handles sorting parameters |
75 | 37 |
|
76 | | -Standardized error response format. |
| 38 | +### Entities |
77 | 39 |
|
78 | | -```python |
79 | | -from archipy.models.dtos.error_dto import ErrorDetailDTO |
| 40 | +**Base Entities** - Base classes for SQLAlchemy entities with common functionality |
| 41 | +**Update Tracking** - Entities with automatic update timestamp tracking |
| 42 | +**Soft Deletion** - Entities with soft deletion support |
| 43 | +**Admin Tracking** - Entities with admin user tracking |
| 44 | +**Manager Tracking** - Entities with manager user tracking |
80 | 45 |
|
81 | | -error = ErrorDetailDTO( |
82 | | - code="USER_NOT_FOUND", |
83 | | - message_en="User not found", |
84 | | -) |
85 | | -``` |
| 46 | +### Errors |
86 | 47 |
|
87 | | -::: archipy.models.dtos.error_dto |
88 | | -options: |
89 | | -show_root_heading: true |
90 | | -show_source: true |
| 48 | +**Base Error** - Base class for all custom exceptions |
| 49 | +**Auth Errors** - Authentication and authorization errors |
| 50 | +**Business Errors** - Business logic violation errors |
| 51 | +**Database Errors** - Database operation errors |
| 52 | +**Network Errors** - Network communication errors |
| 53 | +**Resource Errors** - Resource not found or access errors |
| 54 | +**System Errors** - System-level errors |
| 55 | +**Validation Errors** - Data validation errors |
91 | 56 |
|
92 | | -### Pagination DTO |
| 57 | +### Types |
93 | 58 |
|
94 | | -Handles pagination parameters for queries. |
| 59 | +**Base Types** - Common type definitions |
| 60 | +**Email Types** - Email-related type definitions |
| 61 | +**Error Message Types** - Error message type definitions |
| 62 | +**Language Type** - Language enumeration |
| 63 | +**Sort Order Type** - Sort order enumeration |
| 64 | +**Time Interval Unit Type** - Time interval unit enumeration |
95 | 65 |
|
96 | | -```python |
97 | | -from archipy.models.dtos.pagination_dto import PaginationDTO |
| 66 | +## Examples |
98 | 67 |
|
99 | | -pagination = PaginationDTO( |
100 | | - page=1, |
| 68 | +For detailed examples, see: |
| 69 | +- [Protobuf DTOs](../examples/models/protobuf_dtos.md) |
| 70 | +- [Error Handling](../examples/error_handling.md) |
101 | 71 | page_size=10, |
102 | 72 | total_items=100 |
103 | 73 | ) |
|
0 commit comments