From e44b95e4e83e9faef276b7651d57c721378747b8 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Sat, 9 Nov 2024 15:24:05 +0100 Subject: [PATCH] Replace AMS with jbuilder --- Gemfile | 4 +- Gemfile.lock | 13 ++-- app/controllers/albums_controller.rb | 9 +-- app/controllers/application_controller.rb | 4 +- app/controllers/artists_controller.rb | 9 +-- app/controllers/auth_tokens_controller.rb | 7 +- .../codec_conversions_controller.rb | 9 +-- app/controllers/codecs_controller.rb | 9 +-- app/controllers/cover_filenames_controller.rb | 7 +- app/controllers/genres_controller.rb | 11 ++- app/controllers/image_types_controller.rb | 9 +-- app/controllers/labels_controller.rb | 11 ++- app/controllers/locations_controller.rb | 7 +- app/controllers/playlists_controller.rb | 9 +-- app/controllers/plays_controller.rb | 6 +- app/controllers/rescans_controller.rb | 7 +- app/controllers/tracks_controller.rb | 16 ++--- app/controllers/users_controller.rb | 9 +-- app/helpers/albums_helper.rb | 21 ++++++ app/helpers/application_helper.rb | 2 + app/helpers/artists_helper.rb | 11 +++ app/helpers/auth_tokens_helper.rb | 11 +++ app/helpers/codec_conversions_helper.rb | 5 ++ app/helpers/codecs_helper.rb | 5 ++ app/helpers/cover_filenames_helper.rb | 5 ++ app/helpers/genres_helper.rb | 5 ++ app/helpers/image_types_helper.rb | 5 ++ app/helpers/images_helper.rb | 36 ++++++++++ app/helpers/labels_helper.rb | 5 ++ app/helpers/locations_helper.rb | 5 ++ app/helpers/playlists_helper.rb | 5 ++ app/helpers/plays_helper.rb | 9 +++ app/helpers/rescans_helper.rb | 5 ++ app/helpers/tracks_helper.rb | 50 ++++++++++++++ app/helpers/users_helper.rb | 5 ++ app/serializers/album_artist_serializer.rb | 27 -------- app/serializers/album_label_serializer.rb | 23 ------- app/serializers/album_serializer.rb | 67 ------------------- app/serializers/artist_serializer.rb | 61 ----------------- app/serializers/auth_token_serializer.rb | 23 ------- .../auth_token_with_secret_serializer.rb | 3 - .../codec_conversion_serializer.rb | 21 ------ app/serializers/codec_serializer.rb | 15 ----- app/serializers/cover_filename_serializer.rb | 14 ---- app/serializers/genre_serializer.rb | 16 ----- app/serializers/image_type_serializer.rb | 15 ----- app/serializers/label_serializer.rb | 15 ----- app/serializers/location_serializer.rb | 14 ---- app/serializers/play_serializer.rb | 23 ------- app/serializers/play_stat_serializer.rb | 3 - app/serializers/playlist_serializer.rb | 24 ------- app/serializers/rescan_runner_serializer.rb | 23 ------- app/serializers/track_artist_serializer.rb | 28 -------- app/serializers/track_moderator_serializer.rb | 15 ----- app/serializers/track_serializer.rb | 46 ------------- app/serializers/user_serializer.rb | 16 ----- app/views/albums/index.json.jbuilder | 1 + app/views/albums/show.json.jbuilder | 1 + app/views/artists/index.json.jbuilder | 1 + app/views/artists/show.json.jbuilder | 1 + app/views/auth_tokens/create.json.jbuilder | 1 + app/views/auth_tokens/index.json.jbuilder | 1 + app/views/auth_tokens/show.json.jbuilder | 1 + .../codec_conversions/index.json.jbuilder | 1 + .../codec_conversions/show.json.jbuilder | 1 + app/views/codecs/index.json.jbuilder | 1 + app/views/codecs/show.json.jbuilder | 1 + app/views/cover_filenames/index.json.jbuilder | 1 + app/views/cover_filenames/show.json.jbuilder | 1 + app/views/genres/index.json.jbuilder | 1 + app/views/genres/show.json.jbuilder | 1 + app/views/image_types/index.json.jbuilder | 1 + app/views/image_types/show.json.jbuilder | 1 + app/views/labels/index.json.jbuilder | 1 + app/views/labels/show.json.jbuilder | 1 + app/views/locations/index.json.jbuilder | 1 + app/views/locations/show.json.jbuilder | 1 + app/views/playlists/index.json.jbuilder | 1 + app/views/playlists/show.json.jbuilder | 1 + app/views/plays/index.json.jbuilder | 1 + app/views/plays/show.json.jbuilder | 1 + app/views/plays/stats.json.jbuilder | 1 + app/views/rescans/index.json.jbuilder | 1 + app/views/rescans/show.json.jbuilder | 1 + app/views/tracks/index.json.jbuilder | 5 ++ app/views/tracks/show.json.jbuilder | 5 ++ app/views/users/index.json.jbuilder | 1 + app/views/users/show.json.jbuilder | 1 + config/application.rb | 4 ++ gemset.nix | 39 +++-------- 90 files changed, 293 insertions(+), 628 deletions(-) create mode 100644 app/helpers/albums_helper.rb create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/artists_helper.rb create mode 100644 app/helpers/auth_tokens_helper.rb create mode 100644 app/helpers/codec_conversions_helper.rb create mode 100644 app/helpers/codecs_helper.rb create mode 100644 app/helpers/cover_filenames_helper.rb create mode 100644 app/helpers/genres_helper.rb create mode 100644 app/helpers/image_types_helper.rb create mode 100644 app/helpers/images_helper.rb create mode 100644 app/helpers/labels_helper.rb create mode 100644 app/helpers/locations_helper.rb create mode 100644 app/helpers/playlists_helper.rb create mode 100644 app/helpers/plays_helper.rb create mode 100644 app/helpers/rescans_helper.rb create mode 100644 app/helpers/tracks_helper.rb create mode 100644 app/helpers/users_helper.rb delete mode 100644 app/serializers/album_artist_serializer.rb delete mode 100644 app/serializers/album_label_serializer.rb delete mode 100644 app/serializers/album_serializer.rb delete mode 100644 app/serializers/artist_serializer.rb delete mode 100644 app/serializers/auth_token_serializer.rb delete mode 100644 app/serializers/auth_token_with_secret_serializer.rb delete mode 100644 app/serializers/codec_conversion_serializer.rb delete mode 100644 app/serializers/codec_serializer.rb delete mode 100644 app/serializers/cover_filename_serializer.rb delete mode 100644 app/serializers/genre_serializer.rb delete mode 100644 app/serializers/image_type_serializer.rb delete mode 100644 app/serializers/label_serializer.rb delete mode 100644 app/serializers/location_serializer.rb delete mode 100644 app/serializers/play_serializer.rb delete mode 100644 app/serializers/play_stat_serializer.rb delete mode 100644 app/serializers/playlist_serializer.rb delete mode 100644 app/serializers/rescan_runner_serializer.rb delete mode 100644 app/serializers/track_artist_serializer.rb delete mode 100644 app/serializers/track_moderator_serializer.rb delete mode 100644 app/serializers/track_serializer.rb delete mode 100644 app/serializers/user_serializer.rb create mode 100644 app/views/albums/index.json.jbuilder create mode 100644 app/views/albums/show.json.jbuilder create mode 100644 app/views/artists/index.json.jbuilder create mode 100644 app/views/artists/show.json.jbuilder create mode 100644 app/views/auth_tokens/create.json.jbuilder create mode 100644 app/views/auth_tokens/index.json.jbuilder create mode 100644 app/views/auth_tokens/show.json.jbuilder create mode 100644 app/views/codec_conversions/index.json.jbuilder create mode 100644 app/views/codec_conversions/show.json.jbuilder create mode 100644 app/views/codecs/index.json.jbuilder create mode 100644 app/views/codecs/show.json.jbuilder create mode 100644 app/views/cover_filenames/index.json.jbuilder create mode 100644 app/views/cover_filenames/show.json.jbuilder create mode 100644 app/views/genres/index.json.jbuilder create mode 100644 app/views/genres/show.json.jbuilder create mode 100644 app/views/image_types/index.json.jbuilder create mode 100644 app/views/image_types/show.json.jbuilder create mode 100644 app/views/labels/index.json.jbuilder create mode 100644 app/views/labels/show.json.jbuilder create mode 100644 app/views/locations/index.json.jbuilder create mode 100644 app/views/locations/show.json.jbuilder create mode 100644 app/views/playlists/index.json.jbuilder create mode 100644 app/views/playlists/show.json.jbuilder create mode 100644 app/views/plays/index.json.jbuilder create mode 100644 app/views/plays/show.json.jbuilder create mode 100644 app/views/plays/stats.json.jbuilder create mode 100644 app/views/rescans/index.json.jbuilder create mode 100644 app/views/rescans/show.json.jbuilder create mode 100644 app/views/tracks/index.json.jbuilder create mode 100644 app/views/tracks/show.json.jbuilder create mode 100644 app/views/users/index.json.jbuilder create mode 100644 app/views/users/show.json.jbuilder diff --git a/Gemfile b/Gemfile index 6a21b4ba..adb3ef76 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 2b567f7d..0cf7acd8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -290,7 +285,6 @@ PLATFORMS ruby DEPENDENCIES - active_model_serializers (~> 0.10) annotaterb (~> 4.13) bcrypt (~> 3.1) bootsnap (~> 1.18.4) @@ -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) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index d77f5a3d..695376ee 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -12,19 +12,16 @@ 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 @@ -32,7 +29,7 @@ def create 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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0f0dab5e..cd20ed16 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 @@ -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) diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 7a1911fa..4285886d 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -9,19 +9,16 @@ 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 @@ -29,7 +26,7 @@ def create 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 diff --git a/app/controllers/auth_tokens_controller.rb b/app/controllers/auth_tokens_controller.rb index 393bb0aa..8937e0d7 100644 --- a/app/controllers/auth_tokens_controller.rb +++ b/app/controllers/auth_tokens_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/codec_conversions_controller.rb b/app/controllers/codec_conversions_controller.rb index 7ae9369a..6a542910 100644 --- a/app/controllers/codec_conversions_controller.rb +++ b/app/controllers/codec_conversions_controller.rb @@ -9,19 +9,16 @@ 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 @@ -29,7 +26,7 @@ def create 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 diff --git a/app/controllers/codecs_controller.rb b/app/controllers/codecs_controller.rb index 6010a3be..36a39c63 100644 --- a/app/controllers/codecs_controller.rb +++ b/app/controllers/codecs_controller.rb @@ -7,19 +7,16 @@ 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 @@ -27,7 +24,7 @@ def create 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 diff --git a/app/controllers/cover_filenames_controller.rb b/app/controllers/cover_filenames_controller.rb index 0d1eb603..5ae1247e 100644 --- a/app/controllers/cover_filenames_controller.rb +++ b/app/controllers/cover_filenames_controller.rb @@ -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 diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb index ac14122a..4b427b46 100644 --- a/app/controllers/genres_controller.rb +++ b/app/controllers/genres_controller.rb @@ -7,19 +7,16 @@ 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 @@ -27,7 +24,7 @@ def create 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 @@ -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 diff --git a/app/controllers/image_types_controller.rb b/app/controllers/image_types_controller.rb index 34e33500..52ef4bf4 100644 --- a/app/controllers/image_types_controller.rb +++ b/app/controllers/image_types_controller.rb @@ -7,19 +7,16 @@ 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 @@ -27,7 +24,7 @@ def create 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 diff --git a/app/controllers/labels_controller.rb b/app/controllers/labels_controller.rb index ce757c9b..5b1de3d8 100644 --- a/app/controllers/labels_controller.rb +++ b/app/controllers/labels_controller.rb @@ -7,19 +7,16 @@ 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 @@ -27,7 +24,7 @@ def create 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 @@ -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 diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index fc22533e..6cdd36cf 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -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 diff --git a/app/controllers/playlists_controller.rb b/app/controllers/playlists_controller.rb index 921acff8..08f2f393 100644 --- a/app/controllers/playlists_controller.rb +++ b/app/controllers/playlists_controller.rb @@ -8,19 +8,16 @@ def index .order(id: :asc) .paginate(page: params[:page], per_page: params[:per_page]) add_pagination_headers(@playlists) - render json: @playlists end - def show - render json: @playlist - end + def show; end def create authorize Playlist @playlist = Playlist.new(permitted_attributes(Playlist).merge({ user: current_user })) if @playlist.save - render json: @playlist, status: :created + render :show, status: :created else render json: @playlist.errors, status: :unprocessable_entity end @@ -28,7 +25,7 @@ def create def update if @playlist.update(permitted_attributes(@playlist)) - render json: @playlist, status: :ok + render :show, status: :ok else render json: @playlist.errors, status: :unprocessable_entity end diff --git a/app/controllers/plays_controller.rb b/app/controllers/plays_controller.rb index 1a74f7a4..0b8f76a4 100644 --- a/app/controllers/plays_controller.rb +++ b/app/controllers/plays_controller.rb @@ -9,8 +9,6 @@ def index @plays = apply_scopes(policy_scope(Play)) .paginate(page: params[:page], per_page: params[:per_page]) add_pagination_headers(@plays) - - render json: @plays, each_serializer: PlaySerializer end def create @@ -18,7 +16,7 @@ def create @play = Play.new(transformed_attributes) if @play.save - render json: @play, status: :created + render :show, status: :created else render json: @play.errors, status: :unprocessable_entity end @@ -33,8 +31,6 @@ def stats .order(track_id: :desc) .paginate(page: params[:page], per_page: params[:per_page]) add_pagination_headers(@stats) - - render json: @stats, each_serializer: PlayStatSerializer end private diff --git a/app/controllers/rescans_controller.rb b/app/controllers/rescans_controller.rb index 2e40ac23..c6d77c99 100644 --- a/app/controllers/rescans_controller.rb +++ b/app/controllers/rescans_controller.rb @@ -5,16 +5,13 @@ def index authorize RescanRunner @rescans = policy_scope(RescanRunner).paginate(page: params[:page], per_page: params[:per_page]) add_pagination_headers(@rescans) - render json: @rescans end - def show - render json: @rescan - end + def show; end def start @rescan.schedule - render json: @rescan + render :show end def start_all diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index 81014019..1a691a17 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -14,20 +14,16 @@ def index .includes(:track_artists, :genres, audio_file: %i[location codec]) .paginate(page: params[:page], per_page: params[:per_page]) add_pagination_headers(@tracks) - - render json: @tracks, each_serializer: serializer end - def show - render json: @track, serializer: - end + def show; end def create authorize Track @track = Track.new(transformed_attributes) if @track.save - render(json: @track, serializer:, status: :created) + render :show, status: :created else render json: @track.errors, status: :unprocessable_entity end @@ -35,7 +31,7 @@ def create def update if @track.update(transformed_attributes) - render(json: @track, serializer:, status: :ok) + render :show, status: :ok else render json: @track.errors, status: :unprocessable_entity end @@ -81,7 +77,7 @@ def download def merge @track.merge(Track.find(params[:source_id])) # We don't do error handling here. The merge action isn't supposed to fail. - render json: @track, status: :ok + render :show, status: :ok end private @@ -130,10 +126,6 @@ def audio_with_stream(stream, mimetype, total_size) response.stream.close end - def serializer - current_user.moderator? ? TrackModeratorSerializer : TrackSerializer - end - def set_track @track = Track.find(params[:id]) authorize @track diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1c79d0ca..d5139e83 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -7,19 +7,16 @@ def index .order(id: :asc) .paginate(page: params[:page], per_page: params[:per_page]) add_pagination_headers(@users) - render json: @users end - def show - render json: @user - end + def show; end def create authorize User @user = User.new(permitted_attributes(User)) if @user.save - render json: @user, status: :created + render :show, status: :created else render json: @user.errors, status: :unprocessable_entity end @@ -35,7 +32,7 @@ def update end if @user.update(permitted_attributes(@user)) - render json: @user, status: :ok + render :show, status: :ok else render json: @user.errors, status: :unprocessable_entity end diff --git a/app/helpers/albums_helper.rb b/app/helpers/albums_helper.rb new file mode 100644 index 00000000..4b180457 --- /dev/null +++ b/app/helpers/albums_helper.rb @@ -0,0 +1,21 @@ +module AlbumsHelper + include ImagesHelper + + def transform_album_for_json(album) + result = %i[id title normalized_title release review_comment edition edition_description created_at updated_at].index_with { |it| album.send(it) } + %i[image image100 image250 image500 image_type].each do |attr| + result[attr] = send(attr, album) + end + result[:album_artists] = album.album_artists.map { |it| transform_album_artist_for_json(it) } + result[:album_labels] = album.album_labels.map { |it| transform_album_label_for_json(it) } + result + end + + def transform_album_artist_for_json(album_artist) + %i[artist_id name normalized_name order separator].index_with { |attr| album_artist.send(attr) } + end + + def transform_album_label_for_json(album_label) + %i[label_id catalogue_number].index_with { |attr| album_label.send(attr) } + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 00000000..de6be794 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/artists_helper.rb b/app/helpers/artists_helper.rb new file mode 100644 index 00000000..3c6ab159 --- /dev/null +++ b/app/helpers/artists_helper.rb @@ -0,0 +1,11 @@ +module ArtistsHelper + include ImagesHelper + + def transform_artist_for_json(artist) + result = %i[id name normalized_name review_comment created_at updated_at].index_with { |it| artist.send(it) } + %i[image image100 image250 image500 image_type].each do |attr| + result[attr] = send(attr, artist) + end + result + end +end diff --git a/app/helpers/auth_tokens_helper.rb b/app/helpers/auth_tokens_helper.rb new file mode 100644 index 00000000..65dd77cb --- /dev/null +++ b/app/helpers/auth_tokens_helper.rb @@ -0,0 +1,11 @@ +module AuthTokensHelper + def transform_auth_token_for_json(auth_token) + %i[id device_id user_id user_agent application].index_with { |it| auth_token.send(it) } + end + + def transform_auth_token_for_json_with_secret(auth_token) + result = transform_auth_token_for_json(auth_token) + result[:secret] = auth_token.secret + result + end +end diff --git a/app/helpers/codec_conversions_helper.rb b/app/helpers/codec_conversions_helper.rb new file mode 100644 index 00000000..05b62aba --- /dev/null +++ b/app/helpers/codec_conversions_helper.rb @@ -0,0 +1,5 @@ +module CodecConversionsHelper + def transform_codec_conversion_for_json(codec_conversion) + %i[id name ffmpeg_params resulting_codec_id].index_with { |it| codec_conversion.send(it) } + end +end diff --git a/app/helpers/codecs_helper.rb b/app/helpers/codecs_helper.rb new file mode 100644 index 00000000..34d7a215 --- /dev/null +++ b/app/helpers/codecs_helper.rb @@ -0,0 +1,5 @@ +module CodecsHelper + def transform_codec_for_json(codec) + %i[id mimetype extension].index_with { |it| codec.send(it) } + end +end diff --git a/app/helpers/cover_filenames_helper.rb b/app/helpers/cover_filenames_helper.rb new file mode 100644 index 00000000..8f4808c0 --- /dev/null +++ b/app/helpers/cover_filenames_helper.rb @@ -0,0 +1,5 @@ +module CoverFilenamesHelper + def transform_cover_filename_for_json(cover_filename) + %i[id filename].index_with { |it| cover_filename.send(it) } + end +end diff --git a/app/helpers/genres_helper.rb b/app/helpers/genres_helper.rb new file mode 100644 index 00000000..f559ff31 --- /dev/null +++ b/app/helpers/genres_helper.rb @@ -0,0 +1,5 @@ +module GenresHelper + def transform_genre_for_json(genre) + %i[id name normalized_name].index_with { |it| genre.send(it) } + end +end diff --git a/app/helpers/image_types_helper.rb b/app/helpers/image_types_helper.rb new file mode 100644 index 00000000..e0869fb0 --- /dev/null +++ b/app/helpers/image_types_helper.rb @@ -0,0 +1,5 @@ +module ImageTypesHelper + def transform_image_type_for_json(image_type) + %i[id extension mimetype].index_with { |it| image_type.send(it) } + end +end diff --git a/app/helpers/images_helper.rb b/app/helpers/images_helper.rb new file mode 100644 index 00000000..c32bcef2 --- /dev/null +++ b/app/helpers/images_helper.rb @@ -0,0 +1,36 @@ +module ImagesHelper + def image(object) + return nil if object.image.blank? + return nil unless object.image.image.variable? + + rails_blob_url(object.image.image) + end + + def image100(object) + return nil if object.image.blank? + return nil unless object.image.image.variable? + + rails_representation_url(object.image.image.variant(resize_to_cover: [100, 100])) + end + + def image250(object) + return nil if object.image.blank? + return nil unless object.image.image.variable? + + rails_representation_url(object.image.image.variant(resize_to_cover: [250, 250])) + end + + def image500(object) + return nil if object.image.blank? + return nil unless object.image.image.variable? + + rails_representation_url(object.image.image.variant(resize_to_cover: [500, 500])) + end + + def image_type(object) + return nil if object.image.blank? + return nil unless object.image.image.variable? + + object.image.image_type.mimetype + end +end diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb new file mode 100644 index 00000000..56963000 --- /dev/null +++ b/app/helpers/labels_helper.rb @@ -0,0 +1,5 @@ +module LabelsHelper + def transform_label_for_json(label) + %i[id name normalized_name].index_with { |it| label.send(it) } + end +end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb new file mode 100644 index 00000000..0a3d7c22 --- /dev/null +++ b/app/helpers/locations_helper.rb @@ -0,0 +1,5 @@ +module LocationsHelper + def transform_location_for_json(location) + %i[id path].index_with { |it| location.send(it) } + end +end diff --git a/app/helpers/playlists_helper.rb b/app/helpers/playlists_helper.rb new file mode 100644 index 00000000..7283718f --- /dev/null +++ b/app/helpers/playlists_helper.rb @@ -0,0 +1,5 @@ +module PlaylistsHelper + def transform_playlist_for_json(playlist) + %i[id name description user_id playlist_type created_at updated_at item_ids access].index_with { |it| playlist.send(it) } + end +end diff --git a/app/helpers/plays_helper.rb b/app/helpers/plays_helper.rb new file mode 100644 index 00000000..62a7b10a --- /dev/null +++ b/app/helpers/plays_helper.rb @@ -0,0 +1,9 @@ +module PlaysHelper + def transform_play_for_json(play) + %i[id played_at track_id user_id].index_with { |it| play.send(it) } + end + + def transform_play_stat_for_json(play_stat) + %i[count track_id last_played_at total_length].index_with { |it| play_stat.send(it) } + end +end diff --git a/app/helpers/rescans_helper.rb b/app/helpers/rescans_helper.rb new file mode 100644 index 00000000..ccdeef2b --- /dev/null +++ b/app/helpers/rescans_helper.rb @@ -0,0 +1,5 @@ +module RescansHelper + def transform_rescan_runner_for_json(rescan_runner) + %i[id error_text warning_text processed running finished_at location_id].index_with { |it| rescan_runner.send(it) } + end +end diff --git a/app/helpers/tracks_helper.rb b/app/helpers/tracks_helper.rb new file mode 100644 index 00000000..d255540f --- /dev/null +++ b/app/helpers/tracks_helper.rb @@ -0,0 +1,50 @@ +module TracksHelper + def transform_track_for_json(track) + result = %i[id title normalized_title number album_id review_comment created_at updated_at genre_ids audio_file_id].index_with { |it| track.send(it) } + %i[codec_id length bitrate location_id].each do |attr| + result[attr] = send(attr, track) + end + result[:track_artists] = track.track_artists.map { |it| transform_track_artist_for_json(it) } + result + end + + def transform_track_artist_for_json(track_artist) + %i[artist_id name normalized_name role order hidden].index_with { |it| track_artist.send(it) } + end + + def transform_track_for_json_for_moderator(track) + result = transform_track_for_json(track) + %i[filename sample_rate bit_depth].each do |attr| + result[attr] = send(attr, track) + end + result + end + + def codec_id(track) + track.audio_file&.codec_id + end + + def length(track) + track.audio_file&.length + end + + def bitrate(track) + track.audio_file&.bitrate + end + + def location_id(track) + track.audio_file&.location_id + end + + def filename(track) + track.audio_file&.filename + end + + def sample_rate(track) + track.audio_file&.sample_rate + end + + def bit_depth(track) + track.audio_file&.bit_depth + end +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 00000000..d02f1510 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,5 @@ +module UsersHelper + def transform_user_for_json(user) + %i[id name permission].index_with { |it| user.send(it) } + end +end diff --git a/app/serializers/album_artist_serializer.rb b/app/serializers/album_artist_serializer.rb deleted file mode 100644 index fcd4e5fb..00000000 --- a/app/serializers/album_artist_serializer.rb +++ /dev/null @@ -1,27 +0,0 @@ -# == Schema Information -# -# Table name: album_artists -# -# id :bigint not null, primary key -# name :string not null -# normalized_name :string not null -# order :integer not null -# separator :string -# album_id :bigint not null -# artist_id :bigint not null -# -# Indexes -# -# index_album_artists_on_album_id (album_id) -# index_album_artists_on_album_id_and_artist_id_and_name (album_id,artist_id,name) UNIQUE -# index_album_artists_on_artist_id (artist_id) -# index_album_artists_on_normalized_name (normalized_name) -# -# Foreign Keys -# -# fk_rails_... (album_id => albums.id) -# fk_rails_... (artist_id => artists.id) -# -class AlbumArtistSerializer < ActiveModel::Serializer - attributes :artist_id, :name, :normalized_name, :order, :separator -end diff --git a/app/serializers/album_label_serializer.rb b/app/serializers/album_label_serializer.rb deleted file mode 100644 index 9b72ea16..00000000 --- a/app/serializers/album_label_serializer.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: album_labels -# -# id :bigint not null, primary key -# catalogue_number :string -# album_id :bigint not null -# label_id :bigint not null -# -# Indexes -# -# index_album_labels_on_album_id (album_id) -# index_album_labels_on_album_id_and_label_id (album_id,label_id) UNIQUE -# index_album_labels_on_label_id (label_id) -# -# Foreign Keys -# -# fk_rails_... (album_id => albums.id) -# fk_rails_... (label_id => labels.id) -# -class AlbumLabelSerializer < ActiveModel::Serializer - attributes :label_id, :catalogue_number -end diff --git a/app/serializers/album_serializer.rb b/app/serializers/album_serializer.rb deleted file mode 100644 index 1951d0ec..00000000 --- a/app/serializers/album_serializer.rb +++ /dev/null @@ -1,67 +0,0 @@ -# == Schema Information -# -# Table name: albums -# -# id :bigint not null, primary key -# edition :date -# edition_description :string -# normalized_title :string not null -# release :date default(Thu, 01 Jan 0000), not null -# review_comment :string -# title :string not null -# created_at :datetime not null -# updated_at :datetime not null -# image_id :bigint -# -# Indexes -# -# index_albums_on_image_id (image_id) UNIQUE -# index_albums_on_normalized_title (normalized_title) -# -# Foreign Keys -# -# fk_rails_... (image_id => images.id) -# -class AlbumSerializer < ActiveModel::Serializer - include Rails.application.routes.url_helpers - - attributes :id, :title, :normalized_title, :release, :review_comment, :edition, :edition_description, :created_at, :updated_at, :image, :image100, :image250, :image500, :image_type - - has_many :album_artists - has_many :album_labels - - def image - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_blob_url(object.image.image, **scope) - end - - def image100 - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_representation_url(object.image.image.variant(resize_to_cover: [100, 100]), **scope) - end - - def image250 - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_representation_url(object.image.image.variant(resize_to_cover: [250, 250]), **scope) - end - - def image500 - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_representation_url(object.image.image.variant(resize_to_cover: [500, 500]), **scope) - end - - def image_type - return nil if object.image.blank? - return nil unless object.image.image.variable? - - object.image.image_type.mimetype - end -end diff --git a/app/serializers/artist_serializer.rb b/app/serializers/artist_serializer.rb deleted file mode 100644 index 9cabcffc..00000000 --- a/app/serializers/artist_serializer.rb +++ /dev/null @@ -1,61 +0,0 @@ -# == Schema Information -# -# Table name: artists -# -# id :bigint not null, primary key -# name :string not null -# normalized_name :string not null -# review_comment :string -# created_at :datetime not null -# updated_at :datetime not null -# image_id :bigint -# -# Indexes -# -# index_artists_on_image_id (image_id) UNIQUE -# index_artists_on_normalized_name (normalized_name) -# -# Foreign Keys -# -# fk_rails_... (image_id => images.id) -# -class ArtistSerializer < ActiveModel::Serializer - include Rails.application.routes.url_helpers - - attributes :id, :name, :normalized_name, :review_comment, :created_at, :updated_at, :image, :image100, :image250, :image500, :image_type - - def image - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_blob_url(object.image.image, **scope) - end - - def image100 - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_representation_url(object.image.image.variant(resize_to_cover: [100, 100]), **scope) - end - - def image250 - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_representation_url(object.image.image.variant(resize_to_cover: [250, 250]), **scope) - end - - def image500 - return nil if object.image.blank? - return nil unless object.image.image.variable? - - rails_representation_url(object.image.image.variant(resize_to_cover: [500, 500]), **scope) - end - - def image_type - return nil if object.image.blank? - return nil unless object.image.image.variable? - - object.image.image_type.mimetype - end -end diff --git a/app/serializers/auth_token_serializer.rb b/app/serializers/auth_token_serializer.rb deleted file mode 100644 index aed1e323..00000000 --- a/app/serializers/auth_token_serializer.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: auth_tokens -# -# id :bigint not null, primary key -# application :string -# hashed_secret :string not null -# user_agent :string not null -# device_id :string not null -# user_id :bigint not null -# -# Indexes -# -# index_auth_tokens_on_device_id (device_id) UNIQUE -# index_auth_tokens_on_user_id (user_id) -# -# Foreign Keys -# -# fk_rails_... (user_id => users.id) -# -class AuthTokenSerializer < ActiveModel::Serializer - attributes :id, :device_id, :user_id, :user_agent, :application -end diff --git a/app/serializers/auth_token_with_secret_serializer.rb b/app/serializers/auth_token_with_secret_serializer.rb deleted file mode 100644 index 1279d35c..00000000 --- a/app/serializers/auth_token_with_secret_serializer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class AuthTokenWithSecretSerializer < AuthTokenSerializer - attribute :secret -end diff --git a/app/serializers/codec_conversion_serializer.rb b/app/serializers/codec_conversion_serializer.rb deleted file mode 100644 index 9cce9cd3..00000000 --- a/app/serializers/codec_conversion_serializer.rb +++ /dev/null @@ -1,21 +0,0 @@ -# == Schema Information -# -# Table name: codec_conversions -# -# id :bigint not null, primary key -# ffmpeg_params :string not null -# name :string not null -# resulting_codec_id :bigint not null -# -# Indexes -# -# index_codec_conversions_on_name (name) UNIQUE -# index_codec_conversions_on_resulting_codec_id (resulting_codec_id) -# -# Foreign Keys -# -# fk_rails_... (resulting_codec_id => codecs.id) -# -class CodecConversionSerializer < ActiveModel::Serializer - attributes :id, :name, :ffmpeg_params, :resulting_codec_id -end diff --git a/app/serializers/codec_serializer.rb b/app/serializers/codec_serializer.rb deleted file mode 100644 index 6c47775d..00000000 --- a/app/serializers/codec_serializer.rb +++ /dev/null @@ -1,15 +0,0 @@ -# == Schema Information -# -# Table name: codecs -# -# id :bigint not null, primary key -# extension :string not null -# mimetype :string not null -# -# Indexes -# -# index_codecs_on_extension (extension) UNIQUE -# -class CodecSerializer < ActiveModel::Serializer - attributes :id, :mimetype, :extension -end diff --git a/app/serializers/cover_filename_serializer.rb b/app/serializers/cover_filename_serializer.rb deleted file mode 100644 index f76faeda..00000000 --- a/app/serializers/cover_filename_serializer.rb +++ /dev/null @@ -1,14 +0,0 @@ -# == Schema Information -# -# Table name: cover_filenames -# -# id :bigint not null, primary key -# filename :string not null -# -# Indexes -# -# index_cover_filenames_on_filename (filename) UNIQUE -# -class CoverFilenameSerializer < ActiveModel::Serializer - attributes :id, :filename -end diff --git a/app/serializers/genre_serializer.rb b/app/serializers/genre_serializer.rb deleted file mode 100644 index 2ad1139f..00000000 --- a/app/serializers/genre_serializer.rb +++ /dev/null @@ -1,16 +0,0 @@ -# == Schema Information -# -# Table name: genres -# -# id :bigint not null, primary key -# name :string not null -# normalized_name :string not null -# -# Indexes -# -# index_genres_on_name (name) UNIQUE -# index_genres_on_normalized_name (normalized_name) -# -class GenreSerializer < ActiveModel::Serializer - attributes :id, :name, :normalized_name -end diff --git a/app/serializers/image_type_serializer.rb b/app/serializers/image_type_serializer.rb deleted file mode 100644 index 81cded3b..00000000 --- a/app/serializers/image_type_serializer.rb +++ /dev/null @@ -1,15 +0,0 @@ -# == Schema Information -# -# Table name: image_types -# -# id :bigint not null, primary key -# extension :string not null -# mimetype :string not null -# -# Indexes -# -# index_image_types_on_extension (extension) UNIQUE -# -class ImageTypeSerializer < ActiveModel::Serializer - attributes :id, :extension, :mimetype -end diff --git a/app/serializers/label_serializer.rb b/app/serializers/label_serializer.rb deleted file mode 100644 index 1819b66c..00000000 --- a/app/serializers/label_serializer.rb +++ /dev/null @@ -1,15 +0,0 @@ -# == Schema Information -# -# Table name: labels -# -# id :bigint not null, primary key -# name :string not null -# normalized_name :string not null -# -# Indexes -# -# index_labels_on_normalized_name (normalized_name) -# -class LabelSerializer < ActiveModel::Serializer - attributes :id, :name, :normalized_name -end diff --git a/app/serializers/location_serializer.rb b/app/serializers/location_serializer.rb deleted file mode 100644 index 75aee012..00000000 --- a/app/serializers/location_serializer.rb +++ /dev/null @@ -1,14 +0,0 @@ -# == Schema Information -# -# Table name: locations -# -# id :bigint not null, primary key -# path :string not null -# -# Indexes -# -# index_locations_on_path (path) UNIQUE -# -class LocationSerializer < ActiveModel::Serializer - attributes :id, :path -end diff --git a/app/serializers/play_serializer.rb b/app/serializers/play_serializer.rb deleted file mode 100644 index 317bffb4..00000000 --- a/app/serializers/play_serializer.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: plays -# -# id :bigint not null, primary key -# played_at :datetime not null -# track_id :bigint not null -# user_id :bigint not null -# -# Indexes -# -# index_plays_on_track_id (track_id) -# index_plays_on_user_id (user_id) -# index_plays_on_user_id_and_track_id (user_id,track_id) -# -# Foreign Keys -# -# fk_rails_... (track_id => tracks.id) -# fk_rails_... (user_id => users.id) -# -class PlaySerializer < ActiveModel::Serializer - attributes :id, :played_at, :track_id, :user_id -end diff --git a/app/serializers/play_stat_serializer.rb b/app/serializers/play_stat_serializer.rb deleted file mode 100644 index ec94f741..00000000 --- a/app/serializers/play_stat_serializer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class PlayStatSerializer < ActiveModel::Serializer - attributes :count, :track_id, :last_played_at, :total_length -end diff --git a/app/serializers/playlist_serializer.rb b/app/serializers/playlist_serializer.rb deleted file mode 100644 index a449ddfd..00000000 --- a/app/serializers/playlist_serializer.rb +++ /dev/null @@ -1,24 +0,0 @@ -# == Schema Information -# -# Table name: playlists -# -# id :bigint not null, primary key -# access :integer default("shared") -# description :string -# name :string not null -# playlist_type :integer not null -# created_at :datetime not null -# updated_at :datetime not null -# user_id :bigint not null -# -# Indexes -# -# index_playlists_on_user_id (user_id) -# -# Foreign Keys -# -# fk_rails_... (user_id => users.id) -# -class PlaylistSerializer < ActiveModel::Serializer - attributes :id, :name, :description, :user_id, :playlist_type, :created_at, :updated_at, :item_ids, :access -end diff --git a/app/serializers/rescan_runner_serializer.rb b/app/serializers/rescan_runner_serializer.rb deleted file mode 100644 index ebf96a2c..00000000 --- a/app/serializers/rescan_runner_serializer.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: rescan_runners -# -# id :bigint not null, primary key -# error_text :text -# finished_at :datetime not null -# processed :integer default(0), not null -# running :boolean default(FALSE), not null -# warning_text :text -# location_id :bigint not null -# -# Indexes -# -# index_rescan_runners_on_location_id (location_id) -# -# Foreign Keys -# -# fk_rails_... (location_id => locations.id) -# -class RescanRunnerSerializer < ActiveModel::Serializer - attributes :id, :error_text, :warning_text, :processed, :running, :finished_at, :location_id -end diff --git a/app/serializers/track_artist_serializer.rb b/app/serializers/track_artist_serializer.rb deleted file mode 100644 index 8cdc1c8a..00000000 --- a/app/serializers/track_artist_serializer.rb +++ /dev/null @@ -1,28 +0,0 @@ -# == Schema Information -# -# Table name: track_artists -# -# id :bigint not null, primary key -# hidden :boolean default(FALSE), not null -# name :string not null -# normalized_name :string not null -# order :integer not null -# role :integer not null -# artist_id :bigint not null -# track_id :bigint not null -# -# Indexes -# -# index_track_artists_on_artist_id (artist_id) -# index_track_artists_on_normalized_name (normalized_name) -# index_track_artists_on_track_id (track_id) -# index_track_artists_on_track_id_and_artist_id_and_name_and_role (track_id,artist_id,name,role) UNIQUE -# -# Foreign Keys -# -# fk_rails_... (artist_id => artists.id) -# fk_rails_... (track_id => tracks.id) -# -class TrackArtistSerializer < ActiveModel::Serializer - attributes :artist_id, :name, :normalized_name, :role, :order, :hidden -end diff --git a/app/serializers/track_moderator_serializer.rb b/app/serializers/track_moderator_serializer.rb deleted file mode 100644 index ddcdba55..00000000 --- a/app/serializers/track_moderator_serializer.rb +++ /dev/null @@ -1,15 +0,0 @@ -class TrackModeratorSerializer < TrackSerializer - attributes :filename, :sample_rate, :bit_depth - - def filename - object.audio_file&.filename - end - - def sample_rate - object.audio_file&.sample_rate - end - - def bit_depth - object.audio_file&.bit_depth - end -end diff --git a/app/serializers/track_serializer.rb b/app/serializers/track_serializer.rb deleted file mode 100644 index 9d8c4bff..00000000 --- a/app/serializers/track_serializer.rb +++ /dev/null @@ -1,46 +0,0 @@ -# == Schema Information -# -# Table name: tracks -# -# id :bigint not null, primary key -# normalized_title :string not null -# number :integer not null -# review_comment :string -# title :string not null -# created_at :datetime not null -# updated_at :datetime not null -# album_id :bigint not null -# audio_file_id :bigint -# -# Indexes -# -# index_tracks_on_album_id (album_id) -# index_tracks_on_audio_file_id (audio_file_id) UNIQUE -# index_tracks_on_normalized_title (normalized_title) -# -# Foreign Keys -# -# fk_rails_... (album_id => albums.id) -# fk_rails_... (audio_file_id => audio_files.id) -# -class TrackSerializer < ActiveModel::Serializer - attributes :id, :title, :normalized_title, :number, :album_id, :review_comment, :created_at, :updated_at, :genre_ids, :codec_id, :length, :bitrate, :location_id, :audio_file_id - - has_many :track_artists - - def codec_id - object.audio_file&.codec_id - end - - def length - object.audio_file&.length - end - - def bitrate - object.audio_file&.bitrate - end - - def location_id - object.audio_file&.location_id - end -end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb deleted file mode 100644 index 10418092..00000000 --- a/app/serializers/user_serializer.rb +++ /dev/null @@ -1,16 +0,0 @@ -# == Schema Information -# -# Table name: users -# -# id :bigint not null, primary key -# name :string not null -# password_digest :string not null -# permission :integer default("user"), not null -# -# Indexes -# -# index_users_on_name (name) UNIQUE -# -class UserSerializer < ActiveModel::Serializer - attributes :id, :name, :permission -end diff --git a/app/views/albums/index.json.jbuilder b/app/views/albums/index.json.jbuilder new file mode 100644 index 00000000..23601b42 --- /dev/null +++ b/app/views/albums/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@albums) { |it| json.merge!(transform_album_for_json(it)) } diff --git a/app/views/albums/show.json.jbuilder b/app/views/albums/show.json.jbuilder new file mode 100644 index 00000000..270795d3 --- /dev/null +++ b/app/views/albums/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_album_for_json(@album)) diff --git a/app/views/artists/index.json.jbuilder b/app/views/artists/index.json.jbuilder new file mode 100644 index 00000000..d901344a --- /dev/null +++ b/app/views/artists/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@artists) { |it| json.merge!(transform_artist_for_json(it)) } diff --git a/app/views/artists/show.json.jbuilder b/app/views/artists/show.json.jbuilder new file mode 100644 index 00000000..cc446ee3 --- /dev/null +++ b/app/views/artists/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_artist_for_json(@artist)) diff --git a/app/views/auth_tokens/create.json.jbuilder b/app/views/auth_tokens/create.json.jbuilder new file mode 100644 index 00000000..db8488ba --- /dev/null +++ b/app/views/auth_tokens/create.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_auth_token_for_json_with_secret(@auth_token)) diff --git a/app/views/auth_tokens/index.json.jbuilder b/app/views/auth_tokens/index.json.jbuilder new file mode 100644 index 00000000..8b017ef1 --- /dev/null +++ b/app/views/auth_tokens/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@auth_tokens) { |it| json.merge!(transform_auth_token_for_json(it)) } diff --git a/app/views/auth_tokens/show.json.jbuilder b/app/views/auth_tokens/show.json.jbuilder new file mode 100644 index 00000000..8c528da8 --- /dev/null +++ b/app/views/auth_tokens/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_auth_token_for_json(@auth_token)) diff --git a/app/views/codec_conversions/index.json.jbuilder b/app/views/codec_conversions/index.json.jbuilder new file mode 100644 index 00000000..8d29e406 --- /dev/null +++ b/app/views/codec_conversions/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@codec_conversions) { |it| json.merge!(transform_codec_conversion_for_json(it)) } diff --git a/app/views/codec_conversions/show.json.jbuilder b/app/views/codec_conversions/show.json.jbuilder new file mode 100644 index 00000000..938e6024 --- /dev/null +++ b/app/views/codec_conversions/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_codec_conversion_for_json(@codec_conversion)) diff --git a/app/views/codecs/index.json.jbuilder b/app/views/codecs/index.json.jbuilder new file mode 100644 index 00000000..5108c879 --- /dev/null +++ b/app/views/codecs/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@codecs) { |it| json.merge!(transform_codec_for_json(it)) } diff --git a/app/views/codecs/show.json.jbuilder b/app/views/codecs/show.json.jbuilder new file mode 100644 index 00000000..a7818ddf --- /dev/null +++ b/app/views/codecs/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_codec_for_json(@codec)) diff --git a/app/views/cover_filenames/index.json.jbuilder b/app/views/cover_filenames/index.json.jbuilder new file mode 100644 index 00000000..756b9add --- /dev/null +++ b/app/views/cover_filenames/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@cover_filenames) { |it| json.merge!(transform_cover_filename_for_json(it)) } diff --git a/app/views/cover_filenames/show.json.jbuilder b/app/views/cover_filenames/show.json.jbuilder new file mode 100644 index 00000000..109b77b9 --- /dev/null +++ b/app/views/cover_filenames/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_cover_filename_for_json(@cover_filename)) diff --git a/app/views/genres/index.json.jbuilder b/app/views/genres/index.json.jbuilder new file mode 100644 index 00000000..f7d37832 --- /dev/null +++ b/app/views/genres/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@genres) { |it| json.merge!(transform_genre_for_json(it)) } diff --git a/app/views/genres/show.json.jbuilder b/app/views/genres/show.json.jbuilder new file mode 100644 index 00000000..5abaac1c --- /dev/null +++ b/app/views/genres/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_genre_for_json(@genre)) diff --git a/app/views/image_types/index.json.jbuilder b/app/views/image_types/index.json.jbuilder new file mode 100644 index 00000000..09812a97 --- /dev/null +++ b/app/views/image_types/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@image_types) { |it| json.merge!(transform_image_type_for_json(it)) } diff --git a/app/views/image_types/show.json.jbuilder b/app/views/image_types/show.json.jbuilder new file mode 100644 index 00000000..aadec28d --- /dev/null +++ b/app/views/image_types/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_image_type_for_json(@image_type)) diff --git a/app/views/labels/index.json.jbuilder b/app/views/labels/index.json.jbuilder new file mode 100644 index 00000000..34973479 --- /dev/null +++ b/app/views/labels/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@labels) { |it| json.merge!(transform_label_for_json(it)) } diff --git a/app/views/labels/show.json.jbuilder b/app/views/labels/show.json.jbuilder new file mode 100644 index 00000000..1a6cb393 --- /dev/null +++ b/app/views/labels/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_label_for_json(@label)) diff --git a/app/views/locations/index.json.jbuilder b/app/views/locations/index.json.jbuilder new file mode 100644 index 00000000..5108c879 --- /dev/null +++ b/app/views/locations/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@codecs) { |it| json.merge!(transform_codec_for_json(it)) } diff --git a/app/views/locations/show.json.jbuilder b/app/views/locations/show.json.jbuilder new file mode 100644 index 00000000..b4297467 --- /dev/null +++ b/app/views/locations/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_location_for_json(@location)) diff --git a/app/views/playlists/index.json.jbuilder b/app/views/playlists/index.json.jbuilder new file mode 100644 index 00000000..740e690a --- /dev/null +++ b/app/views/playlists/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@playlists) { |it| json.merge!(transform_playlist_for_json(it)) } diff --git a/app/views/playlists/show.json.jbuilder b/app/views/playlists/show.json.jbuilder new file mode 100644 index 00000000..54fd7ce7 --- /dev/null +++ b/app/views/playlists/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_playlist_for_json(@playlist)) diff --git a/app/views/plays/index.json.jbuilder b/app/views/plays/index.json.jbuilder new file mode 100644 index 00000000..4eeb3c9f --- /dev/null +++ b/app/views/plays/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@plays) { |it| json.merge!(transform_play_for_json(it)) } diff --git a/app/views/plays/show.json.jbuilder b/app/views/plays/show.json.jbuilder new file mode 100644 index 00000000..3e3b14d0 --- /dev/null +++ b/app/views/plays/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_play_for_json(@play)) diff --git a/app/views/plays/stats.json.jbuilder b/app/views/plays/stats.json.jbuilder new file mode 100644 index 00000000..3ba6c1e9 --- /dev/null +++ b/app/views/plays/stats.json.jbuilder @@ -0,0 +1 @@ +json.array!(@stats) { |it| json.merge!(transform_play_stat_for_json(it)) } diff --git a/app/views/rescans/index.json.jbuilder b/app/views/rescans/index.json.jbuilder new file mode 100644 index 00000000..564ba857 --- /dev/null +++ b/app/views/rescans/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@rescans) { |it| json.merge!(transform_rescan_runner_for_json(it)) } diff --git a/app/views/rescans/show.json.jbuilder b/app/views/rescans/show.json.jbuilder new file mode 100644 index 00000000..bb1c08ac --- /dev/null +++ b/app/views/rescans/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_rescan_runner_for_json(@rescan)) diff --git a/app/views/tracks/index.json.jbuilder b/app/views/tracks/index.json.jbuilder new file mode 100644 index 00000000..4fbdb20e --- /dev/null +++ b/app/views/tracks/index.json.jbuilder @@ -0,0 +1,5 @@ +if current_user.moderator? + json.array!(@tracks) { |it| json.merge!(transform_track_for_json_for_moderator(it)) } +else + json.array!(@tracks) { |it| json.merge!(transform_track_for_json(it)) } +end diff --git a/app/views/tracks/show.json.jbuilder b/app/views/tracks/show.json.jbuilder new file mode 100644 index 00000000..61b044ed --- /dev/null +++ b/app/views/tracks/show.json.jbuilder @@ -0,0 +1,5 @@ +if current_user.moderator? + json.merge!(transform_track_for_json_for_moderator(@track)) +else + json.merge!(transform_track_for_json(@track)) +end diff --git a/app/views/users/index.json.jbuilder b/app/views/users/index.json.jbuilder new file mode 100644 index 00000000..9c8bbbdd --- /dev/null +++ b/app/views/users/index.json.jbuilder @@ -0,0 +1 @@ +json.array!(@users) { |it| json.merge!(transform_user_for_json(it)) } diff --git a/app/views/users/show.json.jbuilder b/app/views/users/show.json.jbuilder new file mode 100644 index 00000000..c41eb62f --- /dev/null +++ b/app/views/users/show.json.jbuilder @@ -0,0 +1 @@ +json.merge!(transform_user_for_json(@user)) diff --git a/config/application.rb b/config/application.rb index 3ac11386..43705235 100644 --- a/config/application.rb +++ b/config/application.rb @@ -37,6 +37,10 @@ class Application < Rails::Application # Skip views, helpers and assets when generating a new resource. config.api_only = true + config.generators do |g| + g.template_engine :jbuilder + end + config.active_job.queue_adapter = :good_job config.active_job.default_queue_name = :within_5_minutes diff --git a/gemset.nix b/gemset.nix index 0554f241..a7d8b948 100644 --- a/gemset.nix +++ b/gemset.nix @@ -65,17 +65,6 @@ }; version = "7.2.2"; }; - active_model_serializers = { - dependencies = ["actionpack" "activemodel" "case_transform" "jsonapi-renderer"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "13n1ipn0dg3k852xhfzdvkr1ljq76xvfnm79qzdix2ishiy1gphl"; - type = "gem"; - }; - version = "0.10.14"; - }; activejob = { dependencies = ["activesupport" "globalid"]; groups = ["default"]; @@ -223,17 +212,6 @@ }; version = "3.3.0"; }; - case_transform = { - dependencies = ["activesupport"]; - groups = ["default"]; - platforms = []; - source = { - remotes = ["https://rubygems.org"]; - sha256 = "0fzyws6spn5arqf6q604dh9mrj84a36k5hsc8z7jgcpfvhc49bg2"; - type = "gem"; - }; - version = "0.2"; - }; concurrent-ruby = { groups = ["default" "development" "test"]; platforms = []; @@ -456,25 +434,26 @@ }; version = "1.14.1"; }; - json = { - groups = ["default" "development"]; + jbuilder = { + dependencies = ["actionview" "activesupport"]; + groups = ["default"]; platforms = []; source = { remotes = ["https://rubygems.org"]; - sha256 = "0pkcvzvarzs5y87srla1m6rgng8mm7y4gnshlpawddsci3rlhd7b"; + sha256 = "1mi7s8kida8rg754bzgiik2mpdwx55x7wxd9ny0sm0803j5a603j"; type = "gem"; }; - version = "2.7.5"; + version = "2.13.0"; }; - jsonapi-renderer = { - groups = ["default"]; + json = { + groups = ["default" "development"]; platforms = []; source = { remotes = ["https://rubygems.org"]; - sha256 = "0ys4drd0k9rw5ixf8n8fx8v0pjh792w4myh0cpdspd317l1lpi5m"; + sha256 = "0pkcvzvarzs5y87srla1m6rgng8mm7y4gnshlpawddsci3rlhd7b"; type = "gem"; }; - version = "0.2.2"; + version = "2.7.5"; }; language_server-protocol = { groups = ["default" "development"];