diff --git a/server/index.py b/server/index.py index 0200aae..b571a61 100644 --- a/server/index.py +++ b/server/index.py @@ -99,10 +99,10 @@ async def _( if patch_type == PatchType.Subject: table = "view_subject_patch" - column = "id,created_at,updated_at,reason,from_user_id,wiki_user_id,state,original_name,subject_type" + column = "id,created_at,updated_at,reason,from_user_id,wiki_user_id,state,original_name,subject_type,comments_count" elif patch_type == PatchType.Episode: table = "view_episode_patch" - column = "id,created_at,updated_at,reason,from_user_id,wiki_user_id,state,original_name" + column = "id,created_at,updated_at,reason,from_user_id,wiki_user_id,state,original_name,comments_count" else: raise BadRequestException(f"{patch_type} is not valid") diff --git a/server/migration.py b/server/migration.py index fb62a9e..e244890 100644 --- a/server/migration.py +++ b/server/migration.py @@ -20,18 +20,20 @@ async def run_migration() -> None: key_migration_version = "version" - fresh_view_sql = sql_dir.joinpath("004-deleted-view.sql").read_text(encoding="utf-8") + refresh_view_sql = sql_dir.joinpath("004-deleted-view.sql").read_text(encoding="utf-8") migrations: list[Migrate] = [ Migrate(1, sql_dir.joinpath("001-init.sql").read_text(encoding="utf8")), - Migrate(4, fresh_view_sql), + Migrate(4, refresh_view_sql), Migrate(5, sql_dir.joinpath("005-edit-suggestion.sql").read_text(encoding="utf-8")), Migrate( 6, "alter table episode_patch add column subject_id int not null default 0;", ), - Migrate(7, fresh_view_sql), + Migrate(7, refresh_view_sql), Migrate(8, sql_dir.joinpath("008-create-index.sql").read_bytes().decode()), + Migrate(9, sql_dir.joinpath("009-show-suggestion-count.sql").read_bytes().decode()), + Migrate(10, refresh_view_sql), ] if not all(x <= y for x, y in itertools.pairwise(migrations)): diff --git a/server/review.py b/server/review.py index a21fd77..d8ec31f 100644 --- a/server/review.py +++ b/server/review.py @@ -354,4 +354,18 @@ async def add_comment( from_user_id, ) + await conn.execute( + f""" + update {patch_type}_patch + set comments_count = ( + select count(1) + from edit_suggestion + where patch_type = $1 and patch_id = $2 + ) + where id = $2 + """, + patch_type, + patch_id, + ) + return Redirect(f"/{patch_type}/{patch_id}") diff --git a/server/sql/009-show-suggestion-count.sql b/server/sql/009-show-suggestion-count.sql new file mode 100644 index 0000000..fc39d4e --- /dev/null +++ b/server/sql/009-show-suggestion-count.sql @@ -0,0 +1,2 @@ +alter table subject_patch add column comments_count int default 0 not null; +alter table episode_patch add column comments_count int default 0 not null; diff --git a/server/templates/list.html.jinja2 b/server/templates/list.html.jinja2 index 1eb85f3..3618863 100644 --- a/server/templates/list.html.jinja2 +++ b/server/templates/list.html.jinja2 @@ -93,25 +93,23 @@ >
- {% if patch.state == 0 %} -
+
+ {% if patch.state == 0 %} 待审核 -
- {% elif patch.state == 1 %} - -
+ {% elif patch.state == 1 %} + Accept -
- {% elif patch.state == 2 %} - -
+ {% elif patch.state == 2 %} + Rejected -
- {% elif patch.state == 3 %} -
+ {% elif patch.state == 3 %} Outdated -
- {% endif %} + {% endif %} + + {% if patch.comments_count %} + {{ patch.comments_count }} comments + {% endif %} +
{% if user_id is defined %}