Skip to content

Commit

Permalink
Merge pull request #13 from moevm/dev
Browse files Browse the repository at this point in the history
Dev to main
  • Loading branch information
Dlexeyn authored Dec 9, 2024
2 parents 9ec2e73 + 9fa4c65 commit 0a52ed2
Show file tree
Hide file tree
Showing 80 changed files with 5,725 additions and 1,634 deletions.
47 changes: 36 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
}
```

4 changes: 3 additions & 1 deletion backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ MONGO_INITDB_DATABASE=fastapi

DATABASE_URL=mongodb://admin:password123@mongo_db:27017/?authSource=admin

ACCESS_TOKEN_EXPIRES_IN=15
ACCESS_TOKEN_EXPIRES_IN=60
REFRESH_TOKEN_EXPIRES_IN=60
JWT_ALGORITHM=HS256
JWT_SECRET_KEY=09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7

CLIENT_ORIGIN=http://app-frontend:8080

DEFAULT_DATA_FILE=./dump/dump.json

JWT_PRIVATE_KEY=LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcEFJQkFBS0NBUUVBMExNZXQvc296T1Rne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OWUFDVkY2T3c9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQ==
JWT_PUBLIC_KEY=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUEwTE1ldC9zb3pPVGd5WWJOK1ltdwozTnlUYkFRemU4eDRQVHk2TmN4K3BVc1RTemh1ZVpvRGdFTTBma1VUdWN3aTJQRFpZd1hySGtOYUNNV09sdkRXCnUzc1RoS3VUOG8zVEYyUy9hRmJ5eE5jenpuNG1QcjBTeTZVRkozb1dkcEZqQ2k2cUUyM2Vmb0xkOEhqcnVGVzQKeXRyZkxJQU1uT0RQdVk5R3VadkduT1B2Z2VoK3loejkrQ1Z3azZsZFpLNnNhVktkME9ub0xTWDlTVERaYmtTdAp1d0VqVG9ld0ZqMjNwdW14b3hLNCtLM2czUFpjckRwdkV0WTF4TWFsQnJWNUhENjBCVzVuajhsaCttbklBSWtZCjJBSkRRYzV5MFJpRlZjcy9JVmxPQk5HdXJBZ3hiUkZDVVc5UFF2NUJUbHA4NmU2VGo1WE8va2FHdmF1dFVJL3IKVVFJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0t
2 changes: 2 additions & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Settings(BaseSettings):
JWT_SECRET_KEY: str

CLIENT_ORIGIN: str

DEFAULT_DATA_FILE: str

class Config:
env_file = "../.env"
Expand Down
65 changes: 65 additions & 0 deletions backend/dao/base.py
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
13 changes: 6 additions & 7 deletions backend/dao/messager.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from datetime import datetime, timezone
from bson import ObjectId
from fastapi.params import Depends

from database import db
from schemas.messager import Participant, LastMessage, Chat, Message, CreateChatResponse, ChatResponse, CreateMessage, \
from schemas.messager import Participant, LastMessage, Chat, Message, ChatResponse, CreateMessage, \
StatusMsg, MessageResponse
from schemas.user import UserDao
from schemas.user import User
from schemas.utils import get_date_now


async def create_chat(user_sender: UserDao, user_receiver: UserDao, content: str) -> ChatResponse | None:
async def create_chat(user_sender: User, user_receiver: User, content: str) -> ChatResponse | None:
chat_collection = db.get_collection('chat')
message_collection = db.get_collection('message')

Expand Down Expand Up @@ -138,7 +137,7 @@ async def add_message_to_chat(user_id: str, message_data: CreateMessage) -> str
{
"$set": {
"lastMessage": last_message.model_dump(),
"updated_at": datetime.now(timezone.utc)
"updated_at": get_date_now()
}
},
return_document=True
Expand All @@ -159,7 +158,7 @@ async def create_message(user_id: str, message_data: CreateMessage) -> MessageRe
sender=user_id,
content=message_data.content,
status=StatusMsg.unread,
timestamp=datetime.now(timezone.utc)
timestamp=get_date_now()
)

insert_result = await message_collection.insert_one(message.model_dump())
Expand Down
Loading

0 comments on commit 0a52ed2

Please sign in to comment.