Skip to content

Commit ed2d594

Browse files
authored
Release v20.12.2023
Release v20.12.2023
2 parents 4bcf1e6 + 16208bc commit ed2d594

File tree

13 files changed

+141
-2
lines changed

13 files changed

+141
-2
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ gem "sprockets-rails"
1212
# Use sqlite3 as the database for Active Record
1313
gem "sqlite3", "~> 1.4"
1414

15+
gem 'pg'
16+
1517
# Use the Puma web server [https://github.com/puma/puma]
1618
gem "puma", "~> 5.0"
1719

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ GEM
190190
mini_portile2 (~> 2.8.0)
191191
racc (~> 1.4)
192192
orm_adapter (0.5.0)
193+
pg (1.5.4)
193194
psych (5.1.1.1)
194195
stringio
195196
public_suffix (5.0.4)
@@ -323,6 +324,7 @@ DEPENDENCIES
323324
grape_logging
324325
importmap-rails
325326
jbuilder
327+
pg
326328
puma (~> 5.0)
327329
rails (~> 7.0.4, >= 7.0.4.3)
328330
redis (~> 4.0)

app/api/web/feedbacks_api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module API
22
class Web::FeedbacksAPI < Grape::API
3+
34
resource :feedbacks do
5+
46
desc 'Create feedback'
57
params do
68
requires :content, type: String, allow_blank: false

app/api/web/posts_api.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,34 @@ def format_post(post)
221221
end
222222
}
223223
end
224+
225+
desc 'Create a feedback for a post'
226+
params do
227+
requires :id, type: Integer, desc: 'Post id'
228+
requires :content, type: String, desc: 'Feedback content', allow_blank: false
229+
end
230+
post '/:id/feedbacks' do
231+
authenticate_user!
232+
post = Post.find_by(id: params[:id])
233+
return status 400 unless post
234+
feedback = post.feedbacks.new({
235+
user_id: current_user.id,
236+
content: params[:content]
237+
})
238+
if feedback.save
239+
status 200
240+
{
241+
success: true,
242+
message: 'Feedback created successfully'
243+
}
244+
else
245+
status 400
246+
{
247+
success: false,
248+
error: 'Feedback cannot be created'
249+
}
250+
end
251+
end
224252
end
225253
end
226254
end

app/controllers/docs_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class DocsController < ApplicationController
2+
3+
http_basic_authenticate_with(
4+
name: Rails.application.credentials.dig(:basic_auth, :api_username),
5+
password: Rails.application.credentials.dig(:basic_auth, :api_password),
6+
only: :index,
7+
)
8+
9+
def index
10+
end
11+
end

app/helpers/docs_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module DocsHelper
2+
end

app/views/docs/index.html.erb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Docs</title>
6+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.1.1/swagger-ui.css">
7+
</head>
8+
9+
<body>
10+
<div id="ui-wrapper-new" data-spec="/api/web/doc.json">
11+
Loading....
12+
</div>
13+
</body>
14+
<script src="https://unpkg.com/swagger-ui-dist@5.1.1/swagger-ui-bundle.js"></script>
15+
<script>
16+
var swaggerUIOptions = {
17+
url: '/api/web/doc.json',
18+
dom_id: '#ui-wrapper-new',
19+
docExpansion: 'list',
20+
deepLinking: true,
21+
filter: true,
22+
presets: [
23+
SwaggerUIBundle.presets.apis,
24+
SwaggerUIBundle.SwaggerUIStandalonePreset
25+
],
26+
plugins: [
27+
SwaggerUIBundle.plugins.DownloadUrl
28+
],
29+
requestInterceptor: function (request) {
30+
request.headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
31+
request.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
32+
return request;
33+
},
34+
}
35+
36+
var ui = SwaggerUIBundle(swaggerUIOptions)
37+
38+
window.ui = ui
39+
</script>
40+
41+
</html>

config/credentials.yml.enc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bnMbcO9jI+ZVwANkEbRXicq4F3Cz65ANfWLuPoCiCdkq0aRrgJY9ytGg2F+eFBbFBcSIUXiUsapE+1O8FO8SG3uk/6OPT5PYpvd4oZrnVUG71bkQY8+gz3VWhHm6L9U6CdQCViktRGkdIbTyX5vQWEjZQXD1gzeQpYrWgOFJDux8DlqQCvWSTzwmIdSC2i5tZjZ0ViidDZ6ac1LOvQniFjtXlV2TXwsPIUbwVEXVoVajKRu7IS3qb77kXPfxuvS8wYh/xg6Z75w6hQ/3OxgTeYDKeqVfvAxDULmMAqx32/Rug14hb5PXp/MODk0Su/ddz/GCYRtIZrDwmwTnyHppCdPMGZhpVRFfInCjlRaHSZw0BreIwUU1GHDr9hiLq4sMm7MhDgWp1CW/28bg2kfETiq97ln2R0ssNlt7j4r/KnRlq4hzwfJ3ZPxVCRC2Fx4kx3vMotZ/0QVBUqJH/dA=--gM9qn9Lvnfpo8C0L--k5jFAP7f8FpGe/K0HRa0wg==
1+
nasE/EtVFeCB7jb5LyyM74X5mVP2/c6sM8SpfwXn5DDpzAqNKoH0nkavnPnc2BH9y/A9O55/Grq5lC/GD8OwlRSHCbZUwYUK2s6I31m/FNNlnKP+sGr9u4Smz82OuMDhMp5c/M7xXw6x6XhwNCaktbLLHB7RsFE16YD53dbo93lF0iaA/7MNGssLg9fGm5TMXiEHr2sbs76qGzCzBvHH8RNqZvFY8gJ/9ufJkPDEchoiNZ3rpWuxT7sVxu49eEul8hckjH/6As844srVWCIdwZfbet+wPLSPOuv/WUoIMoSK3Zja8EchG8Mxaf7EqN02nNEc0Sxcvg0IatZ94bHthqJ+32Pu90r4aE6sVcE4WFBhGuh7gk0+rbRr3ZUOrs4yPJJwMhgX0IinrJGbauasqBhPbd7PcbT6/gYc7TPHAOazK6EInU5ym+KIryRxx4+3H2xmswdQOPorpv1UCBqVZlRqRrgoF0yUYQJiVv8tMXwWxPW8Qut/irF/0FO3PI+rmWUOHRXGc2cC3r6vzPctLifWV7XzjkM2W6jZHeETvx74mGjiVKndTWeoYgerKMPFMmCIZGNG7J2WRgkGeZb+VVE+shH/FD/hSyEBBuCd6ZbDQOKrxhOFzMrFyEUh7sK1Eac4ma1/vv28mnOfsEV7KQHOFgRD5lQ9yZOc2p3pTojD/COqN+GCC3MY28KQqA9mskKx2/MBzv0w5snjy5pwuM/+E4rEpsCzIo8a4vUmx0S0U6Zwtr3faUxlA5D4fy1EilNu2mQ=--uOZmcZEsArPq8ZMN--tn3tcNgW4JCq1Bs/tOozPw==

config/database.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ test:
2222

2323
production:
2424
<<: *default
25-
database: db/production.sqlite3
25+
adapter: postgresql
26+
encoding: unicode
27+
host: <%= Rails.application.credentials.dig(:database, :host) %>
28+
username: <%= Rails.application.credentials.dig(:database, :username) %>
29+
password: <%= Rails.application.credentials.dig(:database, :password) %>

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
# Defines the root path route ("/")
66
# root "articles#index"
7+
get '/docs', to: 'docs#index'
8+
79
mount ApplicationAPI => '/api'
810
end

0 commit comments

Comments
 (0)