hpi-schul-cloud / schulcloud-content

GNU Affero General Public License v3.0
0 stars 0 forks source link

Add resource hook for resource api v1 #34

Closed niccokunzmann closed 7 years ago

niccokunzmann commented 7 years ago

This adds the resource hook for the version 1 of the resource api for the crawlers.

niccokunzmann commented 7 years ago

Ich kann jetzt eine valide resource posten und sie wird in die Datenbank geschrieben. TODO:

niccokunzmann commented 7 years ago

I found the traceback of the error:

    at Error.GeneralError (/app/node_modules/feathers-errors/lib/index.js:177:3)
    at /app/node_modules/feathers-errors/lib/error-handler.js:25:15
    at Layer.handle_error (/app/node_modules/express/lib/router/layer.js:71:5)
    at trim_prefix (/app/node_modules/express/lib/router/index.js:315:13)
    at /app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at next (/app/node_modules/express/lib/router/index.js:275:10)
    at Layer.handle_error (/app/node_modules/express/lib/router/layer.js:67:12)
    at trim_prefix (/app/node_modules/express/lib/router/index.js:315:13)
    at /app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at next (/app/node_modules/express/lib/router/index.js:275:10)
    at ServerResponse.res.format (/app/node_modules/express/lib/response.js:641:5)
    at formatter (/app/node_modules/feathers-rest/lib/index.js:25:7)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/app/node_modules/express/lib/router/route.js:137:13)
niccokunzmann commented 7 years ago

https://docs.feathersjs.com/api/rest.html There is a link to the formatting

app.configure(rest(function(req, res) {
  // Format the message as text/plain
  res.format({
    'text/plain': function() {
      res.end(`The Message is: "${res.data.text}"`);
    }
  });  
}))

Will try this.

niccokunzmann commented 7 years ago

a3d55db resolves the error here

{"name":"GeneralError","message":"Not Acceptable","code":500,"className":"general-error","data":{},"errors":{}}

This error is caused because rest can not convert to the media type of the Accept header. I would have liked a 406 error but somehow we only get a 500 error.

niccokunzmann commented 7 years ago

Now, 12 steps to go and we are done.

niccokunzmann commented 7 years ago

adding travis tests....

niccokunzmann commented 7 years ago

@kremer-io du kannst mergen.

kremer-io commented 7 years ago

@niccokunzmann I'll review your PR today

kremer-io commented 7 years ago

@niccokunzmann atm, this PR is breaking the current implementation. E.g.

GET http://127.0.0.1:4040/resources/

is returning

{
    "data": [
        {
            "id": "x79debcfe",
            "type": "id"
        }
    ],
    "links": {
        "self": "http://127.0.0.1:4040/v1/resources/ids"
    },
    "jsonapi": {
        "version": "1.0",
        "meta": {
            "name": "schulcloud-content",
            "source": "https://github.com/schul-cloud/schulcloud-content",
            "description": "This is the content service for storing learning material."
        }
    }
}

... which can't be right.

kremer-io commented 7 years ago

Please check the other services, e.g. Client and Server, are still working with this PR.

niccokunzmann commented 7 years ago

Then, they must not request using application/vnd.api+json but using application/json. I will check what happens if they request using application/json

niccokunzmann commented 7 years ago

If you provide a command you run and the outpt you expect, this speeds up coordination.

niccokunzmann commented 7 years ago

I use

curl http://localhost:4040/resources

And I suppose, the test case is that it should not contain "jsonapi".

kremer-io commented 7 years ago

Yes, curl is fine. Are you not getting the same response as described?

niccokunzmann commented 7 years ago

I am getting it.

This should return the correct output:

curl -H "Accept: application/json" http://localhost:4040/resources
niccokunzmann commented 7 years ago

This is covered in #36