Skip to content

Commit 8ea8c1c

Browse files
committed
Add FeedbacksAPI and WebAPI to the project
1 parent b54c60e commit 8ea8c1c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

app/api/web/feedbacks_api.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module API
2+
class Web::FeedbacksAPI < Grape::API
3+
resource :feedback do
4+
desc 'Create feedback'
5+
params do
6+
requires :content, type: String
7+
requires :user_id, type: Integer
8+
end
9+
post do
10+
Feedback.create!({
11+
content: params[:content],
12+
user_id: params[:user_id]
13+
})
14+
end
15+
16+
desc 'Get feedback'
17+
get do
18+
Feedback.all
19+
end
20+
21+
desc 'Delete feedback'
22+
params do
23+
requires :id, type: Integer
24+
requires :user_id, type: Integer
25+
end
26+
delete ':id' do
27+
Feedback.find_by(id: params[:id], user_id: params[:user_id]).destroy
28+
end
29+
30+
desc 'Update feedback'
31+
params do
32+
requires :id, type: Integer
33+
requires :content, type: String
34+
requires :user_id, type: Integer
35+
end
36+
37+
put ':id' do
38+
feedback = Feedback.find_by(id: params[:id], user_id: params[:user_id])
39+
feedback.update!({
40+
content: params[:content],
41+
user_id: params[:user_id]
42+
})
43+
end
44+
end
45+
end
46+
end

app/api/web_api.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class WebAPI < Grape::API
2+
3+
mount Web::FeedbacksAPI
4+
5+
add_swagger_documentation(
6+
format: :json,
7+
hide_documentation_path: true,
8+
mount_path: '/doc',
9+
hide_format: true,
10+
doc_version: nil,
11+
produces: ['application/json'],
12+
consumes: ['application/json'],
13+
info: {
14+
title: 'CodeLearn APIs Documentation',
15+
description: 'This is a documentation of CodeLearn APIs. To support client rendering the UI',
16+
}
17+
)
18+
end

0 commit comments

Comments
 (0)