Skip to content

Commit

Permalink
Likes being created, playlist-likes appear to be shown
Browse files Browse the repository at this point in the history
  • Loading branch information
OObadare committed Feb 9, 2018
1 parent 158921d commit 2b63ea9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
25 changes: 11 additions & 14 deletions app/controllers/api/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
class Api::LikesController < ApplicationController

def create
debugger
@like = Like.new(like_params)
@like.save!
if @like.save!
render "api/likes/show"
else
render json:["There was an error creating your playlist"]
end
end

def show
if params[:playlist_id]
@likes = Like.where(playlist_id: params[:playlist_id].to_i)
debugger
elsif params[:user_id]
@likes = Like.where(user_id: params[:user_id].to_i)
end

@like = Like.find(params[:id])
end

def index
if params[:user_id]
if params[:playlist_id] != nil
#the user show page should show all the playlists liked by the user
@likes = likes.find_by(user_id: user_id)
elsif params[:playlist_id]
@likes = Like.where(playlist_id: params[:playlist_id].to_i)
elsif params[:user_id] != nil
#the playlist page should check to see if the likes on the playlist includes the current user's id
@likes = likes.find_by(playlist_id: playlist_id)
@likes = Like.where(user_id: params[:user_id].to_i)
end
end

def destroy
#should just make the like aplode
@like = like.find_by_params(params[:user_id], params[:playlist_id])
@like = Like.find_by_params(params[:user_id], params[:playlist_id])
@like.destroy

end
Expand Down
3 changes: 2 additions & 1 deletion app/views/api/likes/_like.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
json.extract! @like, :id, :user_id, :playlist_id
debugger
json.extract! like, :id, :user_id, :playlist_id
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace :api, defaults: {format: :json} do
resources :users, only: [:create, :show]
resource :session, only: [:create, :destroy, :show]
resource :likes, only: [:create, :destroy, :show, :index]
resources :likes, only: [:index, :create, :destroy, :show]
resources :playlists do
resources :tracks
end
Expand Down
2 changes: 1 addition & 1 deletion frontend/actions/playlist_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const RECEIVE_PLAYLIST = "RECEIVE_PLAYLIST";
export const RECEIVE_PLAYLISTS = "RECEIVE_PLAYLISTS";
export const FETCH_PLAYLIST = "FETCH_PLAYLIST";
export const RECEIVE_LIKE = "CREATE_LIKE";
export const RECEIVE_LIKES = "RECEIVE_USER_LIKES";
export const RECEIVE_LIKES = "RECEIVE_LIKES";

export const receivePlaylist = function(payload){
return {
Expand Down

0 comments on commit 2b63ea9

Please sign in to comment.