jeudi 14 avril 2016

Your way of simple query builder on web API example

Which is a best way, in your opinion, to build simple (3-5 classes, just for practice) database query builder. Something thru http raw post data, by own convention.

I see it like this maybe:

Request examples:

url: //api/users
method: POST
raw:
  {
    "take" : 5,
  }

url: //api/users
method: POST
raw:
  {
    "id" : {"in" : [1, 2, 5]},
    "take" : 100,
  }

url: //api/users
method: POST
raw:
  {
    "name" : {"like" : "%ohn Do%"},
    "date" : {">=" : "2013-03-20T09:00:00.119"},
    "take" : 10,
  }

Filter example:

public class UserFilter
{
  public UserModel model = new UserModel();
  // here goes magic ...
  public List<UserModel> apply(Context context)
  {
    // here too ...
    return filtredUserEntityList;
  }
}

Controller example:

public class UsersController : ApiController
{
  [HttpPost]
  public List<UserModel> getUsers(UserFilter filter)
  {
      return filter.apply(new Context()); // or maybe elike this - retrun repo(filter, new Context());
  }
}

P.S.

Maybe somethintg like this allready provided somewhere?

P.P.S.

Or maybe here too less magic))





Aucun commentaire:

Enregistrer un commentaire