Browse Source

feat: add daily_template setting

main
Inhji Y. 8 months ago
parent
commit
4b9a2e6a99
  1. 5
      lib/mirage/notes.ex
  2. 2
      lib/mirage/settings.ex
  3. 24
      priv/repo/migrations/20210225070255_add_setting_data3.exs

5
lib/mirage/notes.ex

@ -118,10 +118,13 @@ defmodule Mirage.Notes do
[note]
nil ->
template = Mirage.Settings.get_setting_by_name!("daily_template")
IO.inspect(template)
{:ok, note} =
create_note(%{
title: date_title,
content: "Note for #{date_title}"
content: template.value
})
[note]

2
lib/mirage/settings.ex

@ -52,7 +52,7 @@ defmodule Mirage.Settings do
## Examples
iex> get_setting!("somename)
iex> get_setting!("somename")
%Setting{}
iex> get_setting!("someothername")

24
priv/repo/migrations/20210225070255_add_setting_data3.exs

@ -0,0 +1,24 @@
defmodule Mirage.Repo.Migrations.AddSettingsData3 do
use Ecto.Migration
alias Mirage.Settings.Setting
alias Ecto.Multi
import Ecto.Query, warn: false
@settings ["daily_template"]
def up do
Multi.new()
|> Multi.insert(:daily_template, %Setting{
name: "daily_template",
value: "Something",
value_html: "Something"
})
|> repo().transaction()
end
def down do
from(s in Setting, where: s.name in @settings)
|> repo().delete_all()
end
end
Loading…
Cancel
Save