0cf96f88be
- Add FallbackController for proper 404 JSON responses on missing resources - Add non-bang get_source/1 and get_media_item/1 for safe lookups - Fix Task JSON encoder: remove Repo.preload call (not available in encoder scope), handle NotLoaded associations by returning nil - Fix media item index: use list_media_items_for_source/1 instead of list_pending_media_items_for/1 which had overly restrictive filtering - Add missing extras_directory to test config - All 1007 tests pass
33 lines
730 B
Elixir
33 lines
730 B
Elixir
defmodule PinchflatWeb.Api.V1.ApiTaskController do
|
|
@moduledoc """
|
|
JSON API controller for Tasks.
|
|
"""
|
|
|
|
use PinchflatWeb, :controller
|
|
|
|
action_fallback PinchflatWeb.Api.V1.FallbackController
|
|
|
|
alias Pinchflat.Repo
|
|
alias Pinchflat.Tasks
|
|
|
|
def index(conn, params) do
|
|
tasks =
|
|
case params do
|
|
%{"source_id" => source_id} ->
|
|
source = Pinchflat.Sources.get_source!(source_id)
|
|
Tasks.list_tasks_for(source)
|
|
|> Repo.preload(:job)
|
|
|
|
_ ->
|
|
Tasks.list_tasks()
|
|
|> Repo.preload(:job)
|
|
end
|
|
|
|
json(conn, %{data: tasks})
|
|
end
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
task = Tasks.get_task!(id) |> Repo.preload(:job)
|
|
json(conn, %{data: task})
|
|
end
|
|
end |