Skip to content

Commit

Permalink
feat: thread comment count (#322)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
LIEN-YUHSIANG and JasonNotJson authored Sep 17, 2023
1 parent 1f991fd commit a0f032e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
11 changes: 10 additions & 1 deletion lib/configs/api-gateway/schema.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/lambda/get-single-thread/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand Down
17 changes: 17 additions & 0 deletions src/lambda/patch-thread/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/lambda/post-thread/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a0f032e

Please sign in to comment.