-
Notifications
You must be signed in to change notification settings - Fork 86
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
Switches category controller away from ja_resource #880
Switches category controller away from ja_resource #880
Conversation
Push to production
Push to production
Push to production
Push to production
Push project categories endpoints to production
Push to production
Push to production
Push to production
Push to production
Push to production
Push Stripe and tasks to production
Push fix to production
Push receipt emails to prod
Push image changes to production
Push to production
Push dialyzer changes to prod
Push analytics changes to production
Push Stripe event fix to prod
Push to production
Add project users in production
Push to production
Push to production
Push to production
Push to production
Push to production
Push to production
Push to production
Push to production
Push to production
Push to production
Push to production
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.
Just some minor code style changes I'd like before we get this merged. Otherwise, done exactly as it should have been.
Awesome job and thank you!
lib/code_corps/policy/category.ex
Outdated
def update?(%User{admin: true}), do: true | ||
def update?(%User{admin: false}), do: false | ||
def update?(%{admin: true}), do: true | ||
def update?(%{admin: false}), do: false |
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 understand your goal here is reduction of code, but we tend to prefer using stronger type constraints unless we have to loosen them for some reason.
In fact, what we'd prefer here is to rewrite these as
@spec create?(User.t) :: boolean
def create?(%User{admin: true}), do: true
def create?(%User{}), do: false
@spec update?(User.t) :: boolean
def update?(%User{admin: true}), do: true
def update?(%User{}), do: false
lib/code_corps/policy/policy.ex
Outdated
defp can?(%User{} = user, :create, %Category{}, %{}), do: Policy.Category.create?(user) | ||
defp can?(%User{} = user, :update, %Category{}, %{}), do: Policy.Category.update?(user) | ||
|
||
@spec can?(User.t, atom, struct, map) :: boolean |
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 all have the same "prototype" (same amount of arguments, same types of arguments in the same order), so there is no need for an extra @spec
, nor for keeping a blank line between them. Elixir, and Credo prefer no blank lines between the same function's (in the context of arity) different clauses.
This is something that wasn't clear since there was only a single example in the code previously, but should be clearer once we merge your PR in.
def model, do: CodeCorps.Category | ||
@spec index(Conn.t, map) :: Conn.t | ||
def index(%Conn{} = conn, %{} = params) do | ||
with category <- Category |> Query.id_filter(params) |> Repo.all 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.
categories
instead of category
here. We don't want to imply that index loads a single record. I'm guessing a copy-paste lapse :)
{:ok, %Category{} = category} <- category |> Category.changeset(params) |> Repo.update | ||
do | ||
conn |> render("show.json-api", data: category) | ||
end | ||
end | ||
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.
Textbook quality controller conversion here 👍
b98fb0f
to
9806646
Compare
9806646
to
89316ba
Compare
@begedin Having a little trouble when rebasing. Is there a wiki somewhere with your git conventions? |
@begedin Actually, I think I may have rebased from master(instead of develop). I may need to close this PR and open another. |
What's in this PR?
Updates
Category
policy methods- can (
policy.ex
)- update (
category/policy.ex
)- create (
category/policy.ex
)Updates
Category
controller methods- index
- show
- update
- create
Progress on: #864