Skip to content

Commit

Permalink
Merge pull request #55 from bkeepers/browse
Browse files Browse the repository at this point in the history
Browse
  • Loading branch information
bkeepers committed Jan 26, 2022
2 parents 2195040 + f3f2723 commit 1ec80e0
Show file tree
Hide file tree
Showing 119 changed files with 11,702 additions and 243 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://www.theaudiodb.com/api_guide.php
THEAUDIODB_API_KEY=2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ node_modules
*.local
.DS_Store

.env
app/frontend/components.d.ts
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ gem "puma"
gem "bootsnap", ">= 1.4.4", require: false
gem "vite_rails"
gem "jbuilder"
gem "httparty"
gem "pg_search"
gem "good_job"

group :development, :test do
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
gem "standard"
gem "dotenv-rails"
end

group :development do
Expand All @@ -24,4 +28,8 @@ group :test do
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
gem "vcr"
gem "webmock"
gem "factory_bot"
gem "faker"
end
50 changes: 50 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,40 @@ GEM
xpath (~> 3.2)
childprocess (4.1.0)
concurrent-ruby (1.1.9)
crack (0.4.5)
rexml
crass (1.0.6)
dotenv (2.7.6)
dotenv-rails (2.7.6)
dotenv (= 2.7.6)
railties (>= 3.2)
dry-cli (0.7.0)
erubi (1.10.0)
et-orbi (1.2.6)
tzinfo
factory_bot (6.2.0)
activesupport (>= 5.0.0)
faker (2.19.0)
i18n (>= 1.6, < 2)
ffi (1.15.4)
fugit (1.5.2)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
globalid (1.0.0)
activesupport (>= 5.0)
good_job (2.9.0)
activejob (>= 5.2.0)
activerecord (>= 5.2.0)
concurrent-ruby (>= 1.0.2)
fugit (>= 1.1)
railties (>= 5.2.0)
thor (>= 0.14.1)
webrick (>= 1.3)
zeitwerk (>= 2.0)
hashdiff (1.0.1)
httparty (0.20.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
jbuilder (2.11.4)
Expand All @@ -100,9 +128,13 @@ GEM
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.1115)
mini_mime (1.1.2)
minitest (5.15.0)
msgpack (1.4.2)
multi_xml (0.6.0)
nio4r (2.5.8)
nokogiri (1.12.5-arm64-darwin)
racc (~> 1.4)
Expand All @@ -112,9 +144,13 @@ GEM
parser (3.0.3.2)
ast (~> 2.4.1)
pg (1.2.3)
pg_search (2.3.5)
activerecord (>= 5.2)
activesupport (>= 5.2)
public_suffix (4.0.6)
puma (5.5.2)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.6.0)
rack (2.2.3)
rack-proxy (0.7.0)
Expand Down Expand Up @@ -181,6 +217,7 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
vcr (6.0.0)
vite_rails (3.0.2)
railties (>= 5.1, < 8)
vite_ruby (~> 3.0)
Expand All @@ -197,6 +234,11 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
webmock (3.14.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.7.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -212,16 +254,24 @@ DEPENDENCIES
bootsnap (>= 1.4.4)
byebug
capybara
dotenv-rails
factory_bot
faker
good_job
httparty
jbuilder
listen
pg
pg_search
puma
rails
selenium-webdriver
standard
vcr
vite_rails
web-console
webdrivers
webmock

RUBY VERSION
ruby 3.0.2p107
Expand Down
3 changes: 3 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web: puma -C config/puma.rb
release: rails db:migrate
worker: bundle exec good_job start
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: bin/rails s
vite: bin/vite dev
worker: bundle exec good_job start
17 changes: 17 additions & 0 deletions app/controllers/api/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Api::AlbumsController < ApiController
before_action :set_artist, only: :index

def index
@albums = @artist.albums.order_by_popular.limit(10)
end

def show
@album = Album.find(params[:id])
end

private

def set_artist
@artist = Artist.find(params[:artist_id])
end
end
16 changes: 16 additions & 0 deletions app/controllers/api/artists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Api::ArtistsController < ApiController
before_action :set_artist, only: %i[show]

def index
@artists = params[:letter] ? Artist.starts_with(:name, params[:letter]) : Artist.all
end

def show
end

private

def set_artist
@artist = Artist.find(params[:id])
end
end
12 changes: 12 additions & 0 deletions app/controllers/api/autocomplete_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Api::AutocompleteController < ApiController
def index
case params[:type]
when "title"
@results = Track.includes(:album, :artist).starts_with(:title, params[:query]).limit(10)
when "artist"
@results = Artist.starts_with(:name, params[:query]).limit(10)
else
render json: "Unknown type: #{params[:type].inspect}", status: :unprocessable_entity
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/api/genres_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Api::GenresController < ApiController
def index
@genres = Genre.order_by_popular.all
end

def show
@genre = Genre.find(params[:id])
end
end
8 changes: 8 additions & 0 deletions app/controllers/api/search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::SearchController < ApiController
def index
@results = PgSearch.multisearch(params[:q]).limit(10).with_pg_search_rank
unless params[:type].blank?
@results = @results.where(searchable_type: params[:type].split(",").map { |type| type.singularize.titleize })
end
end
end
50 changes: 0 additions & 50 deletions app/controllers/api/songs_controller.rb

This file was deleted.

54 changes: 54 additions & 0 deletions app/controllers/api/songsheets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class Api::SongsheetsController < ApiController
before_action :set_songsheet, only: %i[show update destroy]

# GET /songsheets.json
def index
@songsheets = if params[:letter]
current_scope.starts_with(:title, params[:letter])
else
current_scope.recent
end
end

# GET /songsheets/1.json
def show
end

# POST /songsheets.json
def create
@songsheet = Songsheet.new(songsheet_params)

if @songsheet.save
render :show, status: :created, location: [:api, @songsheet]
else
render json: @songsheet.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /songsheets/1.json
def update
if @songsheet.update(songsheet_params)
render :show, status: :ok, location: [:api, @songsheet]
else
render json: @songsheet.errors, status: :unprocessable_entity
end
end

# DELETE /songsheets/1.json
def destroy
@songsheet.destroy
head :no_content, location: api_songsheets_url
end

private

# Use callbacks to share common setup or constraints between actions.
def set_songsheet
@songsheet = Songsheet.find(params[:id])
end

# Only allow a list of trusted parameters through.
def songsheet_params
params.require(:songsheet).permit(:source, metadata: {})
end
end
5 changes: 5 additions & 0 deletions app/controllers/api/tracks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Api::TracksController < ApiController
def index
@tracks = current_scope.order_by_popular.limit(12)
end
end
24 changes: 24 additions & 0 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ApiController < ActionController::API
private

# Return the current scope based on current controller and route
#
# For example, in the `Api::SongsheetsController`, a request to
# `GET /api/artists/:artist_id/songsheets` will return
# `Artist.find(params[:artist_id]).songsheets`.
#
def current_scope
@current_scope ||= %w[track album artist].detect do |name|
id = params["#{name}_id"]
break name.classify.constantize.find(id).send(default_scope_name) if id
end || default_scope
end

def default_scope_name
controller_name
end

def default_scope
controller_name.singularize.classify.constantize
end
end
17 changes: 17 additions & 0 deletions app/controllers/concerns/alpha_paginate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module AlphaPaginate
extend ActiveSupport::Concern

LETTERS = ["#"] + ("A".."Z").to_a

included do
scope :starts_with, ->(key, letter) {
result = if letter == "#"
where(arel_table[key].matches_regexp("^[0-9]"))
else
where(arel_table[key].matches(letter + "%"))
end

result.order(key)
}
end
end
Loading

0 comments on commit 1ec80e0

Please sign in to comment.