本日作業分
このコミットが含まれているのは:
+18
-21
@@ -26,10 +26,10 @@ def main (
|
||||
|
||||
|
||||
def update_video_table (
|
||||
video_dao,
|
||||
video_dao: VideoDao,
|
||||
api_data: list[dict],
|
||||
) -> None:
|
||||
# TODO: 書くこと
|
||||
# TODO: videos 取得書くこと
|
||||
|
||||
video_dao.upsert_all (videos)
|
||||
|
||||
@@ -176,7 +176,7 @@ class VideoDao:
|
||||
self,
|
||||
videos: list[VideoDto],
|
||||
with_relation_tables: bool = True,
|
||||
) -> int:
|
||||
) -> None:
|
||||
with self.conn.cursor () as c:
|
||||
for video in videos:
|
||||
c.execute ("""
|
||||
@@ -199,14 +199,16 @@ class VideoDao:
|
||||
title = VALUES(title),
|
||||
description = VALUES(description),
|
||||
uploaded_at = VALUES(uploaded_at),
|
||||
deleted_at = VALUES(deleted_at)""", (
|
||||
video.code,
|
||||
deleted_at = VALUES(deleted_at)""", (video.code,
|
||||
video.title,
|
||||
video.description,
|
||||
video.uploaded_at,
|
||||
video.deleted_at))
|
||||
video.id_ = c.lastrowid
|
||||
# TODO: with_relation_tables が True の場合,子テーブルも UPSERT すること
|
||||
if with_relation_tables:
|
||||
VideoTagDao (self.conn).upsert_all (video.video_tags, False)
|
||||
CommentDao (self.conn).upsert_all (video.comments, False)
|
||||
VideoHistoryDao (self.conn).upsert_all (video.video_histories, False)
|
||||
|
||||
def _create_dto_from_row (
|
||||
self,
|
||||
@@ -218,10 +220,7 @@ class VideoDao:
|
||||
title = row['title'],
|
||||
description = row['description'],
|
||||
uploaded_at = row['uploaded_at'],
|
||||
deleted_at = row['deleted_at'],
|
||||
video_tags = None,
|
||||
comments = None,
|
||||
video_histories = None)
|
||||
deleted_at = row['deleted_at'])
|
||||
if with_relation_tables:
|
||||
video.video_tags = VideoTagDao (self.conn).fetch_by_video_id (video.id_, False)
|
||||
for i in range (len (video.video_tags)):
|
||||
@@ -237,15 +236,15 @@ class VideoDao:
|
||||
|
||||
@dataclass (slots = True)
|
||||
class VideoDto:
|
||||
id_: int
|
||||
id_: int | None = None
|
||||
code: str
|
||||
title: str
|
||||
description: str
|
||||
uploaded_at: datetime
|
||||
deleted_at: datetime | None
|
||||
video_tags: list[VideoTagDto] | None
|
||||
comments: list[CommentDto] | None
|
||||
video_histories: list[VideoHistoryDto] | None
|
||||
deleted_at: datetime | None = None
|
||||
video_tags: list[VideoTagDto] | None = None
|
||||
comments: list[CommentDto] | None = None
|
||||
video_histories: list[VideoHistoryDto] | None = None
|
||||
|
||||
|
||||
class VideoTagDao:
|
||||
@@ -288,9 +287,7 @@ class VideoTagDao:
|
||||
video_id = row['video_id'],
|
||||
tag_id = row['tag_id'],
|
||||
tagged_at = row['tagged_at'],
|
||||
untagged_at = row['untagged_at'],
|
||||
video = None,
|
||||
tag = None)
|
||||
untagged_at = row['untagged_at'])
|
||||
if with_relation_tables:
|
||||
video_tag.video = VideoDao (self.conn).fetch (video_tag.video_id, True)
|
||||
video_tag.tag = TagDao (self.conn).fetch (video_tag.tag_id, True)
|
||||
@@ -299,13 +296,13 @@ class VideoTagDao:
|
||||
|
||||
@dataclass (slots = True)
|
||||
class VideoTagDto:
|
||||
id_: int
|
||||
id_: int | None = None
|
||||
video_id: int
|
||||
tag_id: int
|
||||
tagged_at: datetime
|
||||
untagged_at: datetime
|
||||
video: VideoDto
|
||||
tag: TagDto
|
||||
video: VideoDto | None = None
|
||||
tag: TagDto | None = None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
新しい課題から参照
ユーザをブロックする