Skip to content

Commit

Permalink
Merge pull request #8 from 00198216/Hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
Sortweste authored Jul 4, 2020
2 parents 6608326 + aa98b59 commit bf399f9
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem 'puma', '~> 4.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rake (13.0.1)
redis (4.2.1)
sprockets (4.0.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -162,6 +163,7 @@ DEPENDENCIES
puma (~> 4.1)
rails (~> 6.0.2, >= 6.0.2.2)
rails_12factor
redis (~> 4.0)
sqlite3 (~> 1.4)
tzinfo-data

Expand Down
30 changes: 19 additions & 11 deletions app/channels/list_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@ def unsubscribed
def message(data)
@num=data['id'].to_i
@user=User.find(@num)
@all= @user.lists
@message=
@all= List.all
@message=
# Jbuilder.encode do |json|
# json.info @user, :id
#
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
@help= @association= ListProduct.find_by(
list_id: list.id,
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
list_id: list.id,
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
end
end
end

end
end
ActionCable.server.broadcast 'super_channel', message: @message
end

Expand Down
34 changes: 27 additions & 7 deletions app/controllers/api/v1/listproducts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ def destroy
@List.update_attribute(:quantity, @List.quantity)
render json: { message: "Product succesfully removed from list" }, status: 200
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand All @@ -32,7 +36,7 @@ def destroy
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
json.product_status @help.checked
end
end
end
Expand All @@ -57,13 +61,17 @@ def add
@lists=List.all
@products=@List.products
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand All @@ -72,7 +80,7 @@ def add
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
json.product_status @help.checked
end
end
end
Expand All @@ -91,13 +99,17 @@ def update
@association.update_attribute(:description, params[:description])
render json: {status: "product quantity updated"}, status: 201
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand Down Expand Up @@ -129,13 +141,17 @@ def check
@association.update_attribute(:checked, false)
render json: {status: "delisted product"}, status: 201
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand All @@ -153,13 +169,17 @@ def check
@association.update_attribute(:checked, true)
render json: {status: "listed product"}, status: 201
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand Down
24 changes: 18 additions & 6 deletions app/controllers/api/v1/lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ def create
if @list.save
render json: {status: "List created successfully"}, status: 201
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand All @@ -35,7 +39,7 @@ def create
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
json.product_status @help.checked
end
end
end
Expand All @@ -53,13 +57,17 @@ def update
if @List.update(list_params)
render json: {status: "list updated"}, status: 201
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand All @@ -68,7 +76,7 @@ def update
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
json.product_status @help.checked
end
end
end
Expand Down Expand Up @@ -98,13 +106,17 @@ def destroy
if @List.destroy
render json: { message: "List Successfully Deleted." }, status: 200
@User = @current_user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand All @@ -113,7 +125,7 @@ def destroy
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
json.product_status @help.checked
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/api/v1/listusers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def destroy
render json: {status: "deleted friend drom the list successfully"}, status: 201
end

#Agrega un usuario de una lista
#Agrega un usuario a una lista
def add
@user = User.find_by(id: params[:id])
@List= List.find_by(name: params[:name])
Expand All @@ -24,13 +24,17 @@ def add
@lists=List.all
@products=@List.products
@User = @user
@all= @User.lists
@all= List.all
@message=
Jbuilder.encode do |json|
json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def show
#Mostrar las listas de un usuario
def lists
@user = User.find_by(id: params[:id])

@all= @user.lists
end

#Buscar un usuario
Expand Down
22 changes: 20 additions & 2 deletions app/views/api/v1/users/lists.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
@list=@user.lists

json.lists @list, :id, :name, :products

json.info @all do |list|
json.id list.id
json.name list.name
json.creation list.created_at
json.users list.users do |user|
json.user_id user.id
json.username user.username
end
json.products list.products do |product|
json.product_id product.id
json.product_name product.name
@help= @association= ListProduct.find_by(
list_id: list.id,
product_id: product.id)
json.product_quantity @help.quantity
json.product_descripcion @help.description
json.product_status @help.checked
end
end
7 changes: 6 additions & 1 deletion config/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ development:
test:
adapter: test

# production:
# adapter: postgresql
# channel_prefix: proyect_production

production:
adapter: postgresql
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: proyect_production

0 comments on commit bf399f9

Please sign in to comment.