Skip to content

Commit

Permalink
Feat: update list_unarchived_links_by_index
Browse files Browse the repository at this point in the history
  • Loading branch information
AfonsoMartins26 committed Sep 18, 2024
1 parent c1a317b commit 96d8f72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/cesium_link/links.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ defmodule CesiumLink.Links do
"""
def list_unarchived_links_by_index do
Repo.all(from l in Link, where: l.archived == false, order_by: [asc: l.index])
Link
|> where([l], fragment("? > now()", l.publish_at))
|> where([l], l.archived == false )
|> order_by([l], asc: l.index)
|> Repo.all()
end

@doc """
Expand Down
3 changes: 2 additions & 1 deletion lib/cesium_link/links/link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule CesiumLink.Links.Link do
use CesiumLink.Schema

@required_fields ~w(name emoji url attention edited_at)a
@optional_fields ~w(index archived visits)a
@optional_fields ~w(index archived visits publish_at)a

schema "links" do
field :archived, :boolean, default: false
Expand All @@ -16,6 +16,7 @@ defmodule CesiumLink.Links.Link do
field :url, :string
field :visits, :integer, default: 0
field :edited_at, :utc_datetime
field :publish_at, :utc_datetime

timestamps(type: :utc_datetime)
end
Expand Down
9 changes: 9 additions & 0 deletions priv/repo/migrations/20240918181533_add_link_scheduling.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule CesiumLink.Repo.Migrations.AddLinkScheduling do
use Ecto.Migration

def change do
alter table(:links) do
add :publish_at, :utc_datetime
end
end
end

0 comments on commit 96d8f72

Please sign in to comment.