-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbfd544
commit 8c82d45
Showing
21 changed files
with
1,660 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class MasterTunesController < ApplicationController | ||
before_action :set_master_tune, only: [:show, :update, :destroy] | ||
|
||
# GET /master_tunes | ||
def index | ||
@master_tunes = MasterTune.all | ||
|
||
render json: @master_tunes | ||
end | ||
|
||
# GET /master_tunes/1 | ||
def show | ||
render json: @master_tune | ||
end | ||
|
||
# POST /master_tunes | ||
def create | ||
@master_tune = MasterTune.new(master_tune_params) | ||
|
||
if @master_tune.save | ||
render json: @master_tune, status: :created, location: @master_tune | ||
else | ||
render json: @master_tune.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /master_tunes/1 | ||
def update | ||
if @master_tune.update(master_tune_params) | ||
render json: @master_tune | ||
else | ||
render json: @master_tune.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /master_tunes/1 | ||
def destroy | ||
@master_tune.destroy | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_master_tune | ||
@master_tune = MasterTune.find(params[:id]) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def master_tune_params | ||
params.require(:master_tune).permit(:title, :composer) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class MasterTune < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
class Tune < ApplicationRecord | ||
belongs_to :user | ||
validates :user, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
class User < ApplicationRecord | ||
include Authentication | ||
has_many :examples | ||
has_many :tunes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class MasterTuneSerializer < ActiveModel::Serializer | ||
attributes :id, :title, :composer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class TuneSerializer < ActiveModel::Serializer | ||
attributes :id, :title, :composer | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
class UserSerializer < ActiveModel::Serializer | ||
attributes :id, :email | ||
has_many :tunes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
curl "http://localhost:4741/tunes" \ | ||
--include \ | ||
--request POST \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Token token=${TOKEN}" \ | ||
--data '{ | ||
"tune": { | ||
"title": "'"${TITLE}"'", | ||
"composer": "'"${COMPOSER}"'" | ||
} | ||
}' | ||
|
||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
curl "http://localhost:4741/tunes/${ID}" \ | ||
--include \ | ||
--request DELETE \ | ||
# --header "Content-Type: application/json" \ | ||
# --header "Authorization: Token token=${TOKEN}" \ | ||
|
||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
curl "http://localhost:4741/tunes/${ID}" \ | ||
--include \ | ||
--request GET \ | ||
--header "Content-Type: application/json" \ | ||
# --header "Authorization: Token token=${TOKEN}" \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
curl "http://localhost:4741/tunes/${ID}" \ | ||
--include \ | ||
--request PATCH \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Token token=${TOKEN}" \ | ||
--data '{ | ||
"tune": { | ||
"title": "'"${TITLE}"'", | ||
"composer": "'"${COMPOSER}"'" | ||
} | ||
}' | ||
|
||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateMasterTunes < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :master_tunes do |t| | ||
t.string :title | ||
t.string :composer | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.