Skip to content

Commit

Permalink
Replace AMS with jbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
chvp committed Nov 9, 2024
1 parent 33312f9 commit e44b95e
Show file tree
Hide file tree
Showing 90 changed files with 293 additions and 628 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ gem 'rails', '~> 7.2'
gem 'pg', '>= 1.2.3', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 6.4'
# Use ActiveModelSerializer for serializing to JSON
gem 'active_model_serializers', '~> 0.10'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.13'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1'

Expand Down
13 changes: 4 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
active_model_serializers (0.10.14)
actionpack (>= 4.1)
activemodel (>= 4.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (7.2.2)
activesupport (= 7.2.2)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -88,8 +83,6 @@ GEM
brakeman (6.2.2)
racc
builder (3.3.0)
case_transform (0.2)
activesupport
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
Expand Down Expand Up @@ -134,8 +127,10 @@ GEM
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.7.5)
jsonapi-renderer (0.2.2)
language_server-protocol (3.17.0.3)
logger (1.6.1)
loofah (2.23.1)
Expand Down Expand Up @@ -290,7 +285,6 @@ PLATFORMS
ruby

DEPENDENCIES
active_model_serializers (~> 0.10)
annotaterb (~> 4.13)
bcrypt (~> 3.1)
bootsnap (~> 1.18.4)
Expand All @@ -301,6 +295,7 @@ DEPENDENCIES
good_job (~> 4.4)
has_scope (~> 0.8)
image_processing (~> 1.13.0)
jbuilder (~> 2.13)
mocha (~> 2.5.0)
pg (>= 1.2.3, < 2.0)
puma (~> 6.4)
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,24 @@ def index
.includes(:album_artists, :album_labels, image: [{ image_attachment: :blob }, :image_type])
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@albums)
render json: @albums
end

def show
render json: @album
end
def show; end

def create
authorize Album
@album = Album.new(transformed_attributes)

if @album.save
render json: @album, status: :created
render :show, status: :created
else
render json: @album.errors, status: :unprocessable_entity
end
end

def update
if @album.update(transformed_attributes)
render json: @album, status: :ok
render :show, status: :ok
else
render json: @album.errors, status: :unprocessable_entity
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ApplicationController < ActionController::API

attr_accessor :current_user

helper_method :current_user

before_action :authenticate_from_token
after_action :verify_authorized
# rubocop:disable Rails/LexicallyScopedActionFilter
Expand All @@ -16,8 +18,6 @@ class ApplicationController < ActionController::API

has_scope :sorted, default: nil, allow_blank: true, except: :stats

serialization_scope :url_options

protected

def add_pagination_headers(collection)
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/artists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,24 @@ def index
.includes(image: [{ image_attachment: :blob }, :image_type])
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@artists)
render json: @artists
end

def show
render json: @artist
end
def show; end

def create
authorize Artist
@artist = Artist.new(transformed_attributes)

if @artist.save
render json: @artist, status: :created
render :show, status: :created
else
render json: @artist.errors, status: :unprocessable_entity
end
end

def update
if @artist.update(transformed_attributes)
render json: @artist, status: :ok
render :show, status: :ok
else
render json: @artist.errors, status: :unprocessable_entity
end
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/auth_tokens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@auth_tokens)
render json: @auth_tokens
end

def show
render json: @auth_token
end
def show; end

def create
authorize AuthToken
Expand All @@ -31,7 +28,7 @@ def create
)

if @auth_token.save
render json: @auth_token, serializer: AuthTokenWithSecretSerializer, status: :created
render :create, status: :created
else
render json: @auth_token.errors, status: :unprocessable_entity
end
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/codec_conversions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,24 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@codec_conversions)
render json: @codec_conversions
end

def show
render json: @codec_conversion
end
def show; end

def create
authorize CodecConversion
@codec_conversion = CodecConversion.new(permitted_attributes(CodecConversion))

