Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Context with schema for Events CRUD #27

wants to merge 7 commits into from

Conversation

Menubatenny
Copy link
Contributor

closes #9

lib/nudge/accounts/site.ex Show resolved Hide resolved
lib/nudge/sites/event.ex Show resolved Hide resolved
lib/nudge/sites/event.ex Outdated Show resolved Hide resolved
lib/nudge_web/router.ex Outdated Show resolved Hide resolved
render(conn, "new.html", changeset: changeset)
end

def create(conn, %{"event" => event_params}) do
Copy link
Contributor

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

@sreecodeslayer sreecodeslayer changed the title Context with schema for CRUD Context with schema for Events CRUD Sep 13, 2021
Comment on lines +8 to +9
field :end_date, :string
field :start_date, :string
Copy link
Contributor

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))
Copy link
Contributor

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?

Comment on lines +44 to +47
site_id = Nudge.Accounts.get_site!(id)

IO.inspect(site_id)
events = Sites.list_site_events(site_id)
Copy link
Contributor

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

Comment on lines +25 to +28
query =
from site in Nudge.Accounts.Site,
where: site.id == ^site_id,
order_by: site.inserted_at
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Events] Context with schema for CRUD
2 participants