From a0f032e36f80961ff9a5321e924170ce1049518e Mon Sep 17 00:00:00 2001 From: "Y.H LIEN" <85728908+LIEN-YUHSIANG@users.noreply.github.com> Date: Sun, 17 Sep 2023 20:08:48 +0800 Subject: [PATCH] feat: thread comment count (#322) * feat: added comment count to post thread * feat: update comment count * feat: schema update new action * chore: empty commit * chore: test * chore: update count change * feat: adding newComment flag * chore: small changes due to git merge conflict --------- Co-authored-by: Jason Park --- .husky/commit-msg | 0 .husky/pre-commit | 0 lib/configs/api-gateway/schema.ts | 11 ++++++++++- package.json | 2 +- pnpm-lock.yaml | 2 +- src/lambda/get-single-thread/index.py | 8 +++++--- src/lambda/patch-thread/index.py | 17 +++++++++++++++++ src/lambda/post-thread/index.py | 2 ++ 8 files changed, 36 insertions(+), 6 deletions(-) mode change 100644 => 100755 .husky/commit-msg mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/commit-msg b/.husky/commit-msg old mode 100644 new mode 100755 diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/lib/configs/api-gateway/schema.ts b/lib/configs/api-gateway/schema.ts index 051b861ca..84edbc416 100644 --- a/lib/configs/api-gateway/schema.ts +++ b/lib/configs/api-gateway/schema.ts @@ -1,5 +1,6 @@ import * as apigw from 'aws-cdk-lib/aws-apigateway'; +// test export const syllabusSchema: apigw.JsonSchema = { schema: apigw.JsonSchemaVersion.DRAFT7, type: apigw.JsonSchemaType.ARRAY, @@ -428,6 +429,12 @@ export const forumThreadGetRespSchema: apigw.JsonSchema = { totalLikes: { type: apigw.JsonSchemaType.INTEGER, }, + comment_count: { + type: apigw.JsonSchemaType.INTEGER, + }, + new_comment: { + type: apigw.JsonSchemaType.BOOLEAN, + }, }, required: [ 'univ_id', @@ -503,12 +510,14 @@ export const forumThreadPatchReqSchema: apigw.JsonSchema = { }, action: { type: apigw.JsonSchemaType.STRING, - enum: ['update', 'like', 'dislike'], + enum: ['update', 'like', 'dislike', 'update_count'], }, }, required: ['data', 'action'], }; +// turn off double quotation + export const forumCommentGetRespSchema: apigw.JsonSchema = { schema: apigw.JsonSchemaVersion.DRAFT7, type: apigw.JsonSchemaType.OBJECT, diff --git a/package.json b/package.json index 374c21785..e06df7131 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@types/pluralize": "0.0.29", "@typescript-eslint/eslint-plugin": "5.59.6", "@typescript-eslint/parser": "5.59.6", - "aws-cdk-lib": "2.74.0", + "aws-cdk-lib": "^2.74.0", "constructs": "10.1.312", "esbuild": "^0.17.0", "eslint": "8.38.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e8859f1c9..8a16a8a91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,7 +62,7 @@ devDependencies: specifier: 5.59.6 version: 5.59.6(eslint@8.38.0)(typescript@4.9.5) aws-cdk-lib: - specifier: 2.74.0 + specifier: ^2.74.0 version: 2.74.0(constructs@10.1.312) constructs: specifier: 10.1.312 diff --git a/src/lambda/get-single-thread/index.py b/src/lambda/get-single-thread/index.py index 5cba2b371..9df353e29 100644 --- a/src/lambda/get-single-thread/index.py +++ b/src/lambda/get-single-thread/index.py @@ -19,12 +19,14 @@ def get_single_thread(board_id, thread_id, uid=""): "board_id": board_id, "thread_id": thread_id, }, - UpdateExpression="SET #v = #v + :incr", + UpdateExpression="SET #v = #v + :incr, #nc = :newComment", ExpressionAttributeNames={ - '#v': 'views' + '#v': 'views', + '#nc': 'comment_count' }, ExpressionAttributeValues={ - ":incr": 1 + ":incr": 1, + ":newComment": False } ) diff --git a/src/lambda/patch-thread/index.py b/src/lambda/patch-thread/index.py index d718c98e5..4b6341bff 100644 --- a/src/lambda/patch-thread/index.py +++ b/src/lambda/patch-thread/index.py @@ -70,6 +70,23 @@ def patch_thread(board_id, uid, thread_id, thread, action): ':uid': {uid} }, ) + # Update comment_count by 1 + elif action == 'update_count': + table.update_item( + Key={ + "board_id": board_id, + "thread_id": thread_id, + }, + UpdateExpression="SET #c = #c + :incr, #nc = :newComment", + ExpressionAttributeNames={ + '#c': 'comment_count', + '#nc': 'new_comment' + }, + ExpressionAttributeValues={ + ":incr": 1, + ":newComment": True + } + ) body = JsonPayloadBuilder().add_status( True).add_data(None).add_message('').compile() diff --git a/src/lambda/post-thread/index.py b/src/lambda/post-thread/index.py index 9057136e2..8f1728167 100644 --- a/src/lambda/post-thread/index.py +++ b/src/lambda/post-thread/index.py @@ -26,6 +26,8 @@ def post_thread(board_id, thread, uid): "group_id": thread["group_id"], "univ_id": thread["univ_id"], "views": 0, + "comment_count": 0, + "new_comment": False } table.put_item(Item=thread_item)