Files
pinchflat/lib/pinchflat/tasks/task.ex
T
hermes-agent 172c1ff264
Build, Lint, and Test / Build, Lint, and Test (push) Failing after 13m0s
Add JSON REST API for MCP integration
- Add /api/v1 namespace with Bearer token auth (PINCHFLAT_API_TOKEN env var)
- API controllers for sources, media items, media profiles, settings, tasks
- Support for all source actions: create, update, delete, force_download_pending,
  force_redownload, force_index, force_metadata_refresh, sync_files_on_disk
- Media item endpoints: list, show, search, force_download, update, delete
- Media profile CRUD endpoints
- Settings show/update and app_info endpoints
- Task listing endpoints
- Add Jason.Encoder for Task schema
- Comprehensive test suite for all API endpoints
- Gitea Actions CI workflow (runs existing checks + API-specific tests)
- API documentation in docs/API.md
2026-07-03 23:22:24 +00:00

46 lines
968 B
Elixir

defmodule Pinchflat.Tasks.Task do
@moduledoc """
The Task schema.
"""
use Ecto.Schema
import Ecto.Changeset
alias Pinchflat.Repo
alias Pinchflat.Media.MediaItem
alias Pinchflat.Sources.Source
schema "tasks" do
belongs_to :job, Oban.Job
belongs_to :source, Source
belongs_to :media_item, MediaItem
timestamps(type: :utc_datetime)
end
@doc false
def changeset(task, attrs) do
task
|> cast(attrs, [:job_id, :source_id, :media_item_id])
|> validate_required([:job_id])
end
@doc false
def json_excluded_fields do
[:__meta__, :__struct__]
end
end
defimpl Jason.Encoder, for: Pinchflat.Tasks.Task do
def encode(value, opts) do
value
|> Repo.preload(:job)
|> Map.drop(Pinchflat.Tasks.Task.json_excluded_fields())
|> Map.update!(:job, fn
nil -> nil
job -> Map.drop(job, [:__meta__, :__struct__, :args, :meta, :worker, :queue])
end)
|> Jason.Encode.map(opts)
end
end