Compare commits

..

No commits in common. "ea667243e0c44aca8f64edf345e51de0482a7dc4" and "4929ce21fdc10274c6c4b8f3b641719d1c32e1a7" have entirely different histories.

4 changed files with 13 additions and 30 deletions

4
.gitignore vendored
View file

@ -28,8 +28,8 @@ nulla-*.tar
# Ignore assets that are produced by build tools.
/priv/static/assets/
# Ignore upload dir
/priv/static/system/
# Ignore static files
/priv/static/files/
# Ignore digested assets cache.
/priv/static/cache_manifest.json

View file

@ -1,36 +1,22 @@
defmodule Nulla.Models.MediaAttachment do
use Ecto.Schema
import Ecto.Changeset
alias Nulla.Repo
alias Nulla.Snowflake
alias Nulla.Models.Note
@primary_key {:id, :integer, autogenerate: false}
schema "media_attachments" do
field :type, :string
field :mediaType, :string
field :url, :string
field :name, :string
field :width, :integer
field :height, :integer
field :file, :string
field :mime_type, :string
field :description, :string
belongs_to :note, Note
timestamps(type: :utc_datetime)
end
def changeset(media_attachment, attrs) do
media_attachment
|> cast(attrs, [:type, :mediaType, :url, :name, :width, :height, :note_id])
|> validate_required([:type, :mediaType, :url, :note_id])
end
def create_media_attachment(attrs) when is_map(attrs) do
id = Map.get(attrs, :id, Snowflake.next_id())
%__MODULE__{}
|> changeset(attrs)
|> put_change(:id, id)
|> Repo.insert()
def changeset(media, attrs) do
media
|> cast(attrs, [:note_id, :file, :mime_type, :description])
|> validate_required([:note_id, :file])
end
end

View file

@ -17,7 +17,7 @@ defmodule NullaWeb do
those modules here.
"""
def static_paths, do: ~w(assets system fonts images favicon.ico robots.txt)
def static_paths, do: ~w(assets files fonts images favicon.ico robots.txt)
def router do
quote do

View file

@ -4,13 +4,10 @@ defmodule Nulla.Repo.Migrations.CreateMediaAttachments do
def change do
create table(:media_attachments, primary_key: false) do
add :id, :bigint, primary_key: true
add :type, :string, null: false
add :mediaType, :string, null: false
add :url, :string, null: false
add :name, :string
add :width, :integer
add :height, :integer
add :note_id, references(:notes, on_delete: :delete_all), null: false
add :file, :string, null: false
add :mime_type, :string
add :description, :string
timestamps(type: :utc_datetime)
end