if @codec_conversion.save
render json: @codec_conversion, status: :created
render :show, status: :created
else
render json: @codec_conversion.errors, status: :unprocessable_entity
end
end

def update
if @codec_conversion.update(permitted_attributes(CodecConversion))
render json: @codec_conversion, status: :ok
render :show, status: :ok
else
render json: @codec_conversion.errors, status: :unprocessable_entity
end
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/codecs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@codecs)
render json: @codecs
end

def show
render json: @codec
end
def show; end

def create
authorize Codec
@codec = Codec.new(permitted_attributes(Codec))

if @codec.save
render json: @codec, status: :created
render :show, status: :created
else
render json: @codec.errors, status: :unprocessable_entity
end
end

def update
if @codec.update(permitted_attributes(@codec))
render json: @codec, status: :ok
render :show, status: :ok
else
render json: @codec.errors, status: :unprocessable_entity
end
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/cover_filenames_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@cover_filenames)
render json: @cover_filenames
end

def show
render json: @cover_filename
end
def show; end

def create
authorize CoverFilename
@cover_filename = CoverFilename.new(permitted_attributes(CoverFilename))

if @cover_filename.save
render json: @cover_filename, status: :created
render :show, status: :created
else
render json: @cover_filename.errors, status: :unprocessable_entity
end
Expand Down
11 changes: 4 additions & 7 deletions app/controllers/genres_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@genres)
render json: @genres
end

def show
render json: @genre
end
def show; end

def create
authorize Genre
@genre = Genre.new(permitted_attributes(Genre))

if @genre.save
render json: @genre, status: :created
render :show, status: :created
else
render json: @genre.errors, status: :unprocessable_entity
end
end

def update
if @genre.update(permitted_attributes(@genre))
render json: @genre, status: :ok
render :show, status: :ok
else
render json: @genre.errors, status: :unprocessable_entity
end
Expand All @@ -45,7 +42,7 @@ def destroy_empty
def merge
@genre.merge(Genre.find(params[:source_id]))
# We don't do error handling here. The merge action isn't supposed to fail.
render json: @genre, status: :ok
render :show, status: :ok
end

private
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/image_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@image_types)
render json: @image_types
end

def show
render json: @image_type
end
def show; end

def create
authorize ImageType
@image_type = ImageType.new(permitted_attributes(ImageType))

if @image_type.save
render json: @image_type, status: :created
render :show, status: :created
else
render json: @image_type.errors, status: :unprocessable_entity
end
end

def update
if @image_type.update(permitted_attributes(@image_type))
render json: @image_type, status: :ok
render :show, status: :ok
else
render json: @image_type.errors, status: :unprocessable_entity
end
Expand Down
11 changes: 4 additions & 7 deletions app/controllers/labels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@labels)
render json: @labels
end

def show
render json: @label
end
def show; end

def create
authorize Label
@label = Label.new(permitted_attributes(Label))

if @label.save
render json: @label, status: :created
render :show, status: :created
else
render json: @label.errors, status: :unprocessable_entity
end
end

def update
if @label.update(permitted_attributes(@label))
render json: @label, status: :ok
render :show, status: :ok
else
render json: @label.errors, status: :unprocessable_entity
end
Expand All @@ -45,7 +42,7 @@ def destroy_empty
def merge
@label.merge(Label.find(params[:source_id]))
# We don't do error handling here. The merge action isn't supposed to fail.
render json: @label, status: :ok
render :show, status: :ok
end

private
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ def index
.order(id: :asc)
.paginate(page: params[:page], per_page: params[:per_page])
add_pagination_headers(@locations)
render json: @locations
end

def show
render json: @location
end
def show; end

def create
authorize Location
@location = Location.new(permitted_attributes(Location))

if @location.save
render json: @location, status: :created
render :show, status: :created
else
render json: @location.errors, status: :unprocessable_entity
end
Expand Down
Loading

0 comments on commit e44b95e

Please sign in to comment.