generated from moevm/nsql-clean-tempate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from moevm/dev
Dev to main
- Loading branch information
Showing
80 changed files
with
5,725 additions
and
1,634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,31 +22,56 @@ | |
- Администратор | ||
```json | ||
{ | ||
"email": "[email protected]", | ||
"password": "admin123" | ||
"email": "[email protected]", | ||
"password": "AdminPass123" | ||
} | ||
``` | ||
|
||
- Заказчик | ||
```json | ||
{ | ||
"email": "[email protected]", | ||
"password": "CustPass123" | ||
} | ||
``` | ||
|
||
- Прораб | ||
```json | ||
{ | ||
"email": "maria.smirnova@example.com", | ||
"password": "securepassword1" | ||
"email": "foreman1@example.com", | ||
"password": "ForemanPass123" | ||
} | ||
``` | ||
|
||
- Работник | ||
- Работник 1 | ||
```json | ||
{ | ||
"email": "dmitry.kuznetsov@example.com", | ||
"password": "securepassword2" | ||
"email": "worker1@example.com", | ||
"password": "WorkerPass123" | ||
} | ||
``` | ||
|
||
- Заказчик | ||
- Работник 2 | ||
```json | ||
{ | ||
"email": "alex.sidorov@example.com", | ||
"password": "securepassword3" | ||
"email": "worker2@example.com:", | ||
"password": "WorkerPass456" | ||
} | ||
``` | ||
``` | ||
|
||
- Работник 3 | ||
```json | ||
{ | ||
"email": "[email protected]:", | ||
"password": "WorkerPass789" | ||
} | ||
``` | ||
|
||
- Работник 4 | ||
```json | ||
{ | ||
"email": "[email protected]", | ||
"password": "MysticWolf2024!" | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Any | ||
|
||
from bson import ObjectId | ||
from motor.motor_asyncio import AsyncIOMotorCollection | ||
|
||
from schemas.utils import get_date_now, object_id_to_str | ||
|
||
|
||
class BaseDao: | ||
collection: AsyncIOMotorCollection = None | ||
|
||
@classmethod | ||
async def _create(cls, data: dict) -> str: | ||
if cls.collection is not None: | ||
data['updated_at'] = get_date_now() | ||
data['created_at'] = get_date_now() | ||
result = await cls.collection.insert_one(data) | ||
return str(result.inserted_id) | ||
|
||
@classmethod | ||
async def _get_one_by_id(cls, id: str) -> dict: | ||
if cls.collection is not None: | ||
data = await cls.collection.find_one({"_id": ObjectId(id)}) | ||
return object_id_to_str(data) | ||
|
||
@classmethod | ||
async def _get_one_by_field(cls, field: str, data: str) -> dict: | ||
if cls.collection is not None: | ||
data = await cls.collection.find_one({field: data}) | ||
return object_id_to_str(data) | ||
|
||
@classmethod | ||
async def _update(cls, id: str, data: dict) -> str | None: | ||
if cls.collection is not None: | ||
data['updated_at'] = get_date_now() | ||
result = await cls.collection.update_one( | ||
{"_id": ObjectId(id)}, | ||
{"$set": data} | ||
) | ||
|
||
if result.modified_count == 0: | ||
return None | ||
return id | ||
|
||
@classmethod | ||
async def _update_with_query(cls, query: dict[str, Any], data: dict[str, Any]) -> str | None: | ||
if cls.collection is not None: | ||
result = await cls.collection.update_one(query, data) | ||
if result.modified_count == 0: | ||
return None | ||
return str(query["_id"]) | ||
|
||
# @classmethod | ||
# async def _find_with_filters(cls, query: dict) -> dict: | ||
# if cls.collection: | ||
# | ||
|
||
@classmethod | ||
async def _delete_by_id(cls, id: str) -> str | None: | ||
if cls.collection is not None: | ||
result = await cls.collection.delete_one({"_id": ObjectId(id)}) | ||
|
||
if result.deleted_count == 0: | ||
return None | ||
return id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.