Skip to content

Commit

Permalink
added display questions by category
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-mitra committed Oct 6, 2020
1 parent 9676179 commit f9aeef0
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 302 deletions.
7 changes: 1 addition & 6 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ var express = require("express");
var app = express();
var cors = require("cors");
var bodyParser = require("body-parser");
var morgan = require('morgan');

app.use(morgan('combined'));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Expand All @@ -15,9 +13,8 @@ var CodeRoutes = require("./routes/CodeRoutes");
var LeaderboardRoutes = require("./routes/Leaderboard");
var AdminRoutes = require("./routes/AdminRoutes");
var CommentRoute = require("./routes/Comment");
var CategoryRoute = require("./routes/category");
var CategoryRoute = require("./routes/Category");

var findQues = require("./routes/findQuestion");

app.get("/", (req, res) => {
res.send("Goto to the following route -> '/api/question' ");
Expand All @@ -27,8 +24,6 @@ app.use("/api/comments", CommentRoute);
app.use("/api/questions", QuestionRoute);
app.use("/api/category", CategoryRoute);

//find Quesrions
app.use("/category", findQues);

app.use("/api/code", CodeRoutes);
app.use("/api/leaderboard", LeaderboardRoutes);
Expand Down
2 changes: 1 addition & 1 deletion backend/models/Category.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var mongoose = require("mongoose");

var CategorySchema = new mongoose.Schema({
category: String,
name: String,
});

var Category = mongoose.model("Category", CategorySchema);
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-rush-backend",
"version": "2.1.2",
"version": "2.3.5",
"description": "backend for codeplatform2",
"main": "app.js",
"scripts": {
Expand Down
25 changes: 25 additions & 0 deletions backend/routes/Category/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var express = require("express");
var router = express.Router();
var db = require("../../models");


router.get('/:cname', function (req, res, next) {
var filteredQuestions = [];
db.Question.find()
.populate('category')
.lean()
.then(questions => {
questions.forEach(question => {
question.category.forEach(c => {
if (c.name === req.params.cname.toString())
filteredQuestions.push(question);
})
})
})
.then(() => {
res.json({ questions: filteredQuestions });
})
.catch(e => next(e));
})

module.exports = router;
34 changes: 34 additions & 0 deletions backend/routes/Category/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var express = require("express");
var router = express.Router();
var db = require("../../models");
var getQuestionsByCategory = require('./get');

router.use('/get', getQuestionsByCategory);

router.get("/", function (req, res, next) {
db.Category.find()
.lean()
.then((category) => res.json(category))
.catch((err) => next(err));
});

//POST ROUTE
router.post("/:questionId/category", function (req, res, next) {
db.Question.findById(req.params.questionId, function (err, questions) {
if (err) {
next(err);
} else {
db.Category.create(req.body, function (err1, newCategory) {
if (err1) {
next(err1);
} else {
res.json(newCategory);
questions.category.push(newCategory._id);
questions.save();
}
});
}
});
});

module.exports = router;
30 changes: 0 additions & 30 deletions backend/routes/category.js

This file was deleted.

39 changes: 0 additions & 39 deletions backend/routes/findQuestion.js

This file was deleted.

35 changes: 18 additions & 17 deletions frontend/components/Dashboard/card.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import PageLink from 'next/link';
import { CardMedia, Card, CardActions, CardContent, Typography, Button } from "@material-ui/core";

const CCard = props => {
const { title, subtitle, description, imageUrl } = props;
return (
<Card style={{marginTop:"50px" , marginBottom:"30px"}}>
const { link, description, imageUrl } = props;
return (
<Card style={{ marginTop: "50px", marginBottom: "30px" }}>

<CardMedia style={{ height: "150px" ,marginTop:"50px"}} image={imageUrl} />
<CardContent>
<Typography variant="body2" component="p">
{description}
</Typography>
</CardContent>
<CardActions>
<Button size="small" color="primary">
Start
</Button>
</CardActions>
</Card>
);
<CardMedia style={{ height: "150px", marginTop: "50px" }} image={imageUrl} />
<CardContent>
<Typography variant="body2" component="p">
{description}
</Typography>
</CardContent>
<CardActions>
<Button size="small" color="primary">
<PageLink href={link}> Start</PageLink>
</Button>
</CardActions>
</Card>
);
};

export default CCard;
export default CCard;
25 changes: 14 additions & 11 deletions frontend/components/Dashboard/constants.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
export default [
{


description:
"Start Programming with C",
imageUrl:
"http://www.faadooengineers.com/online-study/assets/images/icon/BasicofCProgramming.png"
"http://www.faadooengineers.com/online-study/assets/images/icon/BasicofCProgramming.png",
link: "/questions?cname=c",
},
{
description:
"Start Programming with Java",

imageUrl:
"https://th.bing.com/th/id/OIP.KacZ5bUqrOnHMwyYXYUl4gHaEL?pid=Api&rs=1"
"https://th.bing.com/th/id/OIP.KacZ5bUqrOnHMwyYXYUl4gHaEL?pid=Api&rs=1",
link: "/questions?cname=java",

},
{


description:
"Start Programming with C++",
imageUrl:
"https://ih1.redbubble.net/image.416406976.0438/flat,550x550,075,f.jpg"
"https://ih1.redbubble.net/image.416406976.0438/flat,550x550,075,f.jpg",
link: "/questions?cname=cpp",
},
{
description:
"Start Programming With C++",
"Start Programming With Python",
imageUrl:
"http://genderapi.io/assets/img/3rd-party-logos/python.png"
"http://genderapi.io/assets/img/3rd-party-logos/python.png",
link: "/questions?cname=python",
},
{

description:
"Start Programming with Ruby",
imageUrl:
"https://keyua.org/media/blog_images/ruby-logo_optimized.png"
"https://keyua.org/media/blog_images/ruby-logo_optimized.png",
link: "/questions?cname=ruby"
},
{

description:
'Start Programming with JavaScript.',
imageUrl:
"http://test.codersera.com/blog/wp-content/uploads/2020/06/JavaScript1-1024x576.jpeg"
"http://test.codersera.com/blog/wp-content/uploads/2020/06/JavaScript1-1024x576.jpeg",
link: "/questions?cname=java",
}
];
Loading

0 comments on commit f9aeef0

Please sign in to comment.