Skip to content

Commit

Permalink
- Added sorting by dates for service.get_contacts_by_user()
Browse files Browse the repository at this point in the history
- Updated some libraries in requirements-base.txt
  • Loading branch information
onstabb committed Jan 1, 2024
1 parent 6b0e2b7 commit 2c29d33
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
Binary file modified data/geo/data.db
Binary file not shown.
4 changes: 2 additions & 2 deletions requirements-base.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
fastapi~=0.105.0
pydantic~=2.5.2
pydantic~=2.5.3
python-jose~=3.3.0
mongoengine~=0.27.0
Pillow~=10.1.0
passlib~=1.7.4
python-dotenv~=1.0.0
phonenumbers~=8.13.27
pycities~=0.1.5
pycities~=0.2.0
telesign~=2.2.2
bcrypt~=4.0.1
apscheduler~=3.10.4
Expand Down
4 changes: 2 additions & 2 deletions src/contacts/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class ContactUpdateAction(enum.StrEnum):

@enum.unique
class ContactType(enum.StrEnum):
LIKE = "likes"
DIALOG = "dialogs"
LIKE = "like"
DIALOG = "dialog"
21 changes: 11 additions & 10 deletions src/contacts/schemas.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from datetime import datetime
from functools import cached_property
from typing import Any, Self
from datetime import datetime, timezone
from typing import Any, Self, Annotated

from bson import ObjectId
from pydantic import AliasChoices, BaseModel, Field, constr, computed_field, model_validator
from pydantic import AliasChoices, BaseModel, Field, constr, model_validator, AfterValidator

from contacts import config
from contacts.enums import ContactState, ContactUpdateAction
from models import PydanticObjectId, DateTimeFromObjectId
from users.schemas import UserPublicOut


UtcDatetime = Annotated[datetime, AfterValidator(lambda value: value.astimezone(timezone.utc))]


class MessageBase(BaseModel):
text: constr(max_length=config.MESSAGE_MAX_LENGTH, min_length=1)

Expand All @@ -21,18 +22,18 @@ class MessageIn(MessageBase):

class MessageOut(MessageBase):
sender: PydanticObjectId | UserPublicOut
date: datetime = Field(validation_alias="created_at")
date: UtcDatetime = Field(validation_alias="created_at")


class ContactBaseOut(BaseModel):
initiator: UserPublicOut | PydanticObjectId = Field(exclude=True)
respondent: UserPublicOut | PydanticObjectId = Field(exclude=True)
initiator_last_update_at: datetime = Field(exclude=True)
respondent_last_update_at: datetime | None = Field(exclude=True)
initiator_last_update_at: UtcDatetime = Field(exclude=True)
respondent_last_update_at: UtcDatetime | None = Field(exclude=True)

opposite_user: UserPublicOut | None = None
opposite_user_last_update_at: datetime | None = None
last_update_at: datetime | None = None
opposite_user_last_update_at: UtcDatetime | None = None
last_update_at: UtcDatetime | None = None
created_at: DateTimeFromObjectId = Field(validation_alias=AliasChoices("_id", "id"),)

@model_validator(mode="after")
Expand Down
1 change: 1 addition & 0 deletions src/contacts/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def get_contacts_by_user(user: User, *, limit: int = 0, **filters) -> list[dict]
{
"$match": {"opposite_user.is_active": True, "opposite_user.banned": False, },
},
{"$sort": {"messages.created_at": -1, "_id": -1}},
]

if limit:
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
async def lifespan(_app_instance: FastAPI):
init_db(host=config.DB_URI, db=config.DB_NAME)
scheduler.start()
geonames_db.connect(datasource=config.DB_GEONAMES_DATA_SOURCE)
geonames_db.connect(datasource=config.DB_GEONAMES_DATA_SOURCE,)
create_admin()
yield
close_db()
Expand Down
2 changes: 1 addition & 1 deletion src/photos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if not BUCKET_FILES_LOCAL_PATH.exists():
BUCKET_FILES_LOCAL_PATH.mkdir()

SERVER_STATIC_IMAGES_URL = f'{global_config.SERVER_URL}/static/images'
SERVER_STATIC_IMAGES_URL = f'{global_config.SERVER_URL}/static/bucket'
SUPPORTED_IMAGE_FORMATS = ('jpeg', 'jpg')
SUPPORTED_IMAGE_MEDIA_TYPES = tuple(f'image/{img_format}' for img_format in SUPPORTED_IMAGE_FORMATS)
FILE_TOKEN_LENGTH = 24
Expand Down

0 comments on commit 2c29d33

Please sign in to comment.