diff --git a/app/controllers/v1/complaints_controller.rb b/app/controllers/v1/complaints_controller.rb index 5015fb5c70e218362edb397f172b696d07ce52df..661258533a625f251b0a69476e075bb4d6cbd28e 100644 --- a/app/controllers/v1/complaints_controller.rb +++ b/app/controllers/v1/complaints_controller.rb @@ -33,10 +33,11 @@ class V1::ComplaintsController < ApplicationController # POST v1/complaints # POST v1/complaints.json def create - complaint = Complaint.new(complaint_params) + @complaint = Complaint.new(complaint_params) - if complaint.save - render json: complaint, status: :created + if @complaint.save + ComplaintsMailer.new_complaint_received(@complaint, @current_user).deliver_now + render json: @complaint, status: :created else render json: complaint.errors, status: :unprocessable_entity end diff --git a/app/mailers/complaints_mailer.rb b/app/mailers/complaints_mailer.rb new file mode 100644 index 0000000000000000000000000000000000000000..c402375807719755cd926bce8cda82af45a8954c --- /dev/null +++ b/app/mailers/complaints_mailer.rb @@ -0,0 +1,29 @@ + +# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre +# Departamento de Informatica - Universidade Federal do Parana +# +# This file is part of portalmec. +# +# portalmec is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# portalmec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with portalmec. If not, see <http://www.gnu.org/licenses/>. + +class ComplaintsMailer < ApplicationMailer + default to: 'marcelaribeirooliveira@gmail.com' + default from: Proc.new { @user.email } + + def new_complaint_received(complaint, user) + @complaint = complaint + @user = user + mail(subject: "Denuncia de objeto") + end +end diff --git a/app/views/complaints_mailer/new_complaint_received.html.erb b/app/views/complaints_mailer/new_complaint_received.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a7978285902cf482d347a4f54e5bec829d363e37 --- /dev/null +++ b/app/views/complaints_mailer/new_complaint_received.html.erb @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body> + <h2>Nome do usuário: <%= @user.name %></h1> + <h2>Email do usuário: <%= @user.email %></h1> + <h2>Descrição: <%= @complaint.description %></h1> + <h2>Classe denunciada: <%= @complaint.complainable_type %></h1> + <h2>Id: <%= @complaint.complainable_id %></h1> + <h2>Razão: <%= @complaint.complaint_reason_id %></h1> + </body> +</html>