Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merging updates #4

Merged
merged 35 commits into from
Mar 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ea73792
feat: screenshots of problems pages
aprooks Mar 10, 2014
c238d35
Set base_api to /api/v1/content-delivery
dinoboff Mar 13, 2014
148d453
Update grunt connect task with new api root url
dinoboff Mar 13, 2014
0ca5c93
fix app.config dependencies
dinoboff Mar 13, 2014
917bdd4
Fix missing dependencies in app.sidebar
dinoboff Mar 13, 2014
882a34f
Merge pull request #26 from dinoboff/api-base
dinoboff Mar 14, 2014
05f7aa2
Adds assets
dinoboff Mar 14, 2014
9cfa1e5
Merge pull request #27 from dinoboff/api-base
dinoboff Mar 14, 2014
9717030
Fix templates path
dinoboff Mar 14, 2014
7eb86b6
Merge pull request #28 from dinoboff/api-base
dinoboff Mar 14, 2014
ccfb71f
Fixes link to video create form
dinoboff Mar 14, 2014
1caeb75
Merge pull request #29 from dinoboff/api-base
dinoboff Mar 14, 2014
ec83fdf
Change postAnswer path to include the problem id
dinoboff Mar 15, 2014
e7339a6
Merge pull request #30 from dinoboff/api-base
dinoboff Mar 17, 2014
b450fb7
Update AnswerPayload schema
dinoboff Mar 17, 2014
597ab24
Parse answer to integer
dinoboff Mar 17, 2014
f498c6b
Merge pull request #31 from dinoboff/fix-post-answer
dinoboff Mar 17, 2014
724c1d5
Fix answer call
dinoboff Mar 17, 2014
01e689d
Fix it again
dinoboff Mar 17, 2014
587e344
Update the test
dinoboff Mar 18, 2014
2ac9ba1
Merge pull request #32 from dinoboff/fix-post-answer
dinoboff Mar 18, 2014
7ac5b54
Merge pull request #25 from aprooks/master
dinoboff Mar 18, 2014
2aeb238
Merge pull request #23 from aprooks/feature/createProblem
dinoboff Mar 18, 2014
bbf3d0d
Implement new problem form
dinoboff Mar 18, 2014
03f937d
Update assets/app.js
dinoboff Mar 18, 2014
dc84025
Remove questionRef off the problem creation response
dinoboff Mar 18, 2014
f69f421
Add form to add new question
dinoboff Mar 19, 2014
cb58e60
Added form to attach a video to a problem
dinoboff Mar 20, 2014
82c93f7
Merge pull request #33 from dinoboff/new-problem
dinoboff Mar 20, 2014
bd261b0
Fix new problem form
dinoboff Mar 20, 2014
2abb848
Merge pull request #34 from dinoboff/new-problem
dinoboff Mar 20, 2014
102e63f
Adds the a service to alert users with messages.
dinoboff Mar 21, 2014
e8de79a
Fix alerts.
dinoboff Mar 21, 2014
93ac38a
Convert windows.alert to alerts.warning
dinoboff Mar 21, 2014
ef73d5a
Merge pull request #35 from dinoboff/alert
dinoboff Mar 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ node_modules
bower_components
/selenium
/coverage
/app/assets
/app/fonts

