Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.1'
ruby '3.1.2'

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'rails', '~> 7.0.3'
Expand Down Expand Up @@ -41,6 +41,7 @@ gem 'rack-cors'
gem 'devise'
gem 'devise-jwt'
gem 'fast_jsonapi'
gem 'sprockets-rails'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ GEM
net-protocol
timeout
nio4r (2.5.8)
nokogiri (1.13.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.6-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
Expand Down Expand Up @@ -227,6 +229,13 @@ GEM
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
ruby-progressbar (1.11.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
strscan (3.0.3)
thor (1.2.1)
timeout (0.3.0)
Expand All @@ -246,6 +255,7 @@ GEM
zeitwerk (2.6.0)

PLATFORMS
arm64-darwin-22
x86_64-linux

DEPENDENCIES
Expand All @@ -263,10 +273,11 @@ DEPENDENCIES
rails (~> 7.0.3)
rspec-rails
rubocop-rails
sprockets-rails
tzinfo-data

RUBY VERSION
ruby 3.1.1p18
ruby 3.1.2p20

BUNDLED WITH
2.3.7
Empty file added app/assets/config/manifest.js
Empty file.
8 changes: 6 additions & 2 deletions app/controllers/api/v1/list_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def create
end
end

def edit
@list_item = ListItem.find(params[:id])
end
Comment on lines +35 to +37
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the edit endpoint? Rails already has a show endpoint by default right?

GET /list_item/:id


def update
@list_item = ListItem.find(params[:id])
if @list_item.update(list_item_params)
render json: @list_item
else
Expand All @@ -54,7 +59,6 @@ def set_list_item
end

def list_item_params
params.require(:list_item).permit(:id, :book_id, :user_id, :rating, :notes, :start_date, :finish_date,
:created_at, :updated_at)
params.require(:list_item).permit(:id, :book_id, :user_id, :rating, :notes, :start_date, :finish_date, :created_at, :updated_at)
end
end
15 changes: 4 additions & 11 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ def respond_with(resource, _opts = {})
end

def respond_to_on_destroy
if current_user
render json: {
status: 200,
message: 'logged out successfully'
}, status: :ok
else
render json: {
status: 401,
message: "Couldn't find an active session."
}, status: :unauthorized
end
render json: {
status: 200,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to include the status in the json object? Wouldn't HTTP status 200 already be enough for the frontend to know that it is successful?

message: 'logged out successfully'
}, status: :ok
end
# before_action :configure_sign_in_params, only: [:create]

Expand Down
2 changes: 1 addition & 1 deletion app/models/list_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ class ListItem < ApplicationRecord

validates :book_id, presence: true
validates :user_id, presence: true
validates :rating, presence: true, numericality: { in: 1..5 }
validates :rating, presence: true, numericality: { in: 0..5 }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

can make use of greater_than and less_than, instead of making rails iterate over a range of values. A bit more performant. But again , this is a nit. Performance is negligible

end
6 changes: 6 additions & 0 deletions bin/render-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#/usr/bin/env bash# exit on error
set -o errexit

bundle install
bundle exec rails assets:precompile
bundle exec rails assets:clean
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative 'boot'

require 'rails/all'
require 'sprockets/railtie'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uxkWVScNcve1FirRzfI5llo6u5plSZaRzKwS2we1qCtiG8LBhE9A0q2aT7Fh+OkxPdqg/ycfNrLlXhHWdLZkXG8+kNnnyGbiS66lBUPJmspR9PI0q/I6ukC1W2LM4QxVC7HDGXv1RIzUMwq6LuahLbRSqQcVMBfdtUGWRw1e6PoAlBxW1L7HKnn76SaK3oMg19WNUZwcrkr2vdnLEvrkDBt3Xo0loDXg6PyQypGWUYFEJafDwtGEtEEhXVwxBkVQJmfoRvFr3jn8yp19c8fSzqGsVrHwN8RFhQApQFmvgpj0RxGvpz2xuB2DYUFFkh+7SwY2k5alNm8yjtQW919Mel1RViT/hNYPDGVilPLGDi3gMz/HFdNUbMdJvju31bA6271ZGheUqbcqMe9wkbjjJSdbDeiGVwVHl3Wt--1WJLuUAYx4FK//Sd--YfppxPSj1PolgCC0o2r23Q==
XkmYIxn7/p5YvPqWn64w1UrKz2aAMyEITFovMBeAghv+sqKVytVci3FqOfEuyXkVS1HGPM+jGfMd3eDx5dxTvW0T2LtSliuFTjw1vePziHJq7Eo7qgFrp1TGhgSdJZUjGiBJylsp5y8lvPHd+zHVYoS9xygt4++WOWvUI4mghtYT7NkCNd8GRjZkalcbWkUSbqoZnf+ARqJeJIRTwpxHvbOWD8qo7aTijUQRF+dMjT58gQpelgDHSJF1ISstnoes8MMsky6lW0c7IYZUtofsmLBS2ZlDuKWsXV9Ai5mevIDmUG64FRFTnZp7WxKadvIEU25/BvyT/qWRcOb7TmFm7db0EPwAwHdjkoEQng9r71yVgLIxMjfWlF3vsU2r1lyuZBvPOAEaPKVE5OPaY6wv7V66vCJqy7rTvBD4--a083M/Ot7evGs44m--ncBopitz5lfsX0ntiZ2v2Q==
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
get '/finished_books' => 'list_items#finished_books'
post '/list_item' => 'list_items#show'
post '/add_list_item' => 'list_items#create'
# post '/add_list_item' => 'list_items#add_list_item'
post '/edit_list_item' => 'list_items#update'
get '/list_item/:id/edit' => 'list_items#edit'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you can also make use of resources :list_item - https://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default

patch '/list_item/:id' => 'list_items#update'

delete '/list_item' => 'list_items#destroy'

get '/books' => 'books#index'
Expand Down
13 changes: 13 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
databases:
- name: mysite
databaseName: mysite user: mysite plan: free
services:
- type: web name: mysite runtime: ruby plan: free buildCommand: "./bin/render-build.sh"
# preDeployCommand: "bundle exec rails db:migrate" # preDeployCommand only available on paid instance types
startCommand: "bundle exec rails server" envars:
- key: DATABASE_URL fromDatabase:
name: mysite
property: connectionString
- key: RAILS_MASTER_KEY
sync: false- key: WEB_CONCURRENCY
value: 2 # sensible default