diff --git a/watchapedia/app/movie/dto/requests.py b/watchapedia/app/movie/dto/requests.py index 07c3284..35947bd 100644 --- a/watchapedia/app/movie/dto/requests.py +++ b/watchapedia/app/movie/dto/requests.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/watchapedia/app/movie/dto/responses.py b/watchapedia/app/movie/dto/responses.py index ffdb7ca..5491b13 100644 --- a/watchapedia/app/movie/dto/responses.py +++ b/watchapedia/app/movie/dto/responses.py @@ -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 diff --git a/watchapedia/app/movie/models.py b/watchapedia/app/movie/models.py index 81d7aba..5553c32 100644 --- a/watchapedia/app/movie/models.py +++ b/watchapedia/app/movie/models.py @@ -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)) diff --git a/watchapedia/app/movie/repository.py b/watchapedia/app/movie/repository.py index d8334db..0686220 100644 --- a/watchapedia/app/movie/repository.py +++ b/watchapedia/app/movie/repository.py @@ -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 @@ -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 @@ -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: @@ -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) diff --git a/watchapedia/app/movie/service.py b/watchapedia/app/movie/service.py index 14f45b6..8004c75 100644 --- a/watchapedia/app/movie/service.py +++ b/watchapedia/app/movie/service.py @@ -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, @@ -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 객체 반환. @@ -98,6 +98,7 @@ 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 @@ -105,12 +106,13 @@ def update_movie( 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 @@ -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, diff --git a/watchapedia/app/movie/views.py b/watchapedia/app/movie/views.py index 7795fc3..608566f 100644 --- a/watchapedia/app/movie/views.py +++ b/watchapedia/app/movie/views.py @@ -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 diff --git a/watchapedia/database/alembic/versions/2025_01_09_1532-1b8847f3edf8_movie_running_time_nullable.py b/watchapedia/database/alembic/versions/2025_01_09_1532-1b8847f3edf8_movie_running_time_nullable.py new file mode 100644 index 0000000..59b6602 --- /dev/null +++ b/watchapedia/database/alembic/versions/2025_01_09_1532-1b8847f3edf8_movie_running_time_nullable.py @@ -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 ###