much progress on shift assigning & app navigation

This commit is contained in:
Adam Piontek 2021-03-19 16:38:52 -04:00
commit 8957f2d1dd
33 changed files with 363 additions and 330 deletions
lib/shift73k

View file

@ -22,13 +22,26 @@ defmodule Shift73k.Shifts do
end
def list_shifts_by_user_between_dates(user_id, start_date, end_date) do
q = from(
s in Shift,
select: %{date: s.date, subject: s.subject, time_start: s.time_start, time_end: s.time_end},
where: s.user_id == ^user_id and s.date >= ^start_date and s.date < ^end_date,
order_by: [s.date, s.time_start]
)
Repo.all(q)
from(s in Shift)
|> select([s], %{
date: s.date,
subject: s.subject,
time_start: s.time_start,
time_end: s.time_end
})
|> where([s], s.user_id == ^user_id and s.date >= ^start_date and s.date <= ^end_date)
|> order_by([s], [s.date, s.time_start])
|> Repo.all()
end
defp query_shifts_by_user_on_list_of_dates(user_id, date_list) do
from(s in Shift)
|> where([s], s.user_id == ^user_id and s.date in ^date_list)
end
def list_shifts_by_user_on_list_of_dates(user_id, date_list) do
query_shifts_by_user_on_list_of_dates(user_id, date_list)
|> Repo.all()
end
@doc """
@ -99,6 +112,11 @@ defmodule Shift73k.Shifts do
Repo.delete(shift)
end
def delete_shifts_by_user_on_list_of_dates(user_id, date_list) do
query_shifts_by_user_on_list_of_dates(user_id, date_list)
|> Repo.delete_all()
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking shift changes.

View file

@ -22,7 +22,11 @@ defmodule Shift73k.Shifts.Templates do
end
def list_shift_templates_by_user_id(user_id) do
q = from s in ShiftTemplate, where: s.user_id == ^user_id, order_by: [s.subject, s.time_start]
q =
from s in ShiftTemplate,
where: s.user_id == ^user_id,
order_by: [fragment("lower(?)", s.subject), s.time_start]
Repo.all(q)
end

View file

@ -19,6 +19,7 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do
field :time_end, :time, default: ~T[17:00:00]
belongs_to(:user, Shift73k.Accounts.User)
has_one(:is_fave_of_user, Shift73k.Accounts.User, foreign_key: :fave_shift_template_id)
timestamps()
end
@ -58,7 +59,9 @@ defmodule Shift73k.Shifts.Templates.ShiftTemplate do
[]
end
end)
|> validate_inclusion(:time_zone, Timex.timezones(), message: "must be a valid IANA tz database time zone")
|> validate_inclusion(:time_zone, Timex.timezones(),
message: "must be a valid IANA tz database time zone"
)
end
defp time_start_from_attrs(%{"time_start" => time_start}), do: time_start