diff --git a/lib/configs/api-gateway/schema.ts b/lib/configs/api-gateway/schema.ts index 051b861ca..a6a19368d 100644 --- a/lib/configs/api-gateway/schema.ts +++ b/lib/configs/api-gateway/schema.ts @@ -1,208 +1,208 @@ -import * as apigw from 'aws-cdk-lib/aws-apigateway'; +import * as apigw from "aws-cdk-lib/aws-apigateway"; export const syllabusSchema: apigw.JsonSchema = { schema: apigw.JsonSchemaVersion.DRAFT7, type: apigw.JsonSchemaType.ARRAY, - title: 'Syllabus', - description: 'The new syllabus JSON schema for each school.', + title: "Syllabus", + description: "The new syllabus JSON schema for each school.", items: { type: apigw.JsonSchemaType.OBJECT, - title: 'Items', - description: 'The schema of each course in the array.', + title: "Items", + description: "The schema of each course in the array.", required: [ - 'a', - 'b', - 'c', - 'd', - 'e', - 'f', - 'g', - 'h', - 'i', - 'j', - 'k', - 'l', - 'm', - 'n', - 'o', - 'p', - 'q', + "a", + "b", + "c", + "d", + "e", + "f", + "g", + "h", + "i", + "j", + "k", + "l", + "m", + "n", + "o", + "p", + "q", ], properties: { a: { type: apigw.JsonSchemaType.STRING, - title: 'Course Key', - description: 'Course key of the course.', + title: "Course Key", + description: "Course key of the course.", }, b: { type: apigw.JsonSchemaType.STRING, - title: 'Title', - description: 'Course title in English.', + title: "Title", + description: "Course title in English.", }, c: { type: apigw.JsonSchemaType.STRING, - title: 'Title JP', - description: 'Course title in Japanese.', + title: "Title JP", + description: "Course title in Japanese.", }, d: { type: apigw.JsonSchemaType.STRING, - title: 'Instructor', + title: "Instructor", description: "Instructor's name in English.", }, e: { type: apigw.JsonSchemaType.STRING, - title: 'Instructor JP', + title: "Instructor JP", description: "Instructor's name in Japanese.", }, f: { type: apigw.JsonSchemaType.ARRAY, - title: 'Langauges', - description: 'Languages in which the course is taught.', + title: "Langauges", + description: "Languages in which the course is taught.", items: { type: apigw.JsonSchemaType.INTEGER, - title: 'Language', + title: "Language", description: - '-1 N/A | 0 Japanese | 1 English | 2 German | 3 French | 4 Chinese | 5 Spanish | 6 Korean | 7 Russia | 8 Italian | 9 other', + "-1 N/A | 0 Japanese | 1 English | 2 German | 3 French | 4 Chinese | 5 Spanish | 6 Korean | 7 Russia | 8 Italian | 9 other", enum: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], }, }, g: { type: apigw.JsonSchemaType.INTEGER, - title: 'Type', + title: "Type", description: - 'Type of the course\n-1 N/A | 0 Lecture | 1 Seminar | 2 Work | 3 Foreign Langauge | 4 On-demand | 5 Thesis | 6 Graduate Research | 7 Practice | 8 Blended', + "Type of the course\n-1 N/A | 0 Lecture | 1 Seminar | 2 Work | 3 Foreign Langauge | 4 On-demand | 5 Thesis | 6 Graduate Research | 7 Practice | 8 Blended", enum: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8], }, h: { type: apigw.JsonSchemaType.STRING, - title: 'Term', + title: "Term", description: "The term in which the course is taught.\nseason := 0 Spring | 1 Summer | 2 Fall | 3 Winter\nperiod := 's' Semester| 'q' Quarter | 'i' Intensive Course | 'f' Full Year | 't' Term\ndelimiter := '/' or | '&' and", enum: [ - '0s', - '2s', - '0q', - '1q', - '2q', - '3q', - 'f', - '0', - '1', - '2', - '3', - '0i', - '2i', - '0t', - '2t', - '3t', - '0t/1t', - '0s/2s', - '2t/3t', - '1&2s', - '0s&1', - 'f/2s', - '0i&3i', + "0s", + "2s", + "0q", + "1q", + "2q", + "3q", + "f", + "0", + "1", + "2", + "3", + "0i", + "2i", + "0t", + "2t", + "3t", + "0t/1t", + "0s/2s", + "2t/3t", + "1&2s", + "0s&1", + "f/2s", + "0i&3i", ], }, i: { type: apigw.JsonSchemaType.ARRAY, - title: 'Occurrences', - description: 'The schedules and locations of the course.', + title: "Occurrences", + description: "The schedules and locations of the course.", items: { type: apigw.JsonSchemaType.OBJECT, - title: 'Occurrence', - description: 'Schedule and location', - required: ['d', 'p', 'l'], + title: "Occurrence", + description: "Schedule and location", + required: ["d", "p", "l"], properties: { d: { type: apigw.JsonSchemaType.INTEGER, - title: 'Day', + title: "Day", description: - 'The day on which the course is taught.\n-1 others | 0 Mon | 1 Tues | 2 Wed | 3 Thur | 4 Fri | 5 Sat | 6 Sun', + "The day on which the course is taught.\n-1 others | 0 Mon | 1 Tues | 2 Wed | 3 Thur | 4 Fri | 5 Sat | 6 Sun", enum: [-1, 0, 1, 2, 3, 4, 5, 6], }, p: { type: apigw.JsonSchemaType.INTEGER, - title: 'Period', + title: "Period", description: - 'The period on which the course is taught.\nstart_period := -1 others | 0 On-demand | 1 .. 9\nend_period := start_period ', + "The period on which the course is taught.\nstart_period := -1 others | 0 On-demand | 1 .. 9\nend_period := start_period ", }, l: { type: apigw.JsonSchemaType.STRING, - title: 'Loction', - description: 'The location where the course takes place.', + title: "Loction", + description: "The location where the course takes place.", }, }, }, }, j: { type: apigw.JsonSchemaType.INTEGER, - title: 'Minimum Eligible Year', - description: 'Minimum eligible year.\n-1 unknown | 1 .. 4', + title: "Minimum Eligible Year", + description: "Minimum eligible year.\n-1 unknown | 1 .. 4", enum: [-1, 1, 2, 3, 4], }, k: { type: apigw.JsonSchemaType.STRING, - title: 'Category', - description: 'The category the course falls in.', + title: "Category", + description: "The category the course falls in.", }, l: { type: apigw.JsonSchemaType.INTEGER, - title: 'Credit', - description: 'The credit of the course.\n -1 unknown | 0 ..', + title: "Credit", + description: "The credit of the course.\n -1 unknown | 0 ..", }, m: { type: apigw.JsonSchemaType.INTEGER, - title: 'Level', + title: "Level", description: - 'The level/difficulty of the course.\n-1 N/A | 0 Beginner | 1 Intermediate | 2 Advanced | 3 Final-stage | 4 Master | 5 Doctor', + "The level/difficulty of the course.\n-1 N/A | 0 Beginner | 1 Intermediate | 2 Advanced | 3 Final-stage | 4 Master | 5 Doctor", enum: [-1, 0, 1, 2, 3, 4, 5], }, n: { type: apigw.JsonSchemaType.ARRAY, - title: 'Evaluations', + title: "Evaluations", description: - 'The distribution of evaluation criterion and their descriptions', + "The distribution of evaluation criterion and their descriptions", items: { type: apigw.JsonSchemaType.OBJECT, - title: 'Evaluation', - description: 'Criteria and description', - required: ['t', 'p', 'c'], + title: "Evaluation", + description: "Criteria and description", + required: ["t", "p", "c"], properties: { t: { type: apigw.JsonSchemaType.INTEGER, - title: 'Type', + title: "Type", description: - 'Type of the evaluation\n-1 Unknown | 0 Exam | 1 Papers | 2 Class Participation | 3 Others', + "Type of the evaluation\n-1 Unknown | 0 Exam | 1 Papers | 2 Class Participation | 3 Others", enum: [-1, 0, 1, 2, 3], }, p: { type: apigw.JsonSchemaType.INTEGER, - title: 'Percentage', - description: 'The percentage of this criteria in evaluation.', + title: "Percentage", + description: "The percentage of this criteria in evaluation.", }, c: { type: apigw.JsonSchemaType.STRING, - title: 'Comment', - description: 'An explanation about the criteria.', + title: "Comment", + description: "An explanation about the criteria.", }, }, }, }, o: { type: apigw.JsonSchemaType.STRING, - title: 'Code', - description: 'Course code', + title: "Code", + description: "Course code", }, p: { type: apigw.JsonSchemaType.STRING, - title: 'Subtitle', - description: 'Subtitle of the course (often seen in seminar courses)', + title: "Subtitle", + description: "Subtitle of the course (often seen in seminar courses)", }, q: { type: apigw.JsonSchemaType.STRING, - title: 'CategoryJP', - description: 'The category the course falls in.(in Japanese)', + title: "CategoryJP", + description: "The category the course falls in.(in Japanese)", }, }, }, @@ -273,23 +273,23 @@ export const courseReviewGetRespSchema: apigw.JsonSchema = { }, }, required: [ - 'title_jp', - 'instructor_jp', - 'updated_at', - 'created_at', - 'benefit', - 'difficulty', - 'satisfaction', - 'instructor', - 'comment_zh-CN', - 'comment_zh-TW', - 'comment_ko', - 'comment_en', - 'year', - 'src_lang', - 'comment_ja', - 'title', - 'mod', + "title_jp", + "instructor_jp", + "updated_at", + "created_at", + "benefit", + "difficulty", + "satisfaction", + "instructor", + "comment_zh-CN", + "comment_zh-TW", + "comment_ko", + "comment_en", + "year", + "src_lang", + "comment_ja", + "title", + "mod", ], }, }, @@ -297,7 +297,7 @@ export const courseReviewGetRespSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['success', 'data', 'message'], + required: ["success", "data", "message"], }; export const courseReviewPostReqSchema: apigw.JsonSchema = { @@ -336,19 +336,19 @@ export const courseReviewPostReqSchema: apigw.JsonSchema = { }, }, required: [ - 'title_jp', - 'instructor_jp', - 'benefit', - 'difficulty', - 'satisfaction', - 'instructor', - 'comment', - 'year', - 'title', + "title_jp", + "instructor_jp", + "benefit", + "difficulty", + "satisfaction", + "instructor", + "comment", + "year", + "title", ], }, }, - required: ['data'], + required: ["data"], }; export const courseReviewPatchReqSchema: apigw.JsonSchema = { @@ -371,10 +371,10 @@ export const courseReviewPatchReqSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['benefit', 'difficulty', 'satisfaction', 'comment'], + required: ["benefit", "difficulty", "satisfaction", "comment"], }, }, - required: ['data'], + required: ["data"], }; export const forumThreadGetRespSchema: apigw.JsonSchema = { @@ -428,21 +428,27 @@ 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', - 'board_id', - 'updated_at', - 'created_at', - 'tag_id', - 'group_id', - 'thread_id', - 'title', - 'body', - 'views', - 'mod', - 'userLiked', - 'totalLikes', + "univ_id", + "board_id", + "updated_at", + "created_at", + "tag_id", + "group_id", + "thread_id", + "title", + "body", + "views", + "mod", + "userLiked", + "totalLikes", ], }, }, @@ -450,7 +456,7 @@ export const forumThreadGetRespSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['success', 'data', 'message'], + required: ["success", "data", "message"], }; export const forumThreadPostReqSchema: apigw.JsonSchema = { @@ -473,10 +479,10 @@ export const forumThreadPostReqSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['tag_id', 'group_id', 'title', 'body'], + required: ["tag_id", "group_id", "title", "body"], }, }, - required: ['data'], + required: ["data"], }; export const forumThreadPatchReqSchema: apigw.JsonSchema = { @@ -499,14 +505,14 @@ export const forumThreadPatchReqSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['tag_id', 'group_id', 'title', 'body'], + required: ["tag_id", "group_id", "title", "body"], }, action: { type: apigw.JsonSchemaType.STRING, - enum: ['update', 'like', 'dislike'], + enum: ["update", "like", "dislike"], }, }, - required: ['data', 'action'], + required: ["data", "action"], }; export const forumCommentGetRespSchema: apigw.JsonSchema = { @@ -532,13 +538,13 @@ export const forumCommentGetRespSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.BOOLEAN, }, }, - required: ['thread_id', 'body', 'create_at', 'update_at', 'mod'], + required: ["thread_id", "body", "create_at", "update_at", "mod"], }, message: { type: apigw.JsonSchemaType.STRING, }, }, - required: ['success', 'data', 'message'], + required: ["success", "data", "message"], }; export const forumCommentPostReqSchema: apigw.JsonSchema = { @@ -552,10 +558,10 @@ export const forumCommentPostReqSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['body'], + required: ["body"], }, }, - required: ['data'], + required: ["data"], }; export const forumCommentPatchReqSchema: apigw.JsonSchema = { @@ -569,10 +575,10 @@ export const forumCommentPatchReqSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['body'], + required: ["body"], }, }, - required: ['data'], + required: ["data"], }; export const baseJsonApiSchema: apigw.JsonSchema = { @@ -589,7 +595,7 @@ export const baseJsonApiSchema: apigw.JsonSchema = { type: apigw.JsonSchemaType.STRING, }, }, - required: ['success', 'data', 'message'], + required: ["success", "data", "message"], }; export const careerInfoSchema: apigw.JsonSchema = {}; diff --git a/src/lambda/patch-thread/index.py b/src/lambda/patch-thread/index.py index d718c98e5..250da21d9 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", + ExpressionAttributeNames={ + '#c': 'comment_count' + }, + ExpressionAttributeValues={ + ":incr": 1 + } + ) + + body = JsonPayloadBuilder().add_status( True).add_data(None).add_message('').compile()