1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ScheduledActivity do
9 alias Pleroma.ScheduledActivity
15 schema "scheduled_activities" do
16 belongs_to(:user, User, type: Pleroma.FlakeId)
17 field(:scheduled_at, :naive_datetime)
23 def changeset(%ScheduledActivity{} = scheduled_activity, attrs) do
25 |> cast(attrs, [:scheduled_at, :params])
28 def update_changeset(%ScheduledActivity{} = scheduled_activity, attrs) do
30 |> cast(attrs, [:scheduled_at])
33 def new(%User{} = user, attrs) do
34 %ScheduledActivity{user_id: user.id}
38 def create(%User{} = user, attrs) do
44 def get(%User{} = user, scheduled_activity_id) do
46 |> where(user_id: ^user.id)
47 |> where(id: ^scheduled_activity_id)
51 def update(%User{} = user, scheduled_activity_id, attrs) do
52 with %ScheduledActivity{} = scheduled_activity <- get(user, scheduled_activity_id) do
54 |> update_changeset(attrs)
57 nil -> {:error, :not_found}
61 def delete(%User{} = user, scheduled_activity_id) do
62 with %ScheduledActivity{} = scheduled_activity <- get(user, scheduled_activity_id) do
66 nil -> {:error, :not_found}
70 def for_user_query(%User{} = user) do
72 |> where(user_id: ^user.id)