Skip to content

Commit

Permalink
title attribute now within Post; added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Greenland committed Feb 18, 2014
1 parent 02fff98 commit ef1ee4a
Show file tree
Hide file tree
Showing 12 changed files with 2,819 additions and 10 deletions.
521 changes: 521 additions & 0 deletions README.html

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Overview
The web service allows questions to be added, updated and removed. Comments can be added to questions for remarks on the content of the question. Answers can be added to questions in response to a question posed. Comments can also be added to answers for remarks on the content of the answer.

Cache validation is supported through the use of ETags on the server-side and the HTTP header "If-None-Match" in client requests to the Web Service.


# Installation
The following steps aim to provide a brief guide on how to set up the web service on Ubuntu Server LTS 12.04.

1. Install Node.js

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install curl
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install
curl https://npmjs.org/install.sh | sh

2. Install and updated required packages with ```npm update```

# Usage

## Run
To run the server with the existing database use:

```node index```

When the server has started, in a new shell you can issue HTTP requests, via cURL for example.

On the first run, there will be no existing database, so this is equivalent to running from a clean start.

## Run from clean start
To run the server with an empty database use:

```node index -r```

For the first run, the ```-r``` option is not necessary.

# API
For documentation of the API with endpoints and examples, see [```doc/api.html```](doc/api.html) or [```doc/api.md```](doc/api.md).

# Test
To run the system testing script, ensure the web service server is not running, then execute:

```npm test```

This starts the web service server from a clean start and tests questions, question comments, answers and answer comments and the integration of such.

The test script can also be executed in a two-step process with 2 shells:

node index -r
node test

## Shell script
A shell script, ```bin/demo.sh```, provides a series of cURL commands that request each endpoint of the web service.

## JSLint conformance script
To test the conformance of the code to JSLint, run ```bin/jslint-check.sh```.
Before running, ensure you have globally installed JSLint: ```npm install jslint -g```.

2 changes: 2 additions & 0 deletions controllers/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports.get = function (req, res) {
if (!err && answer) {
var newanswer = {
id: answer.id,
title: answer.title,
text: answer.text,
date: answer.date,
author: answer.author,
Expand Down Expand Up @@ -127,6 +128,7 @@ exports.create = function (req, res) {
generic.create(req.models.Answer, {}, req, function (err, answer) {
if (!err && answer) {
answer.setQuestion(question, function (err) {
// TODO: Change this so that it redirects to created answer.
generic.get(req.models.Answer, answer.id, undefined, function (err, answer2) {
if (!err && answer2) {
var answerTmp = {
Expand Down
1 change: 1 addition & 0 deletions controllers/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports.create = function (model, data, req, cb) {
now = new Date().getTime();

req.models.Post.create([{
title: req.body.title,
text: req.body.text,
date: new Date(),
author: req.body.author,
Expand Down
11 changes: 5 additions & 6 deletions controllers/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ exports.get = function (req, res) {
console.log('answers');
console.log(answers);

// Include answers within question
async.each(answers, generic.gen, function (err) {
if (!err) {
console.log('answers');
Expand All @@ -136,9 +137,6 @@ exports.get = function (req, res) {
});




// res.end();
} else if (err === enums.NOT_MODIFIED) {
// 304 Not Modified.
res.status(304);
Expand Down Expand Up @@ -174,8 +172,9 @@ exports.head = function (req, res) {
exports.create = function (req, res) {
// This is a POST request, so by default, fields go into the body.

var data = { //only extra column(than post) need to bw written here
title: req.body.title
// only extra columns (apart from post) need to be written here
var data = {

};
generic.create(req.models.Question, data, req, function (err, question) {
if (!err && question) {
Expand All @@ -189,7 +188,7 @@ exports.create = function (req, res) {
res.json(wrapper);
res.end();
} else {
//special err: if 404 then it means the create just excuted is invalid.
//special err: if 404 then it means the create just executed is invalid.
res.status(500);
res.end('Error 500: Server Error');
console.r.error(req, 500, err);
Expand Down
5 changes: 5 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# API Documentation
See api.md for the generated normative documentation of the API.
See api.html for the API documentation in HTML.

**Don't edit files in this folder – they're automatically generated!**
Loading

0 comments on commit ef1ee4a

Please sign in to comment.