mongoose + tests
This commit is contained in:
136
server/routers/old/coder/catalog/cardData.json
Normal file
136
server/routers/old/coder/catalog/cardData.json
Normal file
@@ -0,0 +1,136 @@
|
||||
{ "status": "success",
|
||||
|
||||
"dataFeatured": [{
|
||||
"title": "Featured",
|
||||
"items": [{
|
||||
"description":"Detailed Explanation of",
|
||||
"title": "Dynamic Programming",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "/coder/topics/dynamic-programming/",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard": "featured1",
|
||||
"slug": "dynamic-programming",
|
||||
"categorySlug": "featured"
|
||||
},{
|
||||
"description":"Detailed Explanation of",
|
||||
"title": "Heap",
|
||||
"chanptersCount": 4,
|
||||
"itemCount":28,
|
||||
"linkToPage": "/coder/topics/heap/",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard":"featured2",
|
||||
"slug": "heap"
|
||||
|
||||
},{
|
||||
"description":"Detailed Explanation of",
|
||||
"title": "Graph",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":58,
|
||||
"linkToPage": "/coder/topics/graph/",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard":"featured3",
|
||||
"slug": "graph"
|
||||
},{
|
||||
"description":"Introductuion to Data Structure",
|
||||
"title": "Arrays 101",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":31,
|
||||
"linkToPage": "/coder/card/fun-with-arrays/",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard":"featured4",
|
||||
"slug": "fun-with-arrays"
|
||||
}]
|
||||
},{
|
||||
"title": "Interview",
|
||||
"items": [{
|
||||
"description":"Get Well Prepared for",
|
||||
"title": "Google Interview",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "coder/interview/card/google/",
|
||||
"progressCard": 0,
|
||||
"primeContent": 1,
|
||||
"iconCard": "interview1",
|
||||
"slug": "google"
|
||||
},{
|
||||
"description":"Get Well Prepared for",
|
||||
"title": "Facebook",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "coder/interview/card/facebook/",
|
||||
"progressCard": 0,
|
||||
"primeContent": 1,
|
||||
"iconCard": "interview2",
|
||||
"slug": "facebook"
|
||||
},{
|
||||
"description":"Top Questions from",
|
||||
"title": "Microsoft",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "coder/interview/card/microsoft/",
|
||||
"progressCard": 0,
|
||||
"primeContent": 1,
|
||||
"iconCard": "interview3",
|
||||
"slug": "microsoft"
|
||||
},{
|
||||
"description":"Top Questions from",
|
||||
"title": "Amazon",
|
||||
"chanptersCount": 8,
|
||||
"itemCount":68,
|
||||
"linkToPage": "coder/interview/card/amazon/",
|
||||
"progressCard": 0,
|
||||
"primeContent": 1,
|
||||
"iconCard": "interview4",
|
||||
"slug": "amazon"
|
||||
}]
|
||||
},{
|
||||
"title": "Learn",
|
||||
"items": [{
|
||||
"description":"Detailed Explanation of",
|
||||
"title": "Graph",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":58,
|
||||
"linkToPage": "coder/learn/card/graph",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard": "learn1",
|
||||
"slug": "graph"
|
||||
},{
|
||||
"description":"Introductuion to Data Structure",
|
||||
"title": "Arrays 101",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "coder/learn/card/fun-with-arrays",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard": "learn2",
|
||||
"slug": "fun-with-arrays"
|
||||
},{
|
||||
"description":"Introductuion to Data Structure",
|
||||
"title": "Linked List",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "coder/learn/card/linked-list",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard": "learn3",
|
||||
"slug": "linked-list"
|
||||
},{
|
||||
"description":"Introductuion to Data Structure",
|
||||
"title": "Binary Tree",
|
||||
"chanptersCount": 6,
|
||||
"itemCount":55,
|
||||
"linkToPage": "coder/learn/card/data-structure-tree",
|
||||
"progressCard": 0,
|
||||
"primeContent": null,
|
||||
"iconCard": "learn4",
|
||||
"slug": "data-structure-tree"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
|
||||
3
server/routers/old/coder/catalog/error.json
Normal file
3
server/routers/old/coder/catalog/error.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"status": "error"
|
||||
}
|
||||
15
server/routers/old/coder/catalog/index.js
Normal file
15
server/routers/old/coder/catalog/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
// eslint-disable-next-line new-cap
|
||||
const router = require('express').Router();
|
||||
|
||||
router.get('/catalog', (request, response, next) => {
|
||||
setTimeout(() => next());
|
||||
}, (request, response) => {
|
||||
const params = process.env.stub;
|
||||
if (params === 'error') {
|
||||
response.send(require('./error.json'));
|
||||
} else {
|
||||
response.send(require('./cardData.json'));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
424
server/routers/old/coder/controllers.js
Normal file
424
server/routers/old/coder/controllers.js
Normal file
@@ -0,0 +1,424 @@
|
||||
const { getDB } = require('../../../utils/mongo')
|
||||
|
||||
let db = null
|
||||
|
||||
// Database Name
|
||||
const dbName = 'coder'
|
||||
|
||||
// Collections constant
|
||||
const TOPIC_TAGS_COLLECTION = 'topic-tags'
|
||||
const TOPIC_CATEGORIES_COLLECTION = 'topic-categories'
|
||||
const TOPIC_LIST_COLLECTION = 'topic-list'
|
||||
const TOPIC_COMMENTS_COLLECTION = 'topic-comments'
|
||||
const USERS_COLLECTION = 'users'
|
||||
|
||||
// page size
|
||||
const PAGE_SIZE = 2
|
||||
|
||||
// TODO убрать из export?
|
||||
const connect = async () => {
|
||||
db = await getDB(dbName)
|
||||
}
|
||||
|
||||
const getCategories = async () => {
|
||||
// TODO при первом запросе db = null
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
|
||||
const collection = db.collection(TOPIC_CATEGORIES_COLLECTION)
|
||||
|
||||
const categories = await collection.find({
|
||||
}).project({
|
||||
_id: 0,
|
||||
}).toArray()
|
||||
|
||||
if (categories.length === 0) {
|
||||
const newCategories = require('./forum/categories.json').body
|
||||
collection.insertMany(newCategories)
|
||||
return newCategories
|
||||
}
|
||||
return categories
|
||||
}
|
||||
|
||||
const getCategoryByPath = async (path) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
|
||||
const collection = db.collection(TOPIC_CATEGORIES_COLLECTION)
|
||||
|
||||
const category = await collection.findOne({
|
||||
path,
|
||||
}, {
|
||||
projection: {
|
||||
_id: 0,
|
||||
},
|
||||
})
|
||||
|
||||
if (!category) {
|
||||
throw new Error('No data')
|
||||
}
|
||||
return category
|
||||
}
|
||||
|
||||
const getTopicById = async (id) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
|
||||
const topicsCollection = db.collection(TOPIC_LIST_COLLECTION)
|
||||
|
||||
const topic = await topicsCollection
|
||||
.aggregate([
|
||||
{
|
||||
$match: {
|
||||
id: Number(id),
|
||||
},
|
||||
},
|
||||
{
|
||||
$limit: 1,
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: USERS_COLLECTION, localField: 'authorId', foreignField: 'id', as: 'author',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$author',
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: TOPIC_TAGS_COLLECTION, localField: 'tagsId', foreignField: 'id', as: 'tags',
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
id: 0,
|
||||
categoryId: 0,
|
||||
authorId: 0,
|
||||
tagsId: 0,
|
||||
'author.id': 0,
|
||||
'author._id': 0,
|
||||
'tags.id': 0,
|
||||
'tags._id': 0,
|
||||
_id: 0,
|
||||
},
|
||||
},
|
||||
])
|
||||
.toArray()
|
||||
|
||||
if (topic.length === 0) {
|
||||
throw new Error('No data')
|
||||
}
|
||||
|
||||
return topic[0]
|
||||
}
|
||||
|
||||
const getCommentsByTopicId = async (id, page) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
|
||||
if (page === undefined) {
|
||||
page = 1
|
||||
}
|
||||
|
||||
const commentsCollection = db.collection(TOPIC_COMMENTS_COLLECTION)
|
||||
|
||||
let count = await commentsCollection.count({
|
||||
}, {
|
||||
limit: 1,
|
||||
})
|
||||
if (count === 0) {
|
||||
const newComments = require('./forum/topic-comments.json').body
|
||||
commentsCollection.insertMany(newComments)
|
||||
}
|
||||
|
||||
const comments = await commentsCollection
|
||||
.aggregate([
|
||||
{
|
||||
$match: {
|
||||
topicId: Number(id),
|
||||
},
|
||||
},
|
||||
{
|
||||
$skip: PAGE_SIZE * Number(page) - PAGE_SIZE,
|
||||
},
|
||||
{
|
||||
$limit: PAGE_SIZE,
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: USERS_COLLECTION, localField: 'authorId', foreignField: 'id', as: 'author',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$author',
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
topicId: 0,
|
||||
authorId: 0,
|
||||
'author.id': 0,
|
||||
'author._id': 0,
|
||||
_id: 0,
|
||||
},
|
||||
},
|
||||
])
|
||||
.toArray()
|
||||
|
||||
// pagination
|
||||
count = await commentsCollection.count({
|
||||
topicId: Number(id),
|
||||
})
|
||||
const result = {
|
||||
page,
|
||||
pageSize: PAGE_SIZE,
|
||||
total: count,
|
||||
totalPages: Math.ceil(count / PAGE_SIZE),
|
||||
comments,
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const getTopicsByCategoryId = async (id, page) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
|
||||
if (page === undefined) {
|
||||
page = 1
|
||||
}
|
||||
|
||||
const topicsCollection = db.collection(TOPIC_LIST_COLLECTION)
|
||||
|
||||
let count = await topicsCollection.count({
|
||||
}, {
|
||||
limit: 1,
|
||||
})
|
||||
if (count === 0) {
|
||||
const newTopics = require('./forum/topic-list.json').body.items
|
||||
topicsCollection.insertMany(newTopics)
|
||||
}
|
||||
|
||||
// TODO delete after auth implementation
|
||||
const usersCollection = db.collection(USERS_COLLECTION)
|
||||
const usersCount = await usersCollection.count({
|
||||
}, {
|
||||
limit: 1,
|
||||
})
|
||||
if (usersCount === 0) {
|
||||
const newUsers = require('./forum/users.json').body
|
||||
usersCollection.insertMany(newUsers)
|
||||
}
|
||||
|
||||
const topics = await topicsCollection
|
||||
.aggregate([
|
||||
{
|
||||
$match: {
|
||||
categoryId: Number(id),
|
||||
},
|
||||
},
|
||||
{
|
||||
$skip: PAGE_SIZE * Number(page) - PAGE_SIZE,
|
||||
},
|
||||
{
|
||||
$limit: PAGE_SIZE,
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: USERS_COLLECTION, localField: 'authorId', foreignField: 'id', as: 'author',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$author',
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
id: 1,
|
||||
title: 1,
|
||||
commentCount: 1,
|
||||
viewCount: 1,
|
||||
voteCount: 1,
|
||||
creationDate: 1,
|
||||
'author.name': 1,
|
||||
'author.avatar': 1,
|
||||
_id: 0,
|
||||
},
|
||||
},
|
||||
])
|
||||
.toArray()
|
||||
|
||||
if (topics.length === 0) {
|
||||
throw new Error('No data')
|
||||
}
|
||||
|
||||
// pagination
|
||||
count = await topicsCollection.count({
|
||||
categoryId: Number(id),
|
||||
})
|
||||
const result = {
|
||||
page,
|
||||
pageSize: PAGE_SIZE,
|
||||
total: count,
|
||||
totalPages: Math.ceil(count / PAGE_SIZE),
|
||||
topics,
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const getTags = async () => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
|
||||
const tagsCollection = db.collection(TOPIC_TAGS_COLLECTION)
|
||||
|
||||
const count = await tagsCollection.count({
|
||||
}, {
|
||||
limit: 1,
|
||||
})
|
||||
if (count === 0) {
|
||||
const newTags = require('./forum/topic-tags.json').body
|
||||
tagsCollection.insertMany(newTags)
|
||||
}
|
||||
|
||||
const tags = await tagsCollection.find({
|
||||
}).project({
|
||||
_id: 0,
|
||||
}).toArray()
|
||||
|
||||
if (tags.length === 0) {
|
||||
throw new Error('No data')
|
||||
}
|
||||
|
||||
return tags
|
||||
}
|
||||
|
||||
const findTags = async (value) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
const tagsCollection = db.collection(TOPIC_TAGS_COLLECTION)
|
||||
|
||||
const tags = await tagsCollection
|
||||
.find({
|
||||
name: {
|
||||
$regex: `${value}`,
|
||||
},
|
||||
})
|
||||
.project({
|
||||
_id: 0,
|
||||
})
|
||||
.toArray()
|
||||
|
||||
return tags
|
||||
}
|
||||
|
||||
const insertTag = async (value) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
const tagsCollection = db.collection(TOPIC_TAGS_COLLECTION)
|
||||
// TODO no fast, reimplement
|
||||
const count = await tagsCollection.estimatedDocumentCount()
|
||||
|
||||
await tagsCollection.insertOne({
|
||||
id: count + 1,
|
||||
name: value,
|
||||
numTopics: 0,
|
||||
})
|
||||
|
||||
return count + 1
|
||||
}
|
||||
|
||||
const insertComment = async (comment) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
const commentsCollection = db.collection(TOPIC_COMMENTS_COLLECTION)
|
||||
// TODO no fast, reimplement
|
||||
// TODO может перейти на _id?
|
||||
const count = await commentsCollection.estimatedDocumentCount()
|
||||
|
||||
const currentTime = Math.round(new Date().getTime() / 1000)
|
||||
|
||||
await commentsCollection.insertOne({
|
||||
id: count + 1,
|
||||
topicId: comment.topicId,
|
||||
voteCount: 0,
|
||||
content: comment.content,
|
||||
updationDate: currentTime,
|
||||
creationDate: currentTime,
|
||||
authorId: comment.authorId,
|
||||
authorIsModerator: false,
|
||||
isOwnPost: false,
|
||||
})
|
||||
|
||||
return comment
|
||||
}
|
||||
|
||||
const insertTopic = async (topic) => {
|
||||
if (db === null) {
|
||||
throw new Error('no db connection')
|
||||
}
|
||||
const topicsCollection = db.collection(TOPIC_LIST_COLLECTION)
|
||||
// TODO no fast, reimplement
|
||||
// TODO может перейти на _id?
|
||||
const count = await topicsCollection.estimatedDocumentCount()
|
||||
|
||||
const currentTime = Math.round(new Date().getTime() / 1000)
|
||||
|
||||
const tagsId = []
|
||||
|
||||
if (topic.tags) {
|
||||
for (let index = 0; index < topic.tags.length; index++) {
|
||||
const tag = topic.tags[index]
|
||||
if (tag.id === 0) {
|
||||
const tagId = await insertTag(tag.name)
|
||||
tagsId.push(tagId)
|
||||
} else {
|
||||
tagsId.push(tag.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = await topicsCollection.insertOne({
|
||||
id: count + 1,
|
||||
categoryId: topic.categoryId,
|
||||
title: topic.title,
|
||||
commentCount: 0,
|
||||
viewCount: 0,
|
||||
tagsId,
|
||||
voteCount: 0,
|
||||
voteStatus: 0,
|
||||
content: topic.content,
|
||||
updationDate: currentTime,
|
||||
creationDate: currentTime,
|
||||
authorId: topic.authorId,
|
||||
isOwnPost: true,
|
||||
})
|
||||
|
||||
if (!result.insertedId) {
|
||||
throw new Error('Insert data failed, try again later')
|
||||
}
|
||||
|
||||
return count + 1
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
connect,
|
||||
getTags,
|
||||
findTags,
|
||||
insertTag,
|
||||
getCategories,
|
||||
getTopicsByCategoryId,
|
||||
getTopicById,
|
||||
getCommentsByTopicId,
|
||||
insertComment,
|
||||
insertTopic,
|
||||
getCategoryByPath,
|
||||
}
|
||||
49
server/routers/old/coder/forum/categories.json
Normal file
49
server/routers/old/coder/forum/categories.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"success": true,
|
||||
"body": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Interview Question",
|
||||
"description": "Share and discuss questions from real technical interviews",
|
||||
"path": "interview-question"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Interview Experience",
|
||||
"description": "Share details about the interview processes you have been through",
|
||||
"path": "interview-experience"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Compensation",
|
||||
"description": "What kind of offers have you received? Share it here!",
|
||||
"path": "compensation"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "Career",
|
||||
"description": "Question about working in the tech industry? Discuss your career questions here.",
|
||||
"path": "career"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"title": "Study Guide",
|
||||
"description": "Share your study guide or summaries for certain topics/patterns",
|
||||
"path": "study-guide"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"title": "General Discussion",
|
||||
"description": "Discuss anything not covered in other categories",
|
||||
"path": "general-discussion"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"title": "Support & Feedback",
|
||||
"description": "Get help on issues or submit feedback regarding LeetCode",
|
||||
"path": "feedback"
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
||||
3
server/routers/old/coder/forum/error.json
Normal file
3
server/routers/old/coder/forum/error.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"status": "error"
|
||||
}
|
||||
96
server/routers/old/coder/forum/index.js
Normal file
96
server/routers/old/coder/forum/index.js
Normal file
@@ -0,0 +1,96 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
const { getResponse } = require('../../../../utils/common');
|
||||
const {
|
||||
getTags,
|
||||
connect,
|
||||
findTags,
|
||||
insertTag,
|
||||
getCategories,
|
||||
getTopicsByCategoryId,
|
||||
getTopicById,
|
||||
getCommentsByTopicId,
|
||||
insertComment,
|
||||
getCategoryByPath,
|
||||
insertTopic,
|
||||
} = require('../controllers');
|
||||
|
||||
connect();
|
||||
|
||||
router.get('/forum/topic-categories', async (req, res) => {
|
||||
const errors = [];
|
||||
const categories = await getCategories().catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, categories));
|
||||
});
|
||||
|
||||
router.get('/forum/topic-categories/:groupId', async (req, res) => {
|
||||
const errors = [];
|
||||
const category = await getCategoryByPath(req.params.groupId).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, category));
|
||||
});
|
||||
|
||||
router.get('/forum/topic-comments/:topicId', async (req, res) => {
|
||||
const errors = [];
|
||||
const comments = await getCommentsByTopicId(req.params.topicId, req.query.page).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, comments));
|
||||
});
|
||||
|
||||
router.post('/forum/topic-comments', async (req, res) => {
|
||||
const errors = [];
|
||||
if (!req.body) {
|
||||
errors.push('Bad request, no body');
|
||||
res.send(getResponse(errors, undefined));
|
||||
} else {
|
||||
const comment = await insertComment(req.body).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, comment));
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/forum/topic-list/:id', async (req, res) => {
|
||||
const errors = [];
|
||||
const topics = await getTopicsByCategoryId(req.params.id, req.query.page).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, topics));
|
||||
});
|
||||
|
||||
router.get('/forum/topic/:id', async (req, res) => {
|
||||
const errors = [];
|
||||
const topic = await getTopicById(req.params.id).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, topic));
|
||||
});
|
||||
|
||||
router.post('/forum/topic', async (req, res) => {
|
||||
const errors = [];
|
||||
if (!req.body) {
|
||||
errors.push('Bad request, no body');
|
||||
res.send(getResponse(errors, undefined));
|
||||
} else {
|
||||
const topic = await insertTopic(req.body).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, topic));
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/forum/topic-tags', async (req, res) => {
|
||||
const errors = [];
|
||||
if (req.query.search !== undefined) {
|
||||
const tags = await findTags(req.query.search).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, tags));
|
||||
} else {
|
||||
const tags = await getTags().catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, tags));
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/forum/topic-tags', async (req, res) => {
|
||||
const errors = [];
|
||||
const tags = await insertTag(req.body?.name).catch((e) => errors.push(e.message));
|
||||
res.send(getResponse(errors, tags));
|
||||
});
|
||||
|
||||
router.get('/forum/stub/:data', (request, response) => {
|
||||
console.log(request.params);
|
||||
process.env.stub = request.params.data;
|
||||
|
||||
response.sendStatus(200);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
29
server/routers/old/coder/forum/topic-comments.json
Normal file
29
server/routers/old/coder/forum/topic-comments.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"success": true,
|
||||
"body": [
|
||||
{
|
||||
"id": 1,
|
||||
"topicId": 1,
|
||||
"voteCount": 36,
|
||||
"content": "wish for offer",
|
||||
"updationDate": 1563064458,
|
||||
"creationDate": 1563064458,
|
||||
"authorId": 1,
|
||||
"authorIsModerator": false,
|
||||
"isOwnPost": false
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"topicId": 1,
|
||||
"voteCount": 10,
|
||||
"content": "Thank you for your explantion",
|
||||
"updationDate": 1559050657,
|
||||
"creationDate": 1559050657,
|
||||
"authorId": 1,
|
||||
"authorIsModerator": false,
|
||||
"isOwnPost": false
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
||||
235
server/routers/old/coder/forum/topic-list.json
Normal file
235
server/routers/old/coder/forum/topic-list.json
Normal file
@@ -0,0 +1,235 @@
|
||||
{
|
||||
"success": true,
|
||||
"body": {
|
||||
"totalNum": 15,
|
||||
"items": [
|
||||
{
|
||||
"id": 1,
|
||||
"categoryId": 1,
|
||||
"title": "How to write an Interview Question post",
|
||||
"commentCount": 2,
|
||||
"viewCount": 0,
|
||||
"tagsId": [1, 2],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1524865315,
|
||||
"creationDate": 1524865315,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"categoryId": 1,
|
||||
"title": "Microsoft Online Assessment Questions",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [1, 2],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1570318826,
|
||||
"creationDate": 1570318826,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"categoryId": 2,
|
||||
"title": "Google Online Assessment Questions",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [1],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1565090199,
|
||||
"creationDate": 1565090199,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"categoryId": 2,
|
||||
"title": "Meta | March 2022 | Onsite USA E4",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [3, 4],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649546823,
|
||||
"creationDate": 1649546823,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"categoryId": 2,
|
||||
"title": "Flipkart | SDE 2 | Machine Coding",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [4, 5, 6],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649599102,
|
||||
"creationDate": 1649599102,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"categoryId": 3,
|
||||
"title": "Google | SDE (L4/L5) | Virtual Onsite | PENDING",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [7, 8],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649537604,
|
||||
"creationDate": 1649537604,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"categoryId": 3,
|
||||
"title": "Leetcode not taking track of submission and not filled the active days box",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [11, 12],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649486170,
|
||||
"creationDate": 1649486170,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"categoryId": 4,
|
||||
"title": "Salesforce India || AMTS (2022 Graduate) || Online Assessment || Off Campus",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [10, 20],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649572752,
|
||||
"creationDate": 1649572752,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"categoryId": 5,
|
||||
"title": "Meta | February Phone Interview | E4 | USA",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [14, 15],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649462307,
|
||||
"creationDate": 1649462307,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"categoryId": 5,
|
||||
"title": "Maximize minimum array",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [11, 7],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649652616,
|
||||
"creationDate": 1649652616,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"categoryId": 6,
|
||||
"title": "Yelp | London | April 2022 | Screening + Virtual On-Site | Full Stack Role",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [7, 12],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649637943,
|
||||
"creationDate": 1649637943,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"categoryId": 6,
|
||||
"title": "[System Design Question] Design a Game Matching system",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [8, 11],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649637516,
|
||||
"creationDate": 1649637516,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"categoryId": 6,
|
||||
"title": "Uber | Data Analyst | SF | 2022-04",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [1, 12],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649625709,
|
||||
"creationDate": 1649625709,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"categoryId": 7,
|
||||
"title": "Google Online Assessment",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [11, 2],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649622307,
|
||||
"creationDate": 1649622307,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"categoryId": 7,
|
||||
"title": "Amazon || SDE 2 || OA",
|
||||
"commentCount": 0,
|
||||
"viewCount": 0,
|
||||
"tagsId": [],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1649619969,
|
||||
"creationDate": 1649619969,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
||||
107
server/routers/old/coder/forum/topic-tags.json
Normal file
107
server/routers/old/coder/forum/topic-tags.json
Normal file
@@ -0,0 +1,107 @@
|
||||
{
|
||||
"success": true,
|
||||
"body": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "google",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "phone screen",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "amazon",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "facebook",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "online assessment",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"name": "onsite",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"name": "system design",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"name": "microsoft",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"name": "online assesment",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"name": "graph",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"name": "uber",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"name": "intern",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"name": "amazon online assesment",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"name": "bloomberg",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 15,
|
||||
"name": "amazon interview",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 16,
|
||||
"name": "new grad",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 17,
|
||||
"name": "interview",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"name": "amazon sde2",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 19,
|
||||
"name": "array",
|
||||
"numTopics": 0
|
||||
},
|
||||
{
|
||||
"id": 20,
|
||||
"name": "phone-interview",
|
||||
"numTopics": 0
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
||||
20
server/routers/old/coder/forum/topic.json
Normal file
20
server/routers/old/coder/forum/topic.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"success": true,
|
||||
"body": {
|
||||
"id": 1,
|
||||
"categoryId": 1,
|
||||
"title": "How to write an Interview Question post",
|
||||
"commentCount": 2,
|
||||
"viewCount": 0,
|
||||
"tagsId": [1, 2],
|
||||
"voteCount": 0,
|
||||
"voteStatus": 0,
|
||||
"content": "## Heading level 2\n#### Heading level 4\nI just love **bold text**.\nItalicized text is the _cat's meow_.\n- Revenue was off the chart.\n- Profits were higher than ever.\n",
|
||||
"updationDate": 1648229493,
|
||||
"creationDate": 1524865315,
|
||||
"authorId": 1,
|
||||
"isOwnPost": true
|
||||
},
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
||||
6
server/routers/old/coder/forum/users.json
Normal file
6
server/routers/old/coder/forum/users.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": true,
|
||||
"body": [{ "id": 1, "name": "Test", "avatar": "https://s3-us-west-1.amazonaws.com/s3-lc-upload/assets/default_avatar.jpg" }],
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
||||
8
server/routers/old/coder/index.js
Normal file
8
server/routers/old/coder/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// eslint-disable-next-line new-cap
|
||||
const router = require('express').Router()
|
||||
|
||||
router.use(require('./forum'))
|
||||
router.use(require('./catalog'))
|
||||
router.use(require('./topic'))
|
||||
|
||||
module.exports = router
|
||||
27
server/routers/old/coder/topic/dynamic-programming.json
Normal file
27
server/routers/old/coder/topic/dynamic-programming.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"status": "success",
|
||||
"title" : "Dynamic Programming",
|
||||
"slug":"dynamic-programming",
|
||||
"overview":"In this explore card, we're going to go over the basics of DP, provide you with a framework for solving DP problems, learn about common patterns, and walk through many examples.",
|
||||
"chapters": [
|
||||
{
|
||||
"title" : "Dynamic Programming",
|
||||
"section" : "dynamic-programming",
|
||||
"isLock" : false,
|
||||
"content" : "<p>Динамическое программирование</p>"
|
||||
},
|
||||
{
|
||||
"title" : "Arrays and Strings",
|
||||
"section" : "arrays-and-strings",
|
||||
"isLock" : false,
|
||||
"content" : "<p>Массивы и строки</p>"
|
||||
},
|
||||
{
|
||||
"title" : "Linked list",
|
||||
"section" : "linked-list",
|
||||
"isLock" : true,
|
||||
"content" : "<p>Ссылочный список</p>"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"title" : "Arrays and Strings",
|
||||
"slug" : "arrays-and-strings",
|
||||
"content": [
|
||||
{"data":"## Arrays and String"},
|
||||
{"data":"An array is a collection of similar type of elements that are stored in a contiguous memory location. Arrays can contain primitives(int, char, etc) as well as object(non-primitives) references of a class depending upon the definition of the array. In the case of primitive data type, the actual values are stored in contiguous memory locations whereas in the case of objects of a class the actual objects are stored in the heap segment. In Java, all the arrays are allocated dynamically. The size of an array must be specified by an int value and not long or short. The array index starts from 0 and goes up to n-1 where n is the length of the array."},
|
||||
{"data":"#### Array Declaration Syntax"},
|
||||
{"data": "An array declaration has two components: the type and the var-name. The type declares the element type of the array. The element type determines the data type of each element that comprises the array. The var-name declares the name of the array variable. Like an array of int type, we can also create an array of other primitive data types like char, float, double…etc."}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"title": "Dynamic programming",
|
||||
"slug": "dynamic-programming",
|
||||
"content": [
|
||||
{"data":"## Hello markdown"},
|
||||
{"data":"Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics. In both contexts it refers to simplifying a complicated problem by breaking it down into simpler sub-problems in a recursive manner. While some decision problems cannot be taken apart this way, decisions that span several points in time do often break apart recursively. Likewise, in computer science, if a problem can be solved optimally by breaking it into sub-problems and then recursively finding the optimal solutions to the sub-problems, then it is said to have optimal substructure.If sub-problems can be nested recursively inside larger problems, so that dynamic programming methods are applicable, then there is a relation between the value of the larger problem and the values of the sub-problems.[1] In the optimization literature this relationship is called the Bellman equation."},
|
||||
{"data":"#### Mathematical optimization"},
|
||||
{"data": "In terms of mathematical optimization, dynamic programming usually refers to simplifying a decision by breaking it down into a sequence of decision steps over time. This is done by defining a sequence of value functions V1, V2, ..., Vn taking y as an argument representing the state of the system at times i from 1 to n. The definition of Vn(y) is the value obtained in state y at the last time n. The values Vi at earlier times i = n −1, n − 2, ..., 2, 1 can be found by working backwards, using a recursive relationship called the Bellman equation. For i = 2, ..., n, Vi−1 at any state y is calculated from Vi by maximizing a simple function (usually the sum) of the gain from a decision at time i − 1 and the function Vi at the new state of the system if this decision is made. Since Vi has already been calculated for the needed states, the above operation yields Vi−1 for those states. Finally, V1 at the initial state of the system is the value of the optimal solution. The optimal values of the decision variables can be recovered, one by one, by tracking back the calculations already performed."}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"title" : "Linked list",
|
||||
"slug" : "linked-list",
|
||||
"content": [
|
||||
{"data":"# Hello markdown"},
|
||||
{"data":"# Hello markdown"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"title" : "Overview",
|
||||
"slug" : "overview",
|
||||
"content": [
|
||||
{"data":"## Overview"},
|
||||
{"data":"In this explore card, we're going to go over the basics of DP, provide you with a framework for solving DP problems, learn about common patterns, and walk through many examples.No prior knowledge of DP is required for this card, but you will need a solid understanding of recursion, a basic understanding of what greedy algorithms are, and general knowledge such as big O and hash tables. If you aren't familiar with recursion yet, check out the recursion explore card first."}
|
||||
]
|
||||
}
|
||||
3
server/routers/old/coder/topic/error.json
Normal file
3
server/routers/old/coder/topic/error.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"status": "error"
|
||||
}
|
||||
30
server/routers/old/coder/topic/index.js
Normal file
30
server/routers/old/coder/topic/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const router = require('express').Router()
|
||||
|
||||
router.get('/gettopic/:topic/:section', (request, response) => {
|
||||
const topic = request.params.topic
|
||||
let section = request.params.section
|
||||
|
||||
if (!topic || !section) {
|
||||
response.send(require('./error.json'))
|
||||
} else {
|
||||
response.send(
|
||||
// require(`./${topic}/${section}.json`)
|
||||
require(`./dynamic-programming/${section}.json`),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/gettopic/:topic', (request, response) => {
|
||||
const topic = request.params.topic
|
||||
|
||||
if (!topic) {
|
||||
response.send(require('./error.json'))
|
||||
} else {
|
||||
response.send(
|
||||
// require(`./${topic}.json`)
|
||||
require('./dynamic-programming.json'),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user