# ignore IDE Specific files
/.idea
Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ module.exports = function(grunt) {
},
proxies: [
{
context: '/api/v1',
context: '/api/v1/content-delivery',
host: '<%= localhostUrl %>',
port: 9090,
changeOrigin: true,
xforward: true,
rewrite: {
'^/api/v1': ''
'^/api/v1/content-delivery': ''
}
}
]
Expand Down
32 changes: 32 additions & 0 deletions api/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ module.exports = {
}
}
},
QuestionDefinition: {
id: "QuestionDefinition",
required: ["validAnswer", "options", "title"],
properties: {
options: {
type: "array",
items: {
type: "string"
},
uniqueItems: true,
description: "Options available for the question"
},
title: {
type: "string",
description: "Friendly name of the question"
},
validAnswer: {
type: "string",
description: "valid answer"
}
}
},
Answer: {
id: 'Answer',
required: ['isCorrect'],
Expand All @@ -148,6 +170,16 @@ module.exports = {
id: 'Answer',
required: ['answer'],
properties: {
problemId: {
type: 'integer',
format: 'int64',
description: 'ID of the problem to answer'
},
questionId: {
type: 'integer',
format: 'int64',
description: 'ID of the question to answer'
},
answer: {
type: 'integer',
description: 'ID of the option that needs to be matched'
Expand Down
59 changes: 58 additions & 1 deletion api/problemsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ var problems = [
{
id: 2,
title: 'Introduction to AngularJS',
description: 'Instruction or some useful hints'
description: 'Instruction or some useful hints',
questionsRef: []
}
];

Expand All @@ -76,6 +77,62 @@ exports.getById = function(id) {
}
};

exports.add = function(newProblem) {
if (!newProblem || !newProblem.title || !newProblem.description) {
return;
}
newProblem.id = problems.length + 1;
newProblem.questionsRef = [];
problems.push(newProblem);

return _.pick(newProblem, ['id', 'title', 'description', 'questions']);
};

exports.addQuestion = function(problem, question) {
var i, opt, newQuestion;

problem = _.find(problems, {id: problem.id});

if (
!question ||
!question.title ||
!question.options ||
!question.validAnswer ||
question.options.length < 2
) {
return;
}

newQuestion = {
id: questions.length + 1,
title: question.title,
options: []
};

for (i = 0; i < question.options.length; i++) {
opt = {
id: i + 1,
value: question.options[i]
};

if (question.validAnswer === opt.value) {
newQuestion.validAnswer = opt.id;
}

newQuestion.options.push(opt);
}

if (!newQuestion.validAnswer) {
return;
}

questions.push(newQuestion);

problem.questionsRef.push(newQuestion.id);

return newQuestion;
};

exports.postAnswer = function(id, answer) {
var question = _.find(questions, {id: id});
if (question) {
Expand Down
71 changes: 68 additions & 3 deletions api/problemsResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ exports.findAll = {
}
};

exports.createNewProblem = {
spec: {
description: 'Operations about problems',
path: '/problems',
method: 'POST',
summary: 'Add a new problem',
notes: 'Returns a new problems',
type: 'Problem',
nickname: 'createNewProblem',
produces: ['application/json'],
parameters: [params.body('data', 'Expected JSON Payload', 'Problem')],
responseMessages: [swe.invalid('problem')]
},
action: function(req, res) {
var problem = problemsData.add(req.body);

if (problem) {
writeResponse(res, problem);
} else {
throw swe.invalid('problem');
}
}
};

exports.findById = {
spec: {
description: 'Operations about problems',
Expand All @@ -54,7 +78,7 @@ exports.findById = {
if (!req.params.problemId) {
throw swe.invalid('id');
}
var id = parseInt(req.params.problemId);
var id = parseInt(req.params.problemId, 10);
var problem = problemsData.getById(id);

if (problem) {
Expand All @@ -66,16 +90,57 @@ exports.findById = {
}
};

exports.addQuestion = {
spec: {
description: 'Operations about a problem questions',
path: '/problems/{problemId}/questions',
method: 'POST',
summary: 'Add a question to a problem',
notes: 'Returns a question and its ID',
type: 'Question',
nickname: 'addQuestion',
produces: ['application/json'],
parameters: [
params.path('problemId', 'ID of problem that needs to be fetched', 'integer'),
params.body('data', 'Expected JSON Payload', 'QuestionDefinition')
],
responseMessages: [swe.invalid('id'), swe.notFound('problem')]
},
action: function(req, res) {
var id, problem, question;

if (!req.params.problemId) {
throw swe.invalid('id');
}

id = parseInt(req.params.problemId, 10);
problem = problemsData.getById(id);

if (!problem) {
throw swe.notFound('problem');
}

question = problemsData.addQuestion(problem, req.body);
if (question) {
writeResponse(res, question);
} else {
throw swe.invalid('question');
}

}
};

exports.postAnswer = {
spec: {
description: 'Operations about problems',
path: '/problems/questions/{questionId}/answer',
path: '/problems/{problemId}/questions/{questionId}/answer',
method: 'POST',
summary: 'Answer to the question',
notes: 'Returns if the answer is true or false',
type: 'Answer',
nickname: 'postAnswer',
parameters: [
params.path('problemId', 'ID of problem that needs to be fetched', 'integer'),
params.path('questionId', 'ID of question that needs to be fetched', 'integer'),
params.body('data', 'Expected JSON Payload', 'AnswerPayload')
],
Expand All @@ -95,7 +160,7 @@ exports.postAnswer = {
throw swe.invalid('payload');
}
else {
var id = parseInt(req.params.questionId);
var id = parseInt(req.params.questionId, 10);
var answer = parseInt(body.answer, 10);
var answerObj = problemsData.postAnswer(id, answer);

Expand Down
3 changes: 3 additions & 0 deletions api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ swagger.addModels(models)
.addGet(videosResources.findAll)
.addGet(videosResources.findById)
.addPost(videosResources.create)
.addPut(videosResources.attach)
.addGet(problemsResources.findAll)
.addGet(problemsResources.findById)
.addPost(problemsResources.createNewProblem)
.addPost(problemsResources.addQuestion)
.addPost(problemsResources.postAnswer)
;

Expand Down
4 changes: 4 additions & 0 deletions api/videosData.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ exports.getAll = function() {
exports.getById = function(id) {
return _.find(videos, {id: id});
};

exports.getByProblemId = function(problemId) {
return _.find(videos, {problemId: problemId});
};
50 changes: 47 additions & 3 deletions api/videosResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ exports.findAll = {
},
nickname: 'getAllVideos',
produces: ['application/json'],
parameters: [params.query('problemId', 'Option search criteria', 'integer')],
responseMessages: [swe.notFound('videos')]
},
action: function(req, res) {
var videos = videosData.getAll();
var videos, video;

if (req.query && req.query.problemId) {
video = videosData.getByProblemId(parseInt(req.query.problemId, 10));
videos = video ? [video] : [];
} else {
videos = videosData.getAll();
}

if (videos) {
writeResponse(res, videos);
Expand Down Expand Up @@ -54,7 +62,7 @@ exports.findById = {
if (!req.params.videoId) {
throw swe.invalid('id');
}
var id = parseInt(req.params.videoId);
var id = parseInt(req.params.videoId, 10);
var video = videosData.getById(id);

if (video) {
Expand All @@ -76,7 +84,7 @@ exports.create = {
nickname: 'createVideo',
produces: ['application/json'],
parameters: [
params.body('data', 'Expected JSON Payload', 'Video')
params.body('data', 'Expected JSON Payload', 'Video')
],
responseMessages: [
swe.invalid('payload')
Expand All @@ -85,4 +93,40 @@ exports.create = {
action: function(req, res) {
writeResponse(res,{status:"ok"});
}
};

exports.attach = {
spec: {
description: 'Attach video',
path: '/videos/{videoId}/problem',
method: 'PUT',
summary: 'Attach a problem to a video',
nickname: 'attachProblem',
parameters: [
params.path('videoId', 'ID of video that will be edited', 'integer'),
params.body('data', 'Expected JSON Payload', 'Video')
],
responseMessages: [
swe.invalid('payload')
]
},
action: function(req, res) {
if (!req.params.videoId) {
throw swe.invalid('id');
}

var id = parseInt(req.params.videoId, 10);
var video = videosData.getById(id);

if (!video) {
throw swe.notFound('video');
}

if (!req.body.problemId) {
throw swe.invalid('payload');
}

video.problemId = req.body.problemId;
writeResponse(res,{status:"ok"});
}
};
Loading