-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Context with schema for Events CRUD #27
base: main
Are you sure you want to change the base?
Conversation
render(conn, "new.html", changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"event" => event_params}) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a service module for events.
Events will have more things to implement, and those things can't be part of controller. Let's extract these code to a svc module and use context inside it
field :end_date, :string | ||
field :start_date, :string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two should be utc datetime type, not strings
{:ok, event} -> | ||
conn | ||
|> put_flash(:info, "Site created successfully.") | ||
|> redirect(to: Routes.site_event_path(conn, :index, :id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redirect(to: Routes.site_event_path(conn, :index, :id))
Will this line work? Shouldn't we be passing the id of the site?
site_id = Nudge.Accounts.get_site!(id) | ||
|
||
IO.inspect(site_id) | ||
events = Sites.list_site_events(site_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does get_site!/1
return just id or the whole site struct with data?
This is why we end up having type casting error in the query. The query expects and id, but you are passing the whole result to the list_site_events/1
query = | ||
from site in Nudge.Accounts.Site, | ||
where: site.id == ^site_id, | ||
order_by: site.inserted_at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the right query for filtering events?
closes #9