Skip to content

Commit

Permalink
feat: critics ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
suchencjusz committed Sep 16, 2024
1 parent c8a63ed commit edad238
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/filman_server/database/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,30 @@ def create_filmweb_movie(db: Session, movie: schemas.FilmWebMovie) -> models.Fil
year=movie.year,
poster_url=movie.poster_url,
community_rate=movie.community_rate,
critics_rate=movie.critics_rate,
)

db.add(db_movie)
db.commit()
db.refresh(db_movie)

return db_movie


def update_filmweb_movie(db: Session, movie: schemas.FilmWebMovie):
db_movie = get_movie_filmweb_id(db, movie.id)
if db_movie is None:
return create_filmweb_movie(db, movie)

db_movie.title = movie.title
db_movie.year = movie.year
db_movie.poster_url = movie.poster_url
db_movie.community_rate = movie.community_rate
db_movie.critics_rate = movie.critics_rate

db.commit()
db.refresh(db_movie)

return db_movie


Expand Down Expand Up @@ -357,6 +363,7 @@ def create_filmweb_user_watched_movie(db: Session, user_watched_movie: schemas.F
year=None,
poster_url=None,
community_rate=None,
critics_rate=None,
)

create_filmweb_movie(db, watched_movie)
Expand Down
1 change: 1 addition & 0 deletions src/filman_server/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class __FilmwebMedia(Base):
year = Column(SmallInteger)
poster_url = Column(String(128))
community_rate = Column(Float)
critics_rate = Column(Float)


class FilmWebMovie(__FilmwebMedia):
Expand Down
4 changes: 4 additions & 0 deletions src/filman_server/database/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class FilmWebMovie(BaseModel):
year: int | None
poster_url: str | None
community_rate: float | None
critics_rate: float | None

class Config:
orm_mode = True
Expand All @@ -145,6 +146,7 @@ class FilmWebMovieCreate(BaseModel):
year: int | None
poster_url: str | None
community_rate: float | None
critics_rate: float | None

class Config:
orm_mode = True
Expand Down Expand Up @@ -186,6 +188,7 @@ class FilmWebSeries(BaseModel):
other_year: int
poster_url: str
community_rate: float
critics_rate: float

class Config:
orm_mode = True
Expand All @@ -198,6 +201,7 @@ class FilmWebSeriesCreate(BaseModel):
other_year: int | None
poster_url: str | None
community_rate: float | None
critics_rate: float | None

class Config:
orm_mode = True
Expand Down
2 changes: 0 additions & 2 deletions src/filman_server/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any, Dict, List, Optional

import sentry_sdk
import uvicorn
from fastapi import Depends, FastAPI, HTTPException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,23 @@ def test_update_movie(test_client):
"year": 1999,
"poster_url": "https://fwcdn.pl/fpo/06/28/628/7685907_1.10.webp",
"community_rate": 7.6,
"critics_rate": 8.0,
},
{
"id": 1,
"title": "Paragraf 187",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/01/1/7418875_1.10.webp",
"community_rate": 7.3,
"critics_rate": 7.0,
},
{
"id": 2,
"title": "Adwokat diabła",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/02/2/6956729_1.10.webp",
"community_rate": 7.9,
"critics_rate": 8.0,
},
]

Expand Down Expand Up @@ -95,20 +98,23 @@ def test_add_watched_movie(test_client):
"year": 1999,
"poster_url": "https://fwcdn.pl/fpo/06/28/628/7685907_1.10.webp",
"community_rate": 7.6,
"critics_rate": 8.0,
},
{
"id": 1,
"title": "Paragraf 187",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/01/1/7418875_1.10.webp",
"community_rate": 7.3,
"critics_rate": 7.0,
},
{
"id": 2,
"title": "Adwokat diabła",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/02/2/6956729_1.10.webp",
"community_rate": 7.9,
"critics_rate": 8.0,
},
]

Expand Down Expand Up @@ -334,20 +340,23 @@ def test_user_mapping_delete(test_client):
"year": 1999,
"poster_url": "https://fwcdn.pl/fpo/06/28/628/7685907_1.10.webp",
"community_rate": 7.6,
"critics_rate": 8.0,
},
{
"id": 1,
"title": "Paragraf 187",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/01/1/7418875_1.10.webp",
"community_rate": 7.3,
"critics_rate": 7.0,
},
{
"id": 2,
"title": "Adwokat diabła",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/02/2/6956729_1.10.webp",
"community_rate": 7.9,
"critics_rate": 8.0,
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,23 @@ def test_tasks_new_scrap_filmweb_movies(test_client: TestClient):
"year": 1999,
"poster_url": "https://fwcdn.pl/fpo/06/28/628/7685907_1.10.webp",
"community_rate": 7.6,
"critics_rate": 8.0,
},
{
"id": 1,
"title": "Paragraf 187",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/01/1/7418875_1.10.webp",
"community_rate": 7.3,
"critics_rate": 7.0,
},
{
"id": 2,
"title": "Adwokat diabła",
"year": 1997,
"poster_url": "https://fwcdn.pl/fpo/00/02/2/6956729_1.10.webp",
"community_rate": 7.9,
"critics_rate": 7.0,
},
]

Expand Down

0 comments on commit edad238

Please sign in to comment.