93 lines
2.2 KiB
Ruby
93 lines
2.2 KiB
Ruby
class EmailsController < ApplicationController
|
|
before_action :set_email, only: [:show, :edit, :update, :destroy]
|
|
|
|
# GET /emails
|
|
# GET /emails.json
|
|
def index
|
|
results = email_repository.search({
|
|
query: {
|
|
match_all: {}
|
|
},
|
|
sort: [{
|
|
date: { order: 'desc' }
|
|
}],
|
|
size: 100,
|
|
from: 0,
|
|
aggregations: {
|
|
clients: { terms: { field: 'clients.keyword' } },
|
|
servers: { terms: { field: 'servers.keyword' } },
|
|
tickets: { terms: { field: 'tickets.keyword' } }
|
|
},
|
|
})
|
|
@emails = results.results
|
|
end
|
|
|
|
# GET /emails/1
|
|
# GET /emails/1.json
|
|
def show
|
|
end
|
|
|
|
# GET /emails/new
|
|
def new
|
|
@email = Email.new
|
|
end
|
|
|
|
# GET /emails/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /emails
|
|
# POST /emails.json
|
|
def create
|
|
@email = Email.new(email_params)
|
|
|
|
respond_to do |format|
|
|
if @email.save
|
|
format.html { redirect_to @email, notice: 'Email was successfully created.' }
|
|
format.json { render :show, status: :created, location: @email }
|
|
else
|
|
format.html { render :new }
|
|
format.json { render json: @email.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /emails/1
|
|
# PATCH/PUT /emails/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @email.update(email_params)
|
|
format.html { redirect_to @email, notice: 'Email was successfully updated.' }
|
|
format.json { render :show, status: :ok, location: @email }
|
|
else
|
|
format.html { render :edit }
|
|
format.json { render json: @email.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /emails/1
|
|
# DELETE /emails/1.json
|
|
def destroy
|
|
email_repository.delete(params[:id])
|
|
respond_to do |format|
|
|
format.html { redirect_to emails_url, notice: 'Email was successfully destroyed.' }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
def email_repository
|
|
@email_repository ||= EmailRepository.new
|
|
end
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_email
|
|
@email = email_repository.find(params[:id])
|
|
end
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def email_params
|
|
params.fetch(:email, {})
|
|
end
|
|
end
|