Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added nullable user_id #32

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions migrations/versions/0fbda260a023_add_user_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""add user_id

Revision ID: 0fbda260a023
Revises: 5659e13277b6
Create Date: 2024-11-08 12:49:18.796942

"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '0fbda260a023'
down_revision = '5659e13277b6'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('comment', sa.Column('user_id', sa.Integer(), nullable=True))


def downgrade():
op.drop_column('comment', 'user_id')
4 changes: 2 additions & 2 deletions rating_api/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import re

from sqlalchemy import Integer, not_
from sqlalchemy import not_
from sqlalchemy.exc import NoResultFound
from sqlalchemy.orm import Mapped, Query, Session, as_declarative, declared_attr, mapped_column
from sqlalchemy.orm import Query, Session, as_declarative, declared_attr

from rating_api.exceptions import ObjectNotFound

Expand Down
3 changes: 2 additions & 1 deletion rating_api/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import uuid
from enum import Enum

from sqlalchemy import UUID, Boolean, DateTime
from sqlalchemy import UUID, DateTime
from sqlalchemy import Enum as DbEnum
from sqlalchemy import ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
Expand Down Expand Up @@ -37,6 +37,7 @@ class Lecturer(BaseDbModel):

class Comment(BaseDbModel):
uuid: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4)
user_id: Mapped[int] = mapped_column(Integer, nullable=True)
create_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False)
update_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False)
subject: Mapped[str] = mapped_column(String, nullable=False)
Expand Down
4 changes: 2 additions & 2 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ async def get_comments(
raise ForbiddenAction(Comment)
else:
result.comments = [comment for comment in result.comments if comment.review_status is ReviewStatus.APPROVED]

result.comments = result.comments[offset : limit + offset]

if "create_ts" in order_by:
result.comments.sort(key=lambda comment: comment.create_ts)
result.total = len(result.comments)
Expand Down
4 changes: 3 additions & 1 deletion rating_api/routes/lecturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ async def get_lecturers(
if "general" in order_by:
result.lecturers.sort(key=lambda item: (item.mark_general is None, item.mark_general))
if subject:
result.lecturers = [lecturer for lecturer in result.lecturers if lecturer.subjects and subject in lecturer.subjects]
result.lecturers = [
lecturer for lecturer in result.lecturers if lecturer.subjects and subject in lecturer.subjects
]
result.total = len(result.lecturers)
return result

Expand Down
1 change: 1 addition & 0 deletions rating_api/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class CommentGet(Base):
uuid: UUID
user_id: int
create_ts: datetime.datetime
update_ts: datetime.datetime
subject: str
Expand Down
Loading