Class: Profiler::Api::JobsController
- Inherits:
-
Profiler::ApplicationController
- Object
- ActionController::Base
- Profiler::ApplicationController
- Profiler::Api::JobsController
- Defined in:
- app/controllers/profiler/api/jobs_controller.rb
Instance Method Summary collapse
Instance Method Details
#clear ⇒ Object
43 44 45 46 |
# File 'app/controllers/profiler/api/jobs_controller.rb', line 43 def clear Profiler.storage.clear(type: "job") head :no_content end |
#destroy ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/controllers/profiler/api/jobs_controller.rb', line 35 def destroy profile = Profiler.storage.load(params[:id]) return render json: { error: "Job profile not found" }, status: :not_found unless profile&.profile_type == "job" Profiler.storage.delete(params[:id]) head :no_content end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/profiler/api/jobs_controller.rb', line 8 def index limit = (params[:limit] || 50).to_i offset = (params[:offset] || 0).to_i all = Profiler.storage.list(limit: 1000, offset: 0) jobs = all.select { |p| p.profile_type == "job" } page = jobs.drop(offset).first(limit + 1) render json: { profiles: page.first(limit).map(&:to_h), limit: limit, offset: offset, has_more: page.size > limit } end |
#show ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/profiler/api/jobs_controller.rb', line 22 def show profile = Profiler.storage.load(params[:id]) unless profile && profile.profile_type == "job" return render json: { error: "Job profile not found" }, status: :not_found end render json: profile.to_h.merge( child_jobs: build_child_jobs(profile), parent_profile: build_parent_summary(profile) ) end |