sloanelybutsurely.com/lib/cms/posts.ex

31 lines
486 B
Elixir

defmodule CMS.Posts do
@moduledoc false
import Ecto.Query
alias CMS.Posts.Post
alias CMS.Repo
def create_post(attrs) do
%Post{}
|> Post.changeset(attrs)
|> Repo.insert()
end
def update_post(post, attrs) do
post
|> Post.changeset(attrs)
|> Repo.update()
end
def get_post!(id) do
Repo.get!(Post, id)
end
def list_posts do
query =
from post in Post,
order_by: [desc: post.inserted_at]
Repo.all(query)
end
end