Class: Api::V1::TicketsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v1/tickets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
# File 'app/controllers/api/v1/tickets_controller.rb', line 27

def create
  @ticket = Ticket.new(params[:ticket])
  if @ticket.save
    render :json => {:success => true} and return
  else
    render :json => {:success => false, :errors => @ticket.errors.full_messages.to_sentence} and return
  end
end

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/api/v1/tickets_controller.rb', line 2

def index
  @bucket = Ticket.order("name")

  @bucket = @bucket.where(:project_id => params[:project_id]) unless params[:project_id].blank?
  @bucket = @bucket.for_repo_url_and_branch(params[:repo_url],params[:branch]) unless params[:repo_url].blank? && params[:branch].blank?

  json_array = []
  @bucket.all.each do |ticket|
    json_array << build_hash_for_ticket(ticket)
  end
  render :json => json_array
end

#showObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/api/v1/tickets_controller.rb', line 15

def show
  @ticket = Ticket.find params[:id]

  json_hash = {
      :name                 => @ticket.name,
      :estimated_hours      => @ticket.estimated_hours,
      :percentage_complete  => @ticket.percentage_complete,
      :hours                => @ticket.hours
  }
  render :json => json_hash
end