can't resist
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
696 B

defmodule Blog do
@moduledoc """
Documentation for `Blog`.
"""
import Ecto.Query, warn: false
alias Blog.Post
@preloads [:tags]
def create_post(attrs \\ %{}) do
%Post{}
|> Post.changeset(attrs)
|> Db.Repo.insert()
end
def update_post(post, attrs) do
post
|> Db.Repo.preload(@preloads)
|> Post.changeset(attrs)
|> Db.Repo.update()
end
def get_post!(id),
do:
Db.Repo.get!(Post, id)
|> Db.Repo.preload(@preloads)
def list_posts(limit \\ 10) do
Post
|> where(type: "post")
|> limit(^limit)
|> Db.Repo.all()
|> Db.Repo.preload(@preloads)
end
def delete_post(post) do
Db.Repo.delete(post)
end
end