Add a controler for "User" (add and authenticate)

This commit is contained in:
Sébastien André
2020-03-12 12:24:51 +01:00
parent 8a29fd7de9
commit 32a27b6d26
23 changed files with 225 additions and 34 deletions

View File

@@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Cors;
using AutoMapper;
using skydiveLogs_api.Business.Interface;
using skydiveLogs_api.DataContract;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
public UserController(IUserService userService,
IMapper mapper)
{
_userService = userService;
_mapper = mapper;
}
// POST: api/User
[HttpPost]
[EnableCors]
public UserResp Authenticate([FromBody] string login, [FromBody] string password)
{
var result = _userService.GetByLogin(login, password);
return _mapper.Map<UserResp>(result);
}
// POST: api/User
[HttpPost]
[EnableCors]
public void Post([FromBody] UserReq value)
{
_userService.AddNewUser(_mapper.Map<User>(value));
}
private readonly IUserService _userService;
private readonly IMapper _mapper;
}
}