Skip to content

Commit 4e55ab2

Browse files
committed
Update dependencies and routes, add Blazer migration and config
1 parent 16208bc commit 4e55ab2

17 files changed

+277
-61
lines changed

Gemfile

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

4-
ruby "3.2.0"
4+
ruby '3.2.0'
55

66
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7-
gem "rails", "~> 7.0.4", ">= 7.0.4.3"
7+
gem 'rails', '~> 7.0.4', '>= 7.0.4.3'
88

99
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
10-
gem "sprockets-rails"
10+
gem 'sprockets-rails'
1111

1212
# Use sqlite3 as the database for Active Record
13-
gem "sqlite3", "~> 1.4"
13+
gem 'sqlite3', '~> 1.4'
1414

1515
gem 'pg'
1616

1717
# Use the Puma web server [https://github.com/puma/puma]
18-
gem "puma", "~> 5.0"
18+
gem 'puma', '~> 5.0'
1919

2020
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
21-
gem "importmap-rails"
21+
gem 'importmap-rails'
2222

2323
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
24-
gem "turbo-rails"
24+
gem 'turbo-rails'
2525

2626
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
27-
gem "stimulus-rails"
27+
gem 'stimulus-rails'
2828

2929
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
30-
gem "jbuilder"
30+
gem 'jbuilder'
3131

3232
# Use Redis adapter to run Action Cable in production
33-
gem "redis", "~> 4.0"
33+
gem 'redis', '~> 4.0'
3434

3535
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
3636
# gem "kredis"
@@ -39,12 +39,12 @@ gem "redis", "~> 4.0"
3939
# gem "bcrypt", "~> 3.1.7"
4040

4141
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
42-
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
42+
gem 'tzinfo-data', platforms: %i[ mingw mswin x64_mingw jruby ]
4343

4444
# Reduces boot times through caching; required in config/boot.rb
45-
gem "bootsnap", require: false
45+
gem 'bootsnap', require: false
4646

47-
gem "devise"
47+
gem 'devise'
4848

4949
gem 'devise-jwt'
5050

@@ -58,6 +58,8 @@ gem 'grape_logging'
5858

5959
gem 'faker'
6060

61+
gem 'blazer'
62+
6163
# Use Sass to process CSS
6264
# gem "sassc-rails"
6365

@@ -66,15 +68,15 @@ gem 'faker'
6668

6769
group :development, :test do
6870
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
69-
gem "debug", platforms: %i[ mri mingw x64_mingw ]
71+
gem 'debug', platforms: %i[ mri mingw x64_mingw ]
7072
gem 'byebug'
7173
gem 'rspec-rails'
7274
gem 'factory_bot_rails'
7375
end
7476

7577
group :development do
7678
# Use console on exceptions pages [https://github.com/rails/web-console]
77-
gem "web-console"
79+
gem 'web-console'
7880

7981
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
8082
# gem "rack-mini-profiler"
@@ -85,7 +87,7 @@ end
8587

8688
group :test do
8789
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
88-
gem "capybara"
89-
gem "selenium-webdriver"
90-
gem "webdrivers"
90+
gem 'capybara'
91+
gem 'selenium-webdriver'
92+
gem 'webdrivers'
9193
end

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ GEM
7272
rack
7373
bcrypt (3.1.20)
7474
bindex (0.8.1)
75+
blazer (3.0.2)
76+
activerecord (>= 6.1)
77+
chartkick (>= 5)
78+
railties (>= 6.1)
79+
safely_block (>= 0.4)
7580
bootsnap (1.17.0)
7681
msgpack (~> 1.2)
7782
builder (3.2.4)
@@ -85,6 +90,7 @@ GEM
8590
rack-test (>= 0.6.3)
8691
regexp_parser (>= 1.5, < 3.0)
8792
xpath (~> 3.2)
93+
chartkick (5.0.5)
8894
concurrent-ruby (1.2.2)
8995
crass (1.0.6)
9096
date (3.3.4)
@@ -258,6 +264,7 @@ GEM
258264
rspec-support (3.12.1)
259265
ruby2_keywords (0.0.5)
260266
rubyzip (2.3.2)
267+
safely_block (0.4.0)
261268
selenium-webdriver (4.10.0)
262269
rexml (~> 3.2, >= 3.2.5)
263270
rubyzip (>= 1.2.2, < 3.0)
@@ -311,6 +318,7 @@ PLATFORMS
311318

