Commit 6bffcd33 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-score-edit' into 'master'

Fix GET /admin/scores/:id/edit and sort scores by descending point

See merge request !1
parents dc240c17 9f46493d
......@@ -2,6 +2,7 @@ defmodule ILoveBackend.Api do
@moduledoc """
The Api context.
"""
import Ecto.Query, only: [from: 2]
alias ILoveBackend.Repo
......@@ -31,8 +32,10 @@ defmodule ILoveBackend.Api do
"""
def list_scores do
Score
|> Repo.all()
query = from s in Score,
order_by: [desc: :point]
Repo.all(query)
|> Repo.preload(:user)
end
end
......@@ -3,7 +3,7 @@ defmodule ILoveBackend.Scores do
The Scores context.
"""
import Ecto.Query, warn: false
import Ecto.Query, only: [from: 2]
alias ILoveBackend.Repo
alias ILoveBackend.Scores.Score
......@@ -20,8 +20,10 @@ defmodule ILoveBackend.Scores do
"""
def list_scores do
Score
|> Repo.all()
query = from s in Score,
order_by: [desc: :point]
Repo.all(query)
|> Repo.preload(:user)
end
......
......@@ -50,7 +50,8 @@ defmodule ILoveBackendWeb.Admin.ScoreController do
def edit(conn, %{"id" => id}) do
score = Scores.get_score!(id)
changeset = Scores.change_score(score)
render(conn, "edit.html", score: score, changeset: changeset)
users = Accounts.list_users()
render(conn, "edit.html", score: score, changeset: changeset, users: users)
end
def update(conn, %{"id" => id, "score" => score_params}) do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment