Add starts_at, ends_at and all_day parameters
This commit is contained in:
parent
fcf3c9057e
commit
cf8334dbc1
6 changed files with 42 additions and 22 deletions
|
|
@ -24,8 +24,7 @@ defmodule Pleroma.Announcement do
|
|||
|
||||
def change(struct, params \\ %{}) do
|
||||
struct
|
||||
|> validate_params()
|
||||
|> cast(params, [:data])
|
||||
|> cast(validate_params(params), [:data, :starts_at, :ends_at])
|
||||
|> validate_required([:data])
|
||||
end
|
||||
|
||||
|
|
@ -39,11 +38,8 @@ defmodule Pleroma.Announcement do
|
|||
Map.merge(base_struct, params.data)
|
||||
|> Map.take(["content", "all_day"])
|
||||
|
||||
%{
|
||||
data: merged_data,
|
||||
starts_at: Map.get(params, "starts_at"),
|
||||
ends_at: Map.get(params, "ends_at")
|
||||
}
|
||||
params
|
||||
|> Map.merge(%{data: merged_data})
|
||||
end
|
||||
|
||||
def add(params) do
|
||||
|
|
@ -92,9 +88,9 @@ defmodule Pleroma.Announcement do
|
|||
base = %{
|
||||
id: announcement.id,
|
||||
content: announcement.data["content"],
|
||||
starts_at: :null,
|
||||
ends_at: :null,
|
||||
all_day: false,
|
||||
starts_at: announcement.starts_at,
|
||||
ends_at: announcement.ends_at,
|
||||
all_day: announcement.data["all_day"],
|
||||
published_at: announcement.inserted_at,
|
||||
updated_at: announcement.updated_at,
|
||||
mentions: [],
|
||||
|
|
|
|||
|
|
@ -32,12 +32,15 @@ defmodule Pleroma.Web.AdminAPI.AnnouncementController do
|
|||
end
|
||||
end
|
||||
|
||||
def create(%{body_params: %{content: content}} = conn, _params) do
|
||||
add_params = %{
|
||||
data: %{
|
||||
"content" => content
|
||||
}
|
||||
}
|
||||
def create(%{body_params: params} = conn, _params) do
|
||||
data =
|
||||
%{}
|
||||
|> Pleroma.Maps.put_if_present("content", params, &Map.fetch(&1, :content))
|
||||
|> Pleroma.Maps.put_if_present("all_day", params, &Map.fetch(&1, :all_day))
|
||||
|
||||
add_params =
|
||||
params
|
||||
|> Map.merge(%{data: data})
|
||||
|
||||
with {:ok, announcement} <- Announcement.add(add_params) do
|
||||
render(conn, "show.json", announcement: announcement)
|
||||
|
|
|
|||
|
|
@ -95,7 +95,10 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do
|
|||
type: :object,
|
||||
required: [:content],
|
||||
properties: %{
|
||||
content: %Schema{type: :string}
|
||||
content: %Schema{type: :string},
|
||||
starts_at: %Schema{type: :string, format: "date-time"},
|
||||
ends_at: %Schema{type: :string, format: "date-time"},
|
||||
all_day: %Schema{type: :boolean}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,10 +16,14 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Announcement do
|
|||
id: FlakeID,
|
||||
content: %Schema{type: :string},
|
||||
starts_at: %Schema{
|
||||
oneOf: [%Schema{type: :null}, %Schema{type: :string, format: "date-time"}]
|
||||
type: :string,
|
||||
format: "date-time",
|
||||
nullable: true
|
||||
},
|
||||
ends_at: %Schema{
|
||||
oneOf: [%Schema{type: :null}, %Schema{type: :string, format: "date-time"}]
|
||||
type: :string,
|
||||
format: "date-time",
|
||||
nullable: true
|
||||
},
|
||||
all_day: %Schema{type: :boolean},
|
||||
published_at: %Schema{type: :string, format: "date-time"},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue