Skip to content

Commit

Permalink
Merge pull request #38 from CMU-313/endorsement-db
Browse files Browse the repository at this point in the history
Added endorsed attribute to the database
  • Loading branch information
ldlin1 authored Oct 8, 2024
2 parents 1369d72 + abcd3b9 commit b82e11f
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 4 deletions.
Binary file removed dump.rdb
Binary file not shown.
2 changes: 2 additions & 0 deletions public/openapi/components/schemas/PostObject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ PostObject:
type: number
deleted:
type: boolean
endorsed:
type: boolean
upvotes:
type: number
downvotes:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/read/topic/topic_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ get:
type: number
deleted:
type: number
endorsed:
type: number
upvotes:
type: number
downvotes:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/write/posts/pid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ get:
type: number
deleted:
type: number
endorsed:
type: number
upvotes:
type: number
downvotes:
Expand Down
2 changes: 2 additions & 0 deletions public/openapi/write/posts/pid/replies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ get:
type: number
deleted:
type: number
endorsed:
type: number
upvotes:
type: number
downvotes:
Expand Down
2 changes: 2 additions & 0 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function (Posts) {
const content = data.content.toString();
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;
const endorsed = data.endorsed || false;

if (!uid && parseInt(uid, 10) !== 0) {
throw new Error('[[error:invalid-uid]]');
Expand All @@ -35,6 +36,7 @@ module.exports = function (Posts) {
tid: tid,
content: content,
timestamp: timestamp,
endorsed: endorsed,
};

if (data.toPid) {
Expand Down
3 changes: 2 additions & 1 deletion src/posts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function (Posts) {
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];

const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle', 'endorsed'].concat(options.extraFields);

let posts = await Posts.getPostsFields(pids, fields);
posts = posts.filter(Boolean);
Expand Down Expand Up @@ -51,6 +51,7 @@ module.exports = function (Posts) {
post.category = post.topic && cidToCategory[post.topic.cid];
post.isMainPost = post.topic && post.pid === post.topic.mainPid;
post.deleted = post.deleted === 1;
post.endorsed = post.endorsed === 1;
post.timestampISO = utils.toISOString(post.timestamp);
});

Expand Down
2 changes: 1 addition & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function filterAndSort(pids, data) {
}

async function getMatchedPosts(pids, data) {
const postFields = ['pid', 'uid', 'tid', 'timestamp', 'deleted', 'upvotes', 'downvotes'];
const postFields = ['pid', 'uid', 'tid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'endorsed'];

let postsData = await posts.getPostsFields(pids, postFields);
postsData = postsData.filter(post => post && !post.deleted);
Expand Down
2 changes: 0 additions & 2 deletions src/topics/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ module.exports = function (Topics) {
// The following code was created with the assistance of ChatGPT.

async function addEventStartEnd(postData, set, reverse, topicData) {
console.log('Lucas Lin');

if (!postData.length) {
return;
}
Expand Down

0 comments on commit b82e11f

Please sign in to comment.