312319
DEPENDENCIES
313320
appsignal
321+
blazer
314322
bootsnap
315323
byebug
316324
capybara

app/api/helpers/authentication_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def authenticate_user!
88
def current_user
99
@current_user ||=
1010
begin
11-
token = request.headers['Authorization'].split(' ').last
11+
token = request.headers['Token']
1212
User.find_by(id: JWT.decode(token, Rails.application.credentials.devise_jwt_secret_key)[0]['user_id']) if token
1313
rescue JWT::DecodeError
1414
nil

app/api/web/feedbacks_api.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ class Web::FeedbacksAPI < Grape::API
33

44
resource :feedbacks do
55

6-
desc 'Create feedback'
6+
desc 'Create feedback',
7+
security: [access_token: {}]
78
params do
89
requires :content, type: String, allow_blank: false
910
requires :post_id, type: Integer
@@ -47,7 +48,8 @@ class Web::FeedbacksAPI < Grape::API
4748
end
4849
end
4950

50-
desc 'Delete feedback'
51+
desc 'Delete feedback',
52+
security: [access_token: {}]
5153
params do
5254
requires :id, type: Integer
5355
end
@@ -70,7 +72,8 @@ class Web::FeedbacksAPI < Grape::API
7072
end
7173
end
7274

73-
desc 'Update feedback'
75+
desc 'Update feedback',
76+
security: [access_token: {}]
7477
params do
7578
requires :id, type: Integer
7679
requires :new_content, type: String, allow_blank: false

app/api/web/posts_api.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def format_post(post)
7777
end
7878
end
7979

80-
desc 'Create a post'
80+
desc 'Create a post',
81+
security: [access_token: {}]
8182
params do
8283
requires :title, type: String, desc: 'Post title', allow_blank: false
8384
requires :body, type: String, desc: 'Post body', allow_blank: false
@@ -88,6 +89,7 @@ def format_post(post)
8889
post = current_user.posts.new({
8990
title: params[:title],
9091
body: params[:body],
92+
total_view: 0,
9193
status: 'approved'
9294
})
9395
end
@@ -107,7 +109,8 @@ def format_post(post)
107109
end
108110
end
109111

110-
desc 'Update a post'
112+
desc 'Update a post',
113+
security: [access_token: {}]
111114
params do
112115
requires :id, type: Integer, desc: 'Post id'
113116
optional :new_title, type: String, desc: 'New post title'
@@ -135,7 +138,8 @@ def format_post(post)
135138
end
136139
end
137140

138-
desc 'Delete a post'
141+
desc 'Delete a post',
142+
security: [access_token: {}]
139143
params do
140144
requires :id, type: Integer, desc: 'Post id'
141145
end
@@ -175,7 +179,8 @@ def format_post(post)
175179
}
176180
end
177181

178-
desc 'Approve a post'
182+
desc 'Approve a post',
183+
security: [access_token: {}]
179184
params do
180185
requires :id, type: Integer, desc: 'Post id'
181186
end
@@ -222,7 +227,8 @@ def format_post(post)
222227
}
223228
end
224229

225-
desc 'Create a feedback for a post'
230+
desc 'Create a feedback for a post',
231+
security: [access_token: {}]
226232
params do
227233
requires :id, type: Integer, desc: 'Post id'
228234
requires :content, type: String, desc: 'Feedback content', allow_blank: false

app/api/web/registrations_api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class Web::RegistrationsAPI < Grape::API
44
desc 'Create a new user'
55
params do
66
requires :user, type: Hash do
7+
optional :first_name, type: String, desc: 'First name'
8+
optional :last_name, type: String, desc: 'Last name'
79
requires :email, type: String, desc: 'Email'
810
requires :password, type: String, desc: 'Password'
911
requires :password_confirmation, type: String, desc: 'Password confirmation'

