Skip to content

Commit

Permalink
Agrego correcciones para app mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnicolas committed May 13, 2019
1 parent 3408283 commit 21c25a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
c
ubicacion
c
params[:imagen]
params
reclamo
c
reclamo_params
c
params[:imagen]
reclamo
reclamo.save
reclamo
params[:imagen]
reclamo
c
params
c
@reclamos_destacados.blank?
c
@reclamos_destacados.blank?
Expand Down
17 changes: 15 additions & 2 deletions app/controllers/api_restv1_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,39 @@ def valorar_reclamo
# POST api_restv1/reclamos
def crear_reclamo
reclamo = Reclamo.new
reclamo.imagen = params[:imagen]
reclamo.tipo_reclamo_id = params[:tipo_reclamo_id]
reclamo.titulo = params[:titulo]
reclamo.fecha = params[:fecha]
reclamo.ubicacion = Ubicacion.new
reclamo.ubicacion.latitud = params[:latitud]
reclamo.ubicacion.longitud = params[:longitud]
reclamo.descripcion = params[:descripcion]
reclamo.user_id = current_user.id
debugger
if reclamo.save
render json: reclamo.to_json(include: [:tipo_reclamo, :ubicacion, :user])
else
render json: {errors: ["Ocurrio un error al crear el reclamo"]}, status: :unprocessable_entity
render json: {errors: reclamo.errors}, status: :unprocessable_entity
end
end

# PUT/PATCH api_restv1/reclamos/:id
def actualizar_reclamo
reclamo = Reclamo.find(params[:id])
reclamo.imagen = params[:imagen]
reclamo.tipo_reclamo_id = params[:tipo_reclamo_id]
reclamo.titulo = params[:titulo]
reclamo.fecha = params[:fecha]
reclamo.ubicacion = Ubicacion.new
reclamo.ubicacion.latitud = params[:latitud]
reclamo.ubicacion.longitud = params[:latitud]
reclamo.descripcion = params[:descripcion]
reclamo.user_id = current_user.id
if reclamo.save
render json: reclamo.to_json(include: [:tipo_reclamo, :ubicacion, :user])
else
render json: {errors: ["Ocurrio un error al crear el reclamo"]}, status: :unprocessable_entity
render json: {errors: reclamo.errors}, status: :unprocessable_entity
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/reclamo.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class Reclamo < ActiveRecord::Base
mount_uploader :imagen, ImagenUploader

validates :tipo_reclamo_id, :presence => { :message => "Debe completar el campo Tipo de reclamo" }
validates :fecha, :presence => { :message => "Debe completar el campo Fecha" }
validates :descripcion, :presence => { :message => "Debe completar el campo Descripción" }

belongs_to :ubicacion
belongs_to :tipo_reclamo
belongs_to :user
Expand Down

0 comments on commit 21c25a3

Please sign in to comment.