-
Notifications
You must be signed in to change notification settings - Fork 0
As a user, I can upload keywords #6
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
base: develop
Are you sure you want to change the base?
Conversation
d418296 to
2a073c6
Compare
| use Ecto.Schema | ||
| import Ecto.Changeset | ||
|
|
||
| embedded_schema 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.
It's a great idea to use embedded_schema. I just read about it last weekend. It's the closest to implement some kind of form object 💪
lib/google_crawler/search.ex
Outdated
| %Keyword{} | ||
|
|
||
| iex> get_keyword!(456) | ||
| ** (Ecto.NoResultsError) |
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.
This will return nil as it's not using get!
| [] | ||
| else | ||
| [file: "is not supported"] | ||
| end |
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.
How about:
defp validate_file_ext(changeset) do
if Enum.member?(@accept_file_ext, Path.extname(file.filename)) do
changeset
else
add_error(changeset, : file, "is not supported")
end
end
The return of an empty array [] is kind of strange while returning changeset seems more expected.
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.
I rechecked this one. I found something interesting 📝
When using the validate_change, seems like it will only validate when the value is not nil - https://hexdocs.pm/ecto/Ecto.Changeset.html#validate_change/3. So after removing it out, there is one case that if the file is nil, it will still validate and the error occurs when file.filename because the file is nil. For this, we might need to add more condition/clause function to handle this case 👍
What happened
✅ Change the default pages controller to dashboard controller
✅ Add an upload form on the user dashboard
✅ Parse the uploaded csv
Insight
Implement the upload form which ties to the
KeywordFileschema which validate for the file typeUse the CSV Library to parse the file
Proof Of Work
Display the upload form on the user dashboard
When the user uploads the invalid file type, displays the error
When the user uploads the valid csv, parses and displays the parsed content
For example we upload the file with this content