beam-community / jsonapi

JSON:API Serializer and Query Handler for Elixir
https://hex.pm/packages/jsonapi
MIT License
491 stars 79 forks source link

Phoenix Generators #21

Open jeregrine opened 8 years ago

jeregrine commented 8 years ago

I think it would be great to get some phoenix generators in here. This is my "best case" api

mix jsonapi.gen.resource User users name:string email:string bio:string number_of_pets:integer
* creating priv/repo/migrations/20150409213440_create_user.exs
* creating web/models/user.ex
* creating test/models/user_test.exs
* creating web/controllers/user_controller.ex
* creating web/views/user_view.ex
* creating test/controllers/user_controller_test.exs

Add the resource to your browser scope in web/router.ex:

    resources "/users", UserController

and then update your repository by running migrations:

    $ mix ecto.migrate

And then

mix jsonapi.gen.resource Post posts title:string body:string belongs_to:User
* creating priv/repo/migrations/20150409213440_create_post.exs
* creating web/models/post.ex
* creating test/models/post_test.exs
* creating web/controllers/post_controller.ex
* creating web/views/post_view.ex
* creating test/controllers/post_controller_test.exs

Add the resource to your browser scope in web/router.ex:

    resources "/posts", PostController
    #TODO Figure out all the different LINKS routes we can insert here

and then update your repository by running migrations:

    $ mix ecto.migrate

Then you could do a GET /posts?include=user&fields=title,body,user.name&order=-posts.created_at And it would work out of the box.

doomspork commented 5 years ago

@jeregrine / @jherdman / @snewcomer is this still something we'd like to consider? If not, I vote we close the issue so we can keep things focused.

jherdman commented 5 years ago

I think it could be kind of nice to do this. I don't think they're a must, but it'd certainly make it easier for new users to get started.

jeregrine commented 5 years ago

Something to consider, not something I'm willing to put time into, if someone else is :+1:

On Thu, Jan 31, 2019 at 3:13 PM James Herdman notifications@github.com wrote:

I think it could be kind of nice to do this. I don't think they're a must, but it'd certainly make it easier for new users to get started.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jeregrine/jsonapi/issues/21#issuecomment-459508554, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGKFktkehMr3cPWW_5XWle7SwVPrlBVks5vI1yKgaJpZM4G3ph1 .

snewcomer commented 5 years ago

Switching over a project soon, so I'll see if I can provide some unique insight!

doomspork commented 5 years ago

Awesome feedback! I don't personally use the generators and have found maintaining them to be a tad bit a pain over time (we've got generators here: https://github.com/slime-lang/phoenix_slime).

That said if someone wants to do the work and maintain them as things change with Ecto, Phoenix, etc then we should keep this open 👍

github-actions[bot] commented 1 week ago

This issue has been automatically marked as "stale:discard". We are sorry that we haven't been able to prioritize it yet. If this issue still relevant, please leave any comment if you have any new additional information that helps to solve this issue. We encourage you to create a pull request, if you can. We are happy to help you with that.