Hash :
2418571d
Author :
Thomas de Grivel
Date :
2022-03-01T07:54:32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
defmodule Kmxgit.SlugManager do
import Ecto.Query, warn: false
alias Kmxgit.Repo
alias Kmxgit.SlugManager.Slug
def list_slugs do
Slug
|> Repo.all
end
def create_slug(slug) do
%Slug{}
|> Slug.changeset(%{slug: slug})
|> Repo.insert()
end
def update_slug(slug, attrs) do
slug
|> Slug.changeset(attrs)
|> Repo.update()
end
def get_slug(slug) do
Repo.one from s in Slug,
where: fragment("lower(?)", s.slug) == ^String.downcase(slug),
preload: [organisation: [:slug,
owned_repositories: [members: :slug,
organisation: [:slug,
:users],
user: :slug],
users: :slug],
user: [:slug,
organisations: :slug,
owned_repositories: [members: :slug,
organisation: :slug,
user: :slug]]],
limit: 1
end
def delete_slug(%Slug{} = slug) do
Repo.delete(slug)
end
end