diff --git a/.ebextensions/00_setup_swap.config b/.ebextensions/00_setup_swap.config new file mode 100644 index 0000000..43ea924 --- /dev/null +++ b/.ebextensions/00_setup_swap.config @@ -0,0 +1,8 @@ +commands: + setup_swap: + test: test ! -e /var/swapfile + command: | + /bin/dd if=/dev/zero of=/var/swapfile bs=1M count=2048 + /bin/chmod 600 /var/swapfile + /sbin/mkswap /var/swapfile + /sbin/swapon /var/swapfile diff --git a/.ebextensions/01_set_vars.config b/.ebextensions/01_set_vars.config new file mode 100644 index 0000000..6c338ba --- /dev/null +++ b/.ebextensions/01_set_vars.config @@ -0,0 +1,6 @@ +commands: + set_env_vars: + command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' > /etc/profile.d/sh.local +packages: + yum: + jq: [] diff --git a/.ebextensions/02_install_yarn.config b/.ebextensions/02_install_yarn.config new file mode 100644 index 0000000..0800973 --- /dev/null +++ b/.ebextensions/02_install_yarn.config @@ -0,0 +1,7 @@ +commands: + install_yarn: + command: | + set -e + npm i -g yarn + ln -s "$(npm bin --global)"/yarn /usr/bin/yarn + test: "! yarn -v" diff --git a/.ebextensions/03_alb_default_process.config b/.ebextensions/03_alb_default_process.config new file mode 100644 index 0000000..104bfeb --- /dev/null +++ b/.ebextensions/03_alb_default_process.config @@ -0,0 +1,12 @@ +option_settings: + aws:elasticbeanstalk:environment:process:default: + DeregistrationDelay: '20' + HealthCheckInterval: '15' + HealthCheckPath: /okcomputer + HealthCheckTimeout: '5' + HealthyThresholdCount: '3' + UnhealthyThresholdCount: '5' + Port: '80' + Protocol: HTTP + StickinessEnabled: 'true' + StickinessLBCookieDuration: '43200' diff --git a/.ebextensions/04_update_bundler.config b/.ebextensions/04_update_bundler.config new file mode 100644 index 0000000..15d9707 --- /dev/null +++ b/.ebextensions/04_update_bundler.config @@ -0,0 +1,3 @@ +commands: + update_bundler: + command: /usr/bin/gem install bundler -v 2.5.3 diff --git a/.ruby-version b/.ruby-version index 03463f3..9e79f6c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.3.0 +ruby-3.2.2 diff --git a/Gemfile b/Gemfile index 65f4efd..9096f31 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.3.0' +ruby '3.2.2' gem 'rails', '~> 7.1', '>= 7.1.3' diff --git a/Gemfile.lock b/Gemfile.lock index 71ee7a6..474e2d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,11 @@ GEM globalid (1.2.1) activesupport (>= 6.1) google-protobuf (3.25.2) + google-protobuf (3.25.2-aarch64-linux) + google-protobuf (3.25.2-arm64-darwin) + google-protobuf (3.25.2-x86-linux) + google-protobuf (3.25.2-x86_64-darwin) + google-protobuf (3.25.2-x86_64-linux) hashie (5.0.0) honeybadger (5.4.1) httparty (0.21.0) @@ -692,7 +697,7 @@ DEPENDENCIES wicked_pdf (~> 2.7) RUBY VERSION - ruby 3.3.0p0 + ruby 3.2.2p53 BUNDLED WITH 2.5.3 diff --git a/README.md b/README.md index f23822d..0331a2e 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,13 @@ Things you may want to cover: * ... curl -v -X POST http://localhost:3001/api/users/sign_up -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"api_user": {"email":"api_user_example@test.com", "password":"123456", "password_confirmation":"123456"}}' + curl -v -X POST http://localhost:3001/api/users/sign_in -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"api_user": {"email":"api_user_example@test.com", "password":"123456"}}' + curl -v -X DELETE http://localhost:3001/api/users/sign_out -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' -curl -X GET 'localhost:3001/api/v1/users' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' -curl -X GET 'localhost:3001/api/v1/users/1' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' -curl -X GET 'localhost:3001/api/v1/current_user' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' +curl -X GET http://localhost:3001/api/v1/users -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' + +curl -X GET http://localhost:3001/api/v1/users/1 -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' + +curl -X GET http://localhost:3001/api/v1/current_user -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' diff --git a/app/controllers/api/v1/charts_controller.rb b/app/controllers/api/v1/charts_controller.rb new file mode 100644 index 0000000..2d5b696 --- /dev/null +++ b/app/controllers/api/v1/charts_controller.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Api + module V1 + class ChartsController < AuthenticatedApplicationController + def data + render json: { + target: 46, + current: 34, + baseline: 452.18, + targetTonnes: 300, + firstStage: 55, + firstStageVehicle: 27, + firstStagePropulsion: 33, + firstStageAvionics: 20, + firstStageThermal: 10, + firstStageAuxiliary: 10, + firstStageDesign: 32, + firstStageManufacture: 20, + firstStageTesting: 5, + firstStageFlight: 15, + firstStageEnd: 28, + secondStage: 26, + secondStageVehicle: 33, + secondStagePropulsion: 20, + secondStageAvionics: 27, + secondStageThermal: 15, + secondStageAuxiliary: 5, + secondStageDesign: 18, + secondStageManufacture: 42, + secondStageTesting: 17, + secondStageFlight: 3, + secondStageEnd: 20, + fairing: 19, + fairingStageVehicle: 21, + fairingStagePropulsion: 39, + fairingStageAvionics: 7, + fairingStageThermal: 20, + fairingStageAuxiliary: 13, + fairingStageDesign: 10, + fairingStageManufacture: 50, + fairingStageTesting: 5, + fairingStageFlight: 10, + fairingStageEnd: 25, + accuracy: 64 + }, status: :ok + end + end + end +end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2844433..d8eedc8 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -4,11 +4,11 @@ module Api module V1 class UsersController < AuthenticatedApplicationController def index - render json: User.all.order(:created_at).map { |user| serialize!(user) }, status: :ok + render json: ApiUser.all.order(:created_at).map { |user| serialize!(user) }, status: :ok end def show - render json: serialize!(User.find_by_id(params[:id])), status: :ok + render json: serialize!(ApiUser.find_by_id(params[:id])), status: :ok end def current_user diff --git a/config/environments/staging.rb b/config/environments/staging.rb index fa8a20d..3a8a9e8 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -49,7 +49,7 @@ # config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + config.force_ssl = false # Log to STDOUT by default config.logger = ActiveSupport::Logger.new(STDOUT) @@ -71,6 +71,8 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "rails_template_production" + Rails.application.routes.default_url_options[:host] = "#{ENV['URL_PROTOCOL']}://#{ENV['URL_HOST']}/" + config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = { host: ENV['URL_HOST'], diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 641dce9..693a0c5 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -379,6 +379,6 @@ ['DELETE', %r{^/api/users/sign_out$}] ] - jwt.expiration_time = 30.minutes.to_i + jwt.expiration_time = 600.minutes.to_i end end diff --git a/config/initializers/letter_opener.rb b/config/initializers/letter_opener.rb index a7099b1..f26ac00 100644 --- a/config/initializers/letter_opener.rb +++ b/config/initializers/letter_opener.rb @@ -1,19 +1,21 @@ # frozen_string_literal: true -require 'letter_opener' +if Rails.env.development? + require 'letter_opener' -LetterOpener.configure do |config| - # To overrider the location for message storage. - # Default value is `tmp/letter_opener` - # config.location = Rails.root.join('tmp', 'my_mails') + LetterOpener.configure do |config| + # To overrider the location for message storage. + # Default value is `tmp/letter_opener` + # config.location = Rails.root.join('tmp', 'my_mails') - # To render only the message body, without any metadata or extra containers or styling. - # Default value is `:default` that renders styled message with showing useful metadata. - config.message_template = :default + # To render only the message body, without any metadata or extra containers or styling. + # Default value is `:default` that renders styled message with showing useful metadata. + config.message_template = :default - # To change default file URI scheme you can provide `file_uri_scheme` config. - # It might be useful when you use WSL (Windows Subsystem for Linux) and default - # scheme doesn't work for you. - # Default value is blank - # config.file_uri_scheme = 'file://///wsl$/Ubuntu-18.04' + # To change default file URI scheme you can provide `file_uri_scheme` config. + # It might be useful when you use WSL (Windows Subsystem for Linux) and default + # scheme doesn't work for you. + # Default value is blank + # config.file_uri_scheme = 'file://///wsl$/Ubuntu-18.04' + end end diff --git a/config/routes.rb b/config/routes.rb index 34d95fd..0662aa6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,6 +54,8 @@ defaults format: :json do resources :users, only: %i(index show) get '/current_user', to: 'users#current_user' + + get '/charts_data', to: 'charts#data' end end end