mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-05-20 01:58:08 +00:00
47 lines
836 B
Elixir
47 lines
836 B
Elixir
defmodule LiveBeats.MediaLibrary do
|
|
@moduledoc """
|
|
The MediaLibrary context.
|
|
"""
|
|
|
|
import Ecto.Query, warn: false
|
|
alias LiveBeats.Repo
|
|
|
|
alias LiveBeats.MediaLibrary.{Song, Genre}
|
|
|
|
def create_genre(attrs \\ %{}) do
|
|
%Genre{}
|
|
|> Genre.changeset(attrs)
|
|
|> Repo.insert()
|
|
end
|
|
|
|
def list_genres do
|
|
Repo.all(Genre, order_by: [asc: :title])
|
|
end
|
|
|
|
def list_songs do
|
|
Repo.all(Song)
|
|
end
|
|
|
|
def get_song!(id), do: Repo.get!(Song, id)
|
|
|
|
def create_song(attrs \\ %{}) do
|
|
%Song{}
|
|
|> Song.changeset(attrs)
|
|
|> Repo.insert()
|
|
end
|
|
|
|
def update_song(%Song{} = song, attrs) do
|
|
song
|
|
|> Song.changeset(attrs)
|
|
|> Repo.update()
|
|
end
|
|
|
|
def delete_song(%Song{} = song) do
|
|
Repo.delete(song)
|
|
end
|
|
|
|
def change_song(%Song{} = song, attrs \\ %{}) do
|
|
Song.changeset(song, attrs)
|
|
end
|
|
end
|