This commit is contained in:
Mirai Kumiko 2025-07-05 15:20:40 +02:00
parent 188bc08494
commit 4af88f3e1d
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
44 changed files with 1041 additions and 34 deletions

View file

@ -0,0 +1,43 @@
defmodule NullaWeb.Api.ActivityController do
use NullaWeb, :controller
alias Nulla.Activities
alias Nulla.Activities.Activity
action_fallback NullaWeb.FallbackController
def index(conn, _params) do
activities = Activities.list_activities()
render(conn, :index, activities: activities)
end
def create(conn, %{"activity" => activity_params}) do
with {:ok, %Activity{} = activity} <- Activities.create_activity(activity_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/activities/#{activity}")
|> render(:show, activity: activity)
end
end
def show(conn, %{"id" => id}) do
activity = Activities.get_activity!(id)
render(conn, :show, activity: activity)
end
def update(conn, %{"id" => id, "activity" => activity_params}) do
activity = Activities.get_activity!(id)
with {:ok, %Activity{} = activity} <- Activities.update_activity(activity, activity_params) do
render(conn, :show, activity: activity)
end
end
def delete(conn, %{"id" => id}) do
activity = Activities.get_activity!(id)
with {:ok, %Activity{}} <- Activities.delete_activity(activity) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -0,0 +1,29 @@
defmodule NullaWeb.Api.ActivityJSON do
alias Nulla.Activities.Activity
@doc """
Renders a list of activities.
"""
def index(%{activities: activities}) do
%{data: for(activity <- activities, do: data(activity))}
end
@doc """
Renders a single activity.
"""
def show(%{activity: activity}) do
%{data: data(activity)}
end
defp data(%Activity{} = activity) do
%{
id: activity.id,
ap_id: activity.ap_id,
type: activity.type,
actor: activity.actor,
object: activity.object,
to: activity.to,
cc: activity.cc
}
end
end

View file

@ -0,0 +1,43 @@
defmodule NullaWeb.Api.ActorController do
use NullaWeb, :controller
alias Nulla.Actors
alias Nulla.Actors.Actor
action_fallback NullaWeb.FallbackController
def index(conn, _params) do
actors = Actors.list_actors()
render(conn, :index, actors: actors)
end
def create(conn, %{"actor" => actor_params}) do
with {:ok, %Actor{} = actor} <- Actors.create_actor(actor_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/actors/#{actor}")
|> render(:show, actor: actor)
end
end
def show(conn, %{"id" => id}) do
actor = Actors.get_actor!(id)
render(conn, :show, actor: actor)
end
def update(conn, %{"id" => id, "actor" => actor_params}) do
actor = Actors.get_actor!(id)
with {:ok, %Actor{} = actor} <- Actors.update_actor(actor, actor_params) do
render(conn, :show, actor: actor)
end
end
def delete(conn, %{"id" => id}) do
actor = Actors.get_actor!(id)
with {:ok, %Actor{}} <- Actors.delete_actor(actor) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -0,0 +1,49 @@
defmodule NullaWeb.Api.ActorJSON do
alias Nulla.Actors.Actor
@doc """
Renders a list of actors.
"""
def index(%{actors: actors}) do
%{data: for(actor <- actors, do: data(actor))}
end
@doc """
Renders a single actor.
"""
def show(%{actor: actor}) do
%{data: data(actor)}
end
defp data(%Actor{} = actor) do
%{
id: actor.id,
acct: actor.acct,
ap_id: actor.ap_id,
type: actor.type,
following: actor.following,
followers: actor.followers,
inbox: actor.inbox,
outbox: actor.outbox,
featured: actor.featured,
featuredTags: actor.featuredTags,
preferredUsername: actor.preferredUsername,
name: actor.name,
summary: actor.summary,
url: actor.url,
manuallyApprovesFollowers: actor.manuallyApprovesFollowers,
discoverable: actor.discoverable,
indexable: actor.indexable,
published: actor.published,
memorial: actor.memorial,
publicKey: actor.publicKey,
tag: actor.tag,
attachment: actor.attachment,
endpoints: actor.endpoints,
icon: actor.icon,
image: actor.image,
vcard_bday: actor.vcard_bday,
vcard_Address: actor.vcard_Address
}
end
end

View file

@ -0,0 +1,45 @@
defmodule NullaWeb.Api.MediaAttachmentController do
use NullaWeb, :controller
alias Nulla.MediaAttachments
alias Nulla.MediaAttachments.MediaAttachment
action_fallback NullaWeb.FallbackController
def index(conn, _params) do
media_attachments = MediaAttachments.list_media_attachments()
render(conn, :index, media_attachments: media_attachments)
end
def create(conn, %{"media_attachment" => media_attachment_params}) do
with {:ok, %MediaAttachment{} = media_attachment} <-
MediaAttachments.create_media_attachment(media_attachment_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/media_attachments/#{media_attachment}")
|> render(:show, media_attachment: media_attachment)
end
end
def show(conn, %{"id" => id}) do
media_attachment = MediaAttachments.get_media_attachment!(id)
render(conn, :show, media_attachment: media_attachment)
end
def update(conn, %{"id" => id, "media_attachment" => media_attachment_params}) do
media_attachment = MediaAttachments.get_media_attachment!(id)
with {:ok, %MediaAttachment{} = media_attachment} <-
MediaAttachments.update_media_attachment(media_attachment, media_attachment_params) do
render(conn, :show, media_attachment: media_attachment)
end
end
def delete(conn, %{"id" => id}) do
media_attachment = MediaAttachments.get_media_attachment!(id)
with {:ok, %MediaAttachment{}} <- MediaAttachments.delete_media_attachment(media_attachment) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -0,0 +1,30 @@
defmodule NullaWeb.Api.MediaAttachmentJSON do
alias Nulla.MediaAttachments.MediaAttachment
@doc """
Renders a list of media_attachments.
"""
def index(%{media_attachments: media_attachments}) do
%{data: for(media_attachment <- media_attachments, do: data(media_attachment))}
end
@doc """
Renders a single media_attachment.
"""
def show(%{media_attachment: media_attachment}) do
%{data: data(media_attachment)}
end
defp data(%MediaAttachment{} = media_attachment) do
%{
id: media_attachment.id,
type: media_attachment.type,
mediaType: media_attachment.mediaType,
url: media_attachment.url,
name: media_attachment.name,
width: media_attachment.width,
height: media_attachment.height,
note_id: media_attachment.note_id
}
end
end

View file

@ -0,0 +1,43 @@
defmodule NullaWeb.Api.NoteController do
use NullaWeb, :controller
alias Nulla.Notes
alias Nulla.Notes.Note
action_fallback NullaWeb.FallbackController
def index(conn, _params) do
notes = Notes.list_notes()
render(conn, :index, notes: notes)
end
def create(conn, %{"note" => note_params}) do
with {:ok, %Note{} = note} <- Notes.create_note(note_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/notes/#{note}")
|> render(:show, note: note)
end
end
def show(conn, %{"id" => id}) do
note = Notes.get_note!(id)
render(conn, :show, note: note)
end
def update(conn, %{"id" => id, "note" => note_params}) do
note = Notes.get_note!(id)
with {:ok, %Note{} = note} <- Notes.update_note(note, note_params) do
render(conn, :show, note: note)
end
end
def delete(conn, %{"id" => id}) do
note = Notes.get_note!(id)
with {:ok, %Note{}} <- Notes.delete_note(note) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -0,0 +1,32 @@
defmodule NullaWeb.Api.NoteJSON do
alias Nulla.Notes.Note
@doc """
Renders a list of notes.
"""
def index(%{notes: notes}) do
%{data: for(note <- notes, do: data(note))}
end
@doc """
Renders a single note.
"""
def show(%{note: note}) do
%{data: data(note)}
end
defp data(%Note{} = note) do
%{
id: note.id,
inReplyTo: note.inReplyTo,
published: note.published,
url: note.url,
visibility: note.visibility,
to: note.to,
cc: note.cc,
sensitive: note.sensitive,
content: note.content,
language: note.language
}
end
end

View file

@ -0,0 +1,43 @@
defmodule NullaWeb.Api.RelationController do
use NullaWeb, :controller
alias Nulla.Relations
alias Nulla.Relations.Relation
action_fallback NullaWeb.FallbackController
def index(conn, _params) do
relations = Relations.list_relations()
render(conn, :index, relations: relations)
end
def create(conn, %{"relation" => relation_params}) do
with {:ok, %Relation{} = relation} <- Relations.create_relation(relation_params) do
conn
|> put_status(:created)
|> put_resp_header("location", ~p"/api/relations/#{relation}")
|> render(:show, relation: relation)
end
end
def show(conn, %{"id" => id}) do
relation = Relations.get_relation!(id)
render(conn, :show, relation: relation)
end
def update(conn, %{"id" => id, "relation" => relation_params}) do
relation = Relations.get_relation!(id)
with {:ok, %Relation{} = relation} <- Relations.update_relation(relation, relation_params) do
render(conn, :show, relation: relation)
end
end
def delete(conn, %{"id" => id}) do
relation = Relations.get_relation!(id)
with {:ok, %Relation{}} <- Relations.delete_relation(relation) do
send_resp(conn, :no_content, "")
end
end
end

View file

@ -0,0 +1,37 @@
defmodule NullaWeb.Api.RelationJSON do
alias Nulla.Relations.Relation
@doc """
Renders a list of relations.
"""
def index(%{relations: relations}) do
%{data: for(relation <- relations, do: data(relation))}
end
@doc """
Renders a single relation.
"""
def show(%{relation: relation}) do
%{data: data(relation)}
end
defp data(%Relation{} = relation) do
%{
id: relation.id,
following: relation.following,
followed_by: relation.followed_by,
showing_replies: relation.showing_replies,
showings_reblogs: relation.showings_reblogs,
notifying: relation.notifying,
muting: relation.muting,
muting_notifications: relation.muting_notifications,
blocking: relation.blocking,
blocked_by: relation.blocked_by,
domain_blocking: relation.domain_blocking,
requested: relation.requested,
note: relation.note,
local_actor_id: relation.local_actor_id,
remote_actor_id: relation.remote_actor_id
}
end
end