Implement Post action for FeedbackReceiverController.cs

This commit is contained in:
Denis-Cosmin Nutiu 2021-05-29 20:02:16 +03:00
parent 1e3f7c74d4
commit 39c0bf72b8
2 changed files with 73 additions and 49 deletions

View file

@ -1,49 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Retroactiune.Models;
namespace Retroactiune.Controllers.Admin
{
[ApiController]
[Route("api/v1/[controller]")]
public class RetroActiune : ControllerBase
{
[HttpDelete("{id}")]
public NoContentResult Delete(long id)
{
return NoContent();
}
[HttpPost]
public BasicResponse Post()
{
return new BasicResponse()
{
Message = "post retroactiune"
};
}
[HttpGet("{id}")]
public BasicResponse Get(long id)
{
return new BasicResponse()
{
Message = "hwlo"
};
}
[HttpGet]
public IEnumerable<BasicResponse> List()
{
return Enumerable.Range(1, 5).Select(i =>
new BasicResponse()
{
Message = "hwlo"
}
);
}
}
}

View file

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Retroactiune.Models;
using Retroactiune.Services;
namespace Retroactiune.Controllers
{
[ApiController]
[Route("api/v1/[controller]")]
public class FeedbackReceiverController : ControllerBase
{
private readonly FeedbackReceiverService _service;
private readonly IMapper _mapper;
public FeedbackReceiverController(FeedbackReceiverService service, IMapper mapper)
{
_service = service;
_mapper = mapper;
}
[HttpDelete("{id}")]
public NoContentResult Delete(long id)
{
// delete feedback item.
return NoContent();
}
[HttpPost]
public async Task<BasicResponse> Post(IEnumerable<FeedbackReceiverDto> items)
{
var mappedItems = items.ToList().Select(i =>
{
var result = _mapper.Map<FeedbackReceiver>(i);
result.CreatedAt = DateTime.UtcNow;
return result;
});
await _service.CreateMany(mappedItems);
return new BasicResponse()
{
Message = "Items created successfully!"
};
}
[HttpGet("{id}")]
public BasicResponse Get(long id)
{
// get feedback item from db
return new BasicResponse()
{
Message = "hwlo"
};
}
[HttpGet]
public IEnumerable<BasicResponse> List()
{
// list all feedback items.
return Enumerable.Range(1, 5).Select(i =>
new BasicResponse()
{
Message = "hwlo"
}
);
}
}
}