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

Phoenix Generators #21

Open
jeregrine opened this issue Dec 17, 2015 · 5 comments
Open

Phoenix Generators #21

jeregrine opened this issue Dec 17, 2015 · 5 comments

Comments

@jeregrine
Copy link

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
Copy link
Member

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

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
Copy link
Author

jeregrine commented Jan 31, 2019 via email

@snewcomer
Copy link
Contributor

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

@doomspork
Copy link
Member

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 👍

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

No branches or pull requests

4 participants