redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Nesting @app.Group? #151

Closed RdeWilde closed 8 years ago

RdeWilde commented 8 years ago

I just got started with Dart and Redstone, looks great.

Is it possible to nest @app.Group thru some sort of structure?

I would ofcourse prefer splitting the services up into different parts (the UserService etc).

For example, possibly pseudo:

const VERSION = "v1";

@app.Group("/api/${VERSION}")
class ApiService {

  // Move this somewhere else, but remain in the app.Group
  @app.Group("/users")
  class UserService extends MongoDbService<User> {
    UserService() : super("users");

    @app.Route("/list")
    @Encode()
    Future<List<User>> list() => find();
  }

}

Would be awesome, thanks!

Pacane commented 8 years ago

This is more like a limitation in Dart. What I suggest you though, is to put your paths in a constant files where the nested paths are included in another constant.

This way you can have things like

const String api = '/api';
const String users = '$api/users';

@app.Group("$users")
class UsersGroup {
}

and so on.

indiealexh commented 8 years ago

My solution to this problem is to extend the Group annotation...

e.g.

class ApiGroup extends app.Group {
  const ApiGroup(String urlPrefix) : super("/api" + urlPrefix);
}

@ApiGroup("/")
class IndexController extends Controller {}

And now I can just call the API specific annotation where I need it, and if needs be, extend that group to have sub groups.