Skip to content

Commit 0501f56

Browse files
author
Osmond Oscar
committed
Update comment documentation to reflect new changes
1 parent d61e8df commit 0501f56

File tree

4 files changed

+278
-15
lines changed

4 files changed

+278
-15
lines changed

app/controllers/comments_controller.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class CommentsController < ApplicationController
22
before_action :set_resource
33
before_action :set_comment, only: [:show, :update, :destroy]
4+
include OwnershipConcern
45

56
def index
67
render json: @resource_comments, status: 200
@@ -14,23 +15,23 @@ def create
1415
comment = @resource_comments.new(content: comment_params[:content])
1516
comment.user = current_user
1617
if comment.save
17-
render json: comment, root: false
18+
render json: comment, status: 201
1819
else
1920
invalid_request("Comment body can not be empty!")
2021
end
2122
end
2223

2324
def update
2425
if @comment.update(content: comment_params[:content])
25-
render json: @comment
26+
render json: @comment, status: 200
2627
else
2728
invalid_request("Comment body can not be empty!")
2829
end
2930
end
3031

3132
def destroy
3233
if @comment.try(:destroy)
33-
render json: { response: "Comment deleted." }, status: 410
34+
render json: :head, status: 204
3435
else
3536
invalid_request
3637
end
@@ -51,9 +52,5 @@ def set_resource
5152
def set_comment
5253
@comment = @resource_comments.find_by(id: comment_params[:id])
5354
resource_not_found && return unless @comment
54-
55-
unless (params[:action] == 'show') || (@comment.user.eql? current_user)
56-
render json: { error: "It is your comment?" }, status: 401
57-
end
5855
end
5956
end

config/routes.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
get "top_questions" => "questions#top_questions"
2121

22-
resources :answers, except: [:index, :show, :create, :destroy, :update, :new, :edit]
23-
2422
post "users/logout" => "user#logout"
2523
get 'users/renew_token' => 'users#renew_token'
2624
get "users" => "users#index"

docs/comments_endpoints.md

Lines changed: 167 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ Endpoints | Usage | Public Access
44
--------- | ----- | -------------
55
GET /answers/:id/comments | Returns all the comments for a particular answer | True
66
POST /answers/:id/comments/ | Creates a new comment for the specified answer | False
7-
PUT /comments/:id | Updates the comment with certain attributes | False
8-
DELETE /comments/:id | Deletes an comment | False
7+
PATCH /answers/:answer_id/comments/:id | Updates the specified comment of the specified answer | False
8+
DELETE /answers/:answer_id/comments/:id | Deletes the specified comment of the specified answer | False
9+
GET /questions/:id/comments | Returns all the comments for a particular question | True
10+
POST /questions/:id/comments/ | Creates a new comment for the specified question | False
11+
PATCH /questions/:question_id/comments/:id | Updates the specified comment of the specified question | False
12+
DELETE /questions/:question_id/comments/:id | Deletes the specified comment of the specified question | False
913

1014
### GET /answers/:id/comments
1115

