Skip to content

Commit

Permalink
show comments
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Sep 3, 2024
1 parent bd7d669 commit 4bf44ea
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
4 changes: 2 additions & 2 deletions server/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 5 additions & 3 deletions server/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
14 changes: 14 additions & 0 deletions server/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
2 changes: 2 additions & 0 deletions server/sql/009-show-suggestion-count.sql
Original file line number Diff line number Diff line change
@@ -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;
28 changes: 13 additions & 15 deletions server/templates/list.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,23 @@
>
<div class="d-flex w-100 justify-content-between">
<div>
{% if patch.state == 0 %}
<h5 class="mb-1">
<h5 class="mb-1">
{% if patch.state == 0 %}
<span class="badge bg-primary">待审核</span>
</h5>
{% elif patch.state == 1 %}
<!-- accept -->
<h5 class="mb-1">
{% elif patch.state == 1 %}
<!-- accept -->
<span class="badge bg-success">Accept</span>
</h5>
{% elif patch.state == 2 %}
<!-- rejected -->
<h5 class="mb-1">
{% elif patch.state == 2 %}
<!-- rejected -->
<span class="badge bg-danger">Rejected</span>
</h5>
{% elif patch.state == 3 %}
<h5 class="mb-1">
{% elif patch.state == 3 %}
<span class="badge bg-secondary">Outdated</span>
</h5>
{% endif %}
{% endif %}

{% if patch.comments_count %}
<span class="badge bg-warning text-dark">{{ patch.comments_count }} comments</span>
{% endif %}
</h5>
</div>

{% if user_id is defined %}
Expand Down

0 comments on commit 4bf44ea

Please sign in to comment.