SES-84 Created User registration method #27
@ -1,6 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SessionCompanion.Services.Interfaces;
|
using SessionCompanion.Services.Interfaces;
|
||||||
|
using SessionCompanion.ViewModels.UserViewModels;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using SessionCompanion.Extensions.EitherType;
|
||||||
|
using SessionCompanion.ViewModels.ApiResponses;
|
||||||
|
|
||||||
namespace SessionCompanion.Controllers
|
namespace SessionCompanion.Controllers
|
||||||
{
|
{
|
||||||
@ -41,5 +44,29 @@ namespace SessionCompanion.Controllers
|
|||||||
Message = "User name not found or incorrect password"
|
Message = "User name not found or incorrect password"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Metoda rejestruje podanego użytkownika
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model"> Model uzytkownika do zarejestrowania </param>
|
||||||
|
/// <returns> SuccessResponse/ErrorResponse </returns>
|
||||||
|
[HttpPost("register")]
|
||||||
|
|
||||||
|
public async Task<Either<SuccessResponse, ErrorResponse>> Register(UserViewModel model)
|
||||||
|
{
|
||||||
|
if(!ModelState.IsValid)
|
||||||
|
return new ErrorResponse()
|
||||||
|
{
|
||||||
|
StatusCode = 400,
|
||||||
|
Message = "Given model is incorect"
|
||||||
|
};
|
||||||
|
|
||||||
|
await _service.Create(model);
|
||||||
|
await _service.SaveAsync();
|
||||||
|
|
||||||
|
return new SuccessResponse("User created");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user