2020-12-18 16:04:07 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-12-06 16:01:38 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-12-06 18:31:05 +01:00
|
|
|
|
using Serwer.Infrastructure.DTO;
|
2020-12-06 16:01:38 +01:00
|
|
|
|
using Serwer.Infrastructure.Services;
|
2020-12-12 20:54:08 +01:00
|
|
|
|
using Serwer.Infrastructure.ViewModels;
|
2020-12-06 16:01:38 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Serwer.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class UserController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
public UserController(IUserService userService)
|
|
|
|
|
{
|
|
|
|
|
_userService = userService;
|
|
|
|
|
}
|
2020-12-06 18:31:05 +01:00
|
|
|
|
|
|
|
|
|
[HttpPost("Register")]
|
2020-12-12 20:54:08 +01:00
|
|
|
|
public async Task<IActionResult> Register([FromForm]RegisterModel request)
|
2020-12-06 18:31:05 +01:00
|
|
|
|
{
|
2020-12-12 20:54:08 +01:00
|
|
|
|
await _userService.RegisterAsync(request.Email, request.Name, request.Surname, request.Login, request.Password);
|
2020-12-06 18:31:05 +01:00
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("SignIn")]
|
2020-12-12 20:54:08 +01:00
|
|
|
|
public async Task<IActionResult> SignIn([FromForm]SignInModel request)
|
2020-12-06 18:31:05 +01:00
|
|
|
|
{
|
2020-12-12 20:54:08 +01:00
|
|
|
|
var user = await _userService.SignInAsync(request.Login, request.Password);
|
2020-12-06 18:31:05 +01:00
|
|
|
|
return Ok(user);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-18 16:04:07 +01:00
|
|
|
|
[Authorize]
|
|
|
|
|
[HttpPost("Update")]
|
|
|
|
|
public async Task<IActionResult> Update([FromForm]UpdateUserModel request)
|
|
|
|
|
{
|
|
|
|
|
var user = await _userService.UpdateAsync(request);
|
|
|
|
|
return Ok(user);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-06 18:31:05 +01:00
|
|
|
|
[HttpGet("Test")]
|
|
|
|
|
public IActionResult Test()
|
|
|
|
|
{
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2020-12-06 16:01:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|