Skip to content

Commit

Permalink
Merge pull request #2 from andela-iamadi/answer_comments_endpoint
Browse files Browse the repository at this point in the history
Answer comments endpoint
  • Loading branch information
oojewale committed Jan 17, 2016
2 parents 57e4c0b + 94ab7b6 commit 4c33af9
Show file tree
Hide file tree
Showing 5 changed files with 482 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'omniauth-slack'
gem "omniauth-google-oauth2"
gem 'figaro'
gem 'ancestry'
gem 'pry-rails'

group :development, :test do
gem 'sqlite3'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GEM
activerecord (>= 3.0.0)
arel (6.0.3)
builder (3.2.2)
coderay (1.1.0)
concurrent-ruby (1.0.0)
erubis (2.7.0)
faraday (0.9.2)
Expand All @@ -57,6 +58,7 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.99)
mini_portile2 (2.0.0)
minitest (5.8.3)
Expand Down Expand Up @@ -86,6 +88,12 @@ GEM
omniauth-slack (2.3.0)
omniauth-oauth2 (~> 1.3.1)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -117,6 +125,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.5.0)
slop (3.6.0)
spring (1.6.2)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
Expand All @@ -141,6 +150,7 @@ DEPENDENCIES
omniauth-oauth2 (~> 1.3.1)
omniauth-slack
pg
pry-rails
rails (= 4.2.5)
rails-api
spring
Expand Down
233 changes: 233 additions & 0 deletions docs/answers_endpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
#Answers Resources

Endpoints | Usage | Public Access
--------- | ----- | -------------
GET /questions/:id/answers | Returns all the answers for a particular question | True
POST /questions/:id/answers/ | Creates a new answer for the specified question | False
GET /questions/:id/answers/recent?limit={:total} | Returns {total} answers ordered by the most recent [ MAXLIMIT = 50 ] | True
GET /questions/:id/answers/popular?limit={:total} | Returns {total} answers ordered by the most popular [ MAXLIMIT = 50 ] | True
POST /questions/:id/answers/:id/upvote | Upvotes an answer | False
POST /questions/:id/answers/:id/downvote | Downvotes an answer | False
PUT /answers/:id | Updates the answer with certain attributes | False
DELETE /answers/:id | Deletes an answer and its related comments | False

### GET /questions/:id/answers

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335"
}
```

Response
```ruby
Status: 200
{
question: {
id: 1,
answers: [
{
id: 2,
text: 'What do you really want to do?',
date_created: 'Wed, 24TH Nov, 2017 10:00AM',
updated: false,
score: 8,
user: {
id: 2,
name: 'Oscar Laide'
}
},
{
id: 4,
text: 'This is such a scam',
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
updated: true,
score: 9,
user: {
id: 3,
name: 'Bayo Owoade'
}
}
]
}
}
```

```ruby
Status: 404
{
message: "Question not found"
}
```


### POST /questions/:id/answers/

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335",
text: "Why in the world do I have to do this?"
}
```

Response
```ruby
Status: 201
{
message: "Successfully added"
}
```

### GET /questions/:id/answers/recent?limit=10

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335"
}
```

Response
```ruby
Status: 200
{
question: {
id: 1,
limit: 10,
answers: [
{
id: 4,
text: 'This is such a scam',
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
updated: true,
user: {
id: 3,
name: 'Bayo Owoade'
}
},
{
id: 2,
text: 'What do you really want to do?',
date_created: 'Wed, 24TH Nov, 2017 10:00AM',
updated: false,
user: {
id: 2,
name: 'Oscar Laide'
}
}
]
}
}
```

### GET /questions/:id/answers/popular?limit={:total}

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335"
}
```

Response
```ruby
# note score param added to the answer
Status: 200
{
question: {
id: 1,
limit: 10,
answers: [
{
id: 4,
text: 'This is such a scam',
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
updated: true,
score: 9,
user: {
id: 3,
name: 'Bayo Owoade'
}
},
{
id: 2,
text: 'What do you really want to do?',
date_created: 'Wed, 24TH Nov, 2017 10:00AM',
updated: false,
score: 8,
user: {
id: 2,
name: 'Oscar Laide'
}
}
]
}
}
```

### POST /questions/:id/answers/:id/upvote

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335",
answer_id: 5
}
```

Response
```ruby
Status: 201
{
message: "Successfully upvoted"
}
```

### POST /questions/:id/answers/:id/downvote

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335",
answer_id: 5
}
```

Response
```ruby
Status: 201
{
message: "Successfully downvoted"
}
```

### PUT /answers/:id

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335",
text: "What in the world does this mean?"
}
```

Response
```ruby
Status: 204
```

### DELETE /answers/:id

Request
```ruby
{
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335"
}
```

Response
```ruby
Status: 204
```
5 changes: 5 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# API Endpoints

The most important parameter for all endpoints except the `Home#index` is the
`user_token`, which can be sent either as a header or as a request params

The token allows the application to authenticate on what
Loading

0 comments on commit 4c33af9

Please sign in to comment.