[Enhancement] Improve ordering of models (#164)

* [WIP] ordering app queries

* Refactored media queries to be self-contained
This commit is contained in:
Kieran
2024-04-03 17:26:46 -07:00
committed by GitHub
parent 4b12764f45
commit e55bcaddd0
10 changed files with 160 additions and 136 deletions
@@ -1,12 +1,19 @@
defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
use PinchflatWeb, :controller
import Ecto.Query, warn: false
alias Pinchflat.Repo
alias Pinchflat.Profiles
alias Pinchflat.Sources.SourcesQuery
alias Pinchflat.Profiles.MediaProfile
def index(conn, _params) do
media_profiles = Profiles.list_media_profiles()
media_profiles =
MediaProfile
|> order_by(asc: :name)
|> Repo.all()
render(conn, :index, media_profiles: media_profiles)
end
@@ -32,12 +39,15 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
end
def show(conn, %{"id" => id}) do
media_profile =
id
|> Profiles.get_media_profile!()
|> Repo.preload(:sources)
media_profile = Profiles.get_media_profile!(id)
render(conn, :show, media_profile: media_profile)
sources =
SourcesQuery.new()
|> SourcesQuery.for_media_profile(media_profile)
|> order_by(asc: :custom_name)
|> Repo.all()
render(conn, :show, media_profile: media_profile, sources: sources)
end
def edit(conn, %{"id" => id}) do