app/api/web/sessions_api.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class Web::SessionsAPI < Grape::API
2424
end
2525
end
2626

27-
desc 'Sign out and revoke JWT token'
27+
desc 'Sign out and revoke JWT token',
28+
security: [access_token: {}]
2829
delete 'sign_out' do
2930
authenticate_user!
30-
current_user.revoke_jwt(request.headers['Authorization'])
31+
current_user.revoke_jwt(request.headers['token'])
3132
status 200
3233
{
3334
success: true,

app/api/web_api.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class WebAPI < Grape::API
2020
info: {
2121
title: 'CodeLearn APIs Documentation',
2222
description: 'This is a documentation of CodeLearn APIs. To support client rendering the UI',
23-
}
23+
},
24+
security_definitions: {
25+
access_token: {
26+
name: 'token',
27+
type: :apiKey,
28+
in: :header,
29+
},
30+
},
2431
)
2532
end

config/application.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ class Application < Rails::Application
2323

2424
# config.eager_load_paths << Rails.root.join("extras")
2525
config.eager_load_paths << Rails.root.join('app/api')
26+
27+
config.before_initialize do
28+
ENV["BLAZER_USERNAME"] = Rails.application.credentials.dig(:basic_auth, :blazer_username)
29+
ENV["BLAZER_PASSWORD"] = Rails.application.credentials.dig(:basic_auth, :blazer_password)
30+
end
2631
end
2732
end

config/blazer.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# see https://github.com/ankane/blazer for more info
2+
data_sources:
3+
main:
4+
url: <%= ENV["DATABASE_URL"].presence || 'sqlite3:db/development.sqlite3' %>
5+
6+
# statement timeout, in seconds
7+
# none by default
8+
# timeout: 15
9+
10+
# caching settings
11+
# can greatly improve speed
12+
# off by default
13+
# cache:
14+
# mode: slow # or all
15+
# expires_in: 60 # min
16+
# slow_threshold: 15 # sec, only used in slow mode
17+
18+
# wrap queries in a transaction for safety
19+
# not necessary if you use a read-only user
20+
# true by default
21+
# use_transaction: false
22+
23+
smart_variables:
24+
# zone_id: "SELECT id, name FROM zones ORDER BY name ASC"
25+
# period: ["day", "week", "month"]
26+
# status: {0: "Active", 1: "Archived"}
27+
28+
linked_columns:
29+
# user_id: "/admin/users/{value}"
30+
31+
smart_columns:
32+
# user_id: "SELECT id, name FROM users WHERE id IN {value}"
33+
34+
# create audits
35+
audit: true
36+
37+
# change the time zone
38+
# time_zone: "Pacific Time (US & Canada)"
39+
40+
# class name of the user model
41+
# user_class: User
42+
43+
# method name for the current user
44+
# user_method: current_user
45+
46+
# method name for the display name
47+
# user_name: name
48+
49+
# custom before_action to use for auth
50+
# before_action_method: require_admin
51+
52+
# email to send checks from
53+
# from_email: blazer@example.org
54+
55+
# webhook for Slack
56+
# slack_webhook_url: <%= ENV["BLAZER_SLACK_WEBHOOK_URL"] %>
57+
58+
check_schedules:
59+
- "1 day"
60+
- "1 hour"
61+
- "5 minutes"
62+
63+
# enable anomaly detection
64+
# note: with trend, time series are sent to https://trendapi.org
65+
# anomaly_checks: prophet / trend / anomaly_detection
66+
67+
# enable forecasting
68+
# note: with trend, time series are sent to https://trendapi.org
69+
# forecasting: prophet / trend
70+
71+
# enable map
72+
# mapbox_access_token: <%= ENV["MAPBOX_ACCESS_TOKEN"] %>
73+
74+
# enable uploads
75+
# uploads:
76+
# url: <%= ENV["BLAZER_UPLOADS_URL"] %>
77+
# schema: uploads
78+
# data_source: main

0 commit comments

Comments
 (0)