Skip to content

Commit

Permalink
Fix/movie (#7)
Browse files Browse the repository at this point in the history
* feat: 영화 정보 반환 시 리뷰 개수 추가

* fix: 영화 러닝타임 nullable

* new alembic version

* chore: settings prod 설정
  • Loading branch information
anandashin authored Jan 9, 2025
1 parent 9aa4495 commit 7f7097a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
7 changes: 4 additions & 3 deletions watchapedia/app/movie/dto/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def validate_year(value: int | None) -> str:
return value

def validate_running_time(value: int | None) -> int:
if value is None or value < 1 or value > 900:
if value is not None and (value < 1 or value > 900):
raise InvalidFieldFormatError("running time")
return value

Expand Down Expand Up @@ -43,7 +43,7 @@ class AddMovieRequest(BaseModel):
original_title: str
year: Annotated[int, AfterValidator(validate_year)]
synopsis: str | None = None
running_time: Annotated[int, AfterValidator(validate_running_time)]
running_time: Annotated[int | None, AfterValidator(validate_running_time)] = None
grade: Annotated[str | None, AfterValidator(validate_grade)] = None
poster_url: Annotated[str | None, AfterValidator(validate_url)] = None
backdrop_url: Annotated[str | None, AfterValidator(validate_url)] = None
Expand All @@ -54,6 +54,7 @@ class AddMovieRequest(BaseModel):
class UpdateMovieRequest(BaseModel):
synopsis: str | None = None
grade: Annotated[str | None, AfterValidator(validate_grade)] = None
running_time: Annotated[int | None, AfterValidator(validate_running_time)] = None
average_rating: float | None = None
poster_url: Annotated[str | None, AfterValidator(validate_url)] = None
backdrop_url: Annotated[str | None, AfterValidator(validate_url)] = None
Expand All @@ -63,7 +64,7 @@ class AddMovieListRequest(BaseModel):
original_title: str
year: Annotated[int, AfterValidator(validate_year)]
synopsis: str | None = None
running_time: Annotated[int, AfterValidator(validate_running_time)]
running_time: Annotated[int | None, AfterValidator(validate_running_time)]
grade: Annotated[str | None, AfterValidator(validate_grade)] = None
poster_url: Annotated[str | None, AfterValidator(validate_url)] = None
backdrop_url: Annotated[str | None, AfterValidator(validate_url)] = None
Expand Down
3 changes: 2 additions & 1 deletion watchapedia/app/movie/dto/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class MovieDataResponse(BaseModel):
countries: list[str]
synopsis: str
average_rating: float | None
running_time: int
ratings_count: int
running_time: int | None
grade: str | None
poster_url: str | None
backdrop_url: str | None
Expand Down
2 changes: 1 addition & 1 deletion watchapedia/app/movie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Movie(Base):
year: Mapped[int] = mapped_column(Integer, nullable=False)
synopsis: Mapped[str] = mapped_column(String(1000), nullable=False, default="등록된 소개글이 없습니다.")
average_rating: Mapped[float | None] = mapped_column(Float, default=None)
running_time: Mapped[int] = mapped_column(Integer, nullable=False)
running_time: Mapped[int | None] = mapped_column(Integer)
grade: Mapped[str | None] = mapped_column(String(20))
poster_url: Mapped[str | None] = mapped_column(String(500))
backdrop_url: Mapped[str | None] = mapped_column(String(500))
Expand Down
7 changes: 5 additions & 2 deletions watchapedia/app/movie/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def add_movie(
original_title: str,
year: int,
synopsis: str,
running_time: int,
running_time: int | None,
grade: str | None,
poster_url: str | None,
backdrop_url: str | None
Expand All @@ -46,6 +46,7 @@ def update_movie(
movie: Movie,
synopsis: str | None,
grade: str | None,
running_time: int | None,
average_rating: float | None,
poster_url: str | None,
backdrop_url: str | None
Expand All @@ -54,6 +55,8 @@ def update_movie(
movie.synopsis = synopsis
if grade:
movie.grade = grade
if running_time:
movie.running_time = running_time
if average_rating:
movie.average_rating = average_rating
if poster_url:
Expand Down Expand Up @@ -145,7 +148,7 @@ def add_movie_participant(self, movie: Movie, participant: Participant, role: st
self.session.flush()

# 동명의 영화가 다수 존재. 하나로 특정하려면 다른 필드와 조합해서 검색
def get_movie(self, title: str, year: int, running_time: int) -> Movie | None:
def get_movie(self, title: str, year: int, running_time: int | None) -> Movie | None:
get_movie_query = select(Movie).filter(
(Movie.title==title)
& (Movie.year==year)
Expand Down
9 changes: 6 additions & 3 deletions watchapedia/app/movie/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def add_movie(
original_title: str,
year: int,
synopsis: str | None,
running_time: int,
running_time: int | None,
grade: str | None,
poster_url: str | None,
backdrop_url: str | None,
Expand Down Expand Up @@ -72,7 +72,7 @@ def add_movie(
return self._process_movie_response(movie)

def raise_if_movie_exist(
self, title: str, year: int, running_time: int, chart_type: str | None, rank: int | None
self, title: str, year: int, running_time: int | None, chart_type: str | None, rank: int | None
) -> Movie | None:
"""
이미 해당 영화가 존재하고, 차트 정보가 업데이트 되었을 때 Movie 객체 반환.
Expand All @@ -98,19 +98,21 @@ def update_movie(
movie_id: int,
synopsis: str | None,
grade: str | None,
running_time: int | None,
average_rating: float | None,
poster_url: str | None,
backdrop_url: str | None
) -> None:
movie = self.movie_repository.get_movie_by_movie_id(movie_id)
if not movie:
raise MovieNotFoundError()
if not any([synopsis, grade, average_rating, poster_url, backdrop_url]):
if not any([synopsis, grade, running_time, average_rating, poster_url, backdrop_url]):
raise InvalidFormatError()
self.movie_repository.update_movie(
movie=movie,
synopsis=synopsis,
grade=grade,
running_time=running_time,
average_rating=average_rating,
poster_url=poster_url,
backdrop_url=backdrop_url
Expand Down Expand Up @@ -174,6 +176,7 @@ def _process_movie_response(self, movie: Movie) -> MovieDataResponse:
],
synopsis=movie.synopsis,
average_rating=movie.average_rating,
ratings_count=len(movie.reviews),
running_time=movie.running_time,
grade=movie.grade,
poster_url=movie.poster_url,
Expand Down
1 change: 1 addition & 0 deletions watchapedia/app/movie/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def update_movie(
movie_id,
update_movie_request.synopsis,
update_movie_request.grade,
update_movie_request.running_time,
update_movie_request.average_rating,
update_movie_request.poster_url,
update_movie_request.backdrop_url
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""movie running_time nullable
Revision ID: 1b8847f3edf8
Revises: 71a45d95f65c
Create Date: 2025-01-09 15:32:30.649786
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '1b8847f3edf8'
down_revision: Union[str, None] = '71a45d95f65c'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('movie', 'running_time',
existing_type=mysql.INTEGER(),
nullable=True)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('movie', 'running_time',
existing_type=mysql.INTEGER(),
nullable=False)
# ### end Alembic commands ###

0 comments on commit 7f7097a

Please sign in to comment.