CD2 / Cord

Original rails implementation of Cord
0 stars 0 forks source link

New response/request format please #4

Open HenryMorgan-cd2 opened 7 years ago

HenryMorgan-cd2 commented 7 years ago

THIS REQUEST:

[
  {
    "api": "things",
    "ids": [
      { "scopes": ["all", "available"] },
      { "_id": "123", "scopes": ["all", "published"], "query": "hello", "sort": "name"},
      { "_id": "uid", "scopes": ["all"] }
    ],
    "records": [
      {
        "ids": [1,"url-slug",4],
        "attributes": ["full_name", "articles"],
      }
    ]
  },
]

produces this response:

[
  {
    "table": "things",
    "ids": {
      "all": [1,2,3,4],
      "available": [1,2,3,4],
      "123": {
        "all": [1,2,3,4],
        "published": [1,2,3],
      },
      "uid": {
        "all": [1,2]
      }
    },
    "records": [
      {"id": 1, "name": "thing", "body": "thing body", "full_name": "asd", "article_ids": [1,2,3]},
      {"id": 3, "name": "thing", "body": "thing body", "full_name": "asd", "article_ids": [1,2]},
      {"id": 4, "name": "thing", "body": "thing body", "full_name": "asd", "article_ids": [4], _errors: {name: 'must be present'}},
    ],
    "aliases": {
      "url-slug": 3,
    }
  },
  {
    "table": "articles",
    "records": [
      {"id": 1, "name": "article 1"},
      {"id": 2, "name": "article 2"},
      {"id": 3, "name": "article 3"},
      {"id": 4, "name": "article 4"},
    ],
    "actions": [
      { name: "destroy", ids: [1,2,3,4] },
    ]
  }
]
HenryMorgan-cd2 commented 7 years ago

@james-cd2 thoughts???? this should come with helper methods:

and maybe

james-page-dev commented 7 years ago

For use in custom APIs, presumably? For tests/console work these would be very helpful too. I'd be in favour of render_api, especially since it would be pretty easy to implement: ArticlesApi.new(Cord::ApiBaseController, {}).get Though, the api would need to be modified to use @params over deferring to the controller's params.