@@ -49,11 +53,63 @@ Status: 200
4953
}
5054
}
5155
```
56+
Or
5257

5358
```ruby
5459
Status: 404
5560
{
56-
message: "Answer not found"
61+
error: "The resource you tried to access was not found"
62+
}
63+
```
64+
65+
### GET /questions/:id/comments
66+
67+
Request
68+
```ruby
69+
{
70+
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335"
71+
}
72+
```
73+
74+
Response
75+
```ruby
76+
Status: 200
77+
{
78+
answer: {
79+
id: 1,
80+
comments: [
81+
{
82+
id: 2,
83+
text: 'What do you really want to do?',
84+
date_created: 'Wed, 24TH Nov, 2017 10:00AM',
85+
updated: false,
86+
score: 8,
87+
user: {
88+
id: 2,
89+
name: 'Oscar Laide'
90+
}
91+
},
92+
{
93+
id: 4,
94+
text: 'This is such a scam',
95+
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
96+
updated: true,
97+
score: 9,
98+
user: {
99+
id: 3,
100+
name: 'Bayo Owoade'
101+
}
102+
}
103+
]
104+
}
105+
}
106+
```
107+
Or
108+
109+
```ruby
110+
Status: 404
111+
{
112+
error: "The resource you tried to access was not found"
57113
}
58114
```
59115

@@ -72,11 +128,52 @@ Response
72128
```ruby
73129
Status: 201
74130
{
75-
message: "Successfully added"
131+
id: 4,
132+
text: 'This is such a scam',
133+
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
134+
updated: true,
135+
score: 9,
136+
user: {
137+
id: 3,
138+
name: 'Bayo Owoade'
139+
}
76140
}
77141
```
78142

79-
### PUT /comments/:id
143+
### POST /questions/:id/comments/
144+
145+
Request
146+
```ruby
147+
{
148+
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335",
149+
content: "Why in the world do I have to do this?"
150+
}
151+
```
152+
153+
Response
154+
```ruby
155+
Status: 201
156+
{
157+
id: 4,
158+
text: 'This is such a scam',
159+
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
160+
updated: true,
161+
score: 9,
162+
user: {
163+
id: 3,
164+
name: 'Bayo Owoade'
165+
}
166+
}
167+
```
168+
OR
169+
```ruby
170+
Status: 404
171+
{
172+
error: "Comment body can not be empty!"
173+
}
174+
```
175+
176+
### PATCH /answers/:answer_id/comments/:id
80177

81178
Request
82179
```ruby
@@ -86,12 +183,68 @@ Request
86183
}
87184
```
88185

186+
Response
187+
```ruby
188+
Status: 200
189+
{
190+
id: 4,
191+
text: 'This is such a scam',
192+
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
193+
updated: true,
194+
score: 9,
195+
user: {
196+
id: 3,
197+
name: 'Bayo Owoade'
198+
}
199+
}
200+
```
201+
### PATCH /questions/:question_id/comments/:id
202+
203+
Request
204+
```ruby
205+
{
206+
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335",
207+
content: "What in the world does this mean?"
208+
}
209+
```
210+
211+
Response
212+
```ruby
213+
Status: 200
214+
{
215+
id: 4,
216+
text: 'This is such a scam',
217+
date_created: 'Wed, 25TH Nov, 2017 12:00PM',
218+
updated: true,
219+
score: 9,
220+
user: {
221+
id: 3,
222+
name: 'Bayo Owoade'
223+
}
224+
}
225+
```
226+
OR
227+
```ruby
228+
Status: 404
229+
{
230+
error: "Comment body can not be empty!"
231+
}
232+
```
233+
### DELETE /answers/:answer_id/comments/:id
234+
235+
Request
236+
```ruby
237+
{
238+
auth_token: "90ioji0j0i0i0ik0k0jmj0090jknieu93833r335"
239+
}
240+
```
241+
89242
Response
90243
```ruby
91244
Status: 204
92245
```
93246

94-
### DELETE /comments/:id
247+
### DELETE /questions/:answer_id/comments/:id
95248

96249
Request
97250
```ruby
@@ -104,3 +257,11 @@ Response
104257
```ruby
105258
Status: 204
106259
```
260+
261+
OR
262+
```ruby
263+
Status: 404
264+
{
265+
error: "The operation could not be performed. Please check your request or try again later"
266+
}
267+
```

docs/vote_endpoints.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#Votes Resources
2+
3+
Endpoints | Usage | Public Access
4+
--------- | ----- | -------------
5+
POST /questions/:question_id/upvote | Increase the upvotes of the given question by one unit | False
6+
POST /questions/:question_id/downvote | Increase the downvotes of the given question by one unit | False
7+
POST /answers/:answer_id/upvote | Increase the upvotes of the given answer by one unit | False
8+
POST /answers/:answer_id/downvote | Increase the downvotes of the given answers by one unit | False
9+
POST /comments/:question_id/upvote | Increase the upvotes of the given comment by one unit | False
10+
POST /comments/:question_id/downvote | Increase the downvotes of the given comments by one unit | False
11+
12+
### POST /questions/:question_id/upvote/
13+
14+
Response
15+
```ruby
16+
Status: 200
17+
{
18+
response: 11
19+
}
20+
```
21+
#### OR
22+
```ruby
23+
Status: 403
24+
{
25+
error: "Invalid vote!"
26+
}
27+
```
28+
### POST /comments/:comment_id/upvote/
29+
30+
Response
31+
```ruby
32+
Status: 200
33+
{
34+
response: 23
35+
}
36+
```
37+
#### OR
38+
```ruby
39+
Status: 403
40+
{
41+
error: "Invalid vote!"
42+
}
43+
```
44+
### POST /answers/:answer_id/upvote/
45+
46+
Response
47+
```ruby
48+
Status: 200
49+
{
50+
response: 0
51+
}
52+
```
53+
#### OR
54+
```ruby
55+
Status: 403
56+
{
57+
error: "Invalid vote!"
58+
}
59+
```
60+
### POST /questions/:question_id/downvote/
61+
62+
Response
63+
```ruby
64+
Status: 200
65+
{
66+
response: 2
67+
}
68+
```
69+
#### OR
70+
```ruby
71+
Status: 403
72+
{
73+
error: "Invalid vote!"
74+
}
75+
```
76+
### POST /comments/:comment_id/downvote/
77+
78+
Response
79+
```ruby
80+
Status: 200
81+
{
82+
response: -12
83+
}
84+
```
85+
#### OR
86+
```ruby
87+
Status: 403
88+
{
89+
error: "Invalid vote!"
90+
}
91+
```
92+
### POST /answers/:answer_id/downvote/
93+
94+
Response
95+
```ruby
96+
Status: 200
97+
{
98+
response: 34
99+
}
100+
```
101+
#### OR
102+
```ruby
103+
Status: 403
104+
{
105+
error: "Invalid vote!"
106+
}
107+
```

0 commit comments

Comments
 (0)