Search code examples
mongodbdartdart-asyncdart-force-mvc

Using objectory with ForceFrameworkMvc


I'm using dart-forcemvc_rest to routing request to my server and serve a json as response. Today I'm starting to using objectory to query data on my mongo db. This is great! I can create models to query my collections and use this ones with properties fetched on my db. This is my model

part of bookshelf; 

class user extends PersistentObject with Jsonify{

  String get username => getProperty(username);
  set username(value) => setProperty(username,value);

  String get email => getProperty(email);
  set email(value) => setProperty(email,value);
}

void registerClasses() {
    objectory.registerClass(user,()=>new user(),()=>new List<user>());
}

And this is my controller

part of bookshelf;

@Controller
class BookController {

  @Autowired
  Objectory db;


  @RequestMapping(value: "/user",method: RequestMethod.GET)
  Future countJson(req) {
    db.initDomainModel().then((_){
      return db[user].findOne();
    }).then((items){
          req.async(items);
    });
    return req.asyncFuture;
  }
}

This uses a async controller feature, but I can't see any response when I call /user, I see only {} on my browser enter image description here

I can't understand where is the trouble. Anybody help me?


Solution

  • To answer your question on the most basic level I believe jsonify package just do not treat setter/getter pair as valid substitution for class variable. Take a look at its source code: https://github.com/jorishermans/jsonify/blob/master/lib/src/jsonify_base.dart#L26

    On another level - maybe it is just not a great idea to have two totally different persistency middleware layer in one project (namely objectory and jsonify). Objectory has it's own unified approach for client/server communication - currently it presuppose using of web sockets and bson transport. (Use of objectory at the server side is trivial in that respect). See simple web example in package itself or (somewhat outdated) example of full stack application at https://github.com/vadimtsushko/angular_objectory_demo . If you prefer to use RESTFULL api and json as transport maybe for example https://github.com/luizmineo/redstone_mapper_mongo would suite you better.

    On the other hand I think it would be nice to have RESTFULL variant of objectory client (with json transport) implemented as shelf plugin or something like this. When/if I'll have a spare time I'll see at it - initially it seems to be quite a trivial task but who knows...