Avanade/Liquid-Application-Framework

CRUD Web API - status codes

karpikpl opened this issue · 3 comments

Hi,
I've followed the readme and created a web API with sample entity.
Template generated this code:

    [ApiController]
    [Route("api/[controller]")]
    public class MyObjectController : LiquidControllerBase
    {
        public MyObjectController(IMediator mediator) : base(mediator)
        {
        }

        [HttpGet("{id}")]
        public async Task<IActionResult> Get([FromRoute] int id) => await ExecuteAsync(new GetByIdMyObjectQuery(id), HttpStatusCode.Created);

        [HttpPost]
        public async Task<IActionResult> Post([FromBody] MyObjectEntity entity) => await ExecuteAsync(new PostMyObjectCommand(entity), HttpStatusCode.OK);

        [HttpPut]
        public async Task<IActionResult> Put([FromBody] MyObjectEntity entity) => await ExecuteAsync(new PutMyObjectCommand(entity), HttpStatusCode.OK);

        [HttpDelete("{id}")]
        public async Task<IActionResult> Delete([FromRoute] int id) => await ExecuteAsync(new DeleteMyObjectCommand(id), HttpStatusCode.OK);
    }

There were few things that are surprising:

  1. Get returns 201 Create status code
  2. Post returns 200 status code without a link to data created
  3. Get returns 201 and null entity when data is not found - it should be 404
  4. Put returns 200 for data that doesn't exist - but it doesn't create it
  5. Delete returns 200 when data doesn't exit - it also returns deleted entity
  6. Post and Get use different schema
    Post:
{
  "id": 7
}

but GET returns:

{
  "data": {
    "id": 7
  }
}

Was the intention to implement a fully functional CRUD or just template something that has to be modified?

Is there a better example for WebApi ?

Hi,
some fixes was maded yesterday, and was published package version 1.1.0, which fix points 1 and 2 as you can see here

About items 3 to 6 are bugs and need fixing. I suspect these are issues in the framework component packages, which need investigation.

@lucianareginalino - actually after searching outside of Avanade organization, I found https://github.com/ycamargo/tdcfuture-demo which is a better demo and it has those issues solved by using GenericCrudController

it's just very hard to find which package has what