Add user service and controller
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 50s
All checks were successful
Game Ideas build for PR / build_blazor_app (pull_request) Successful in 50s
This commit is contained in:
@@ -10,7 +10,8 @@ namespace GameIdeas.WebAPI.Controllers;
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UserController(
|
||||
IUserService userService,
|
||||
IUserReadService userReadService,
|
||||
IUserWriteService userWriteService,
|
||||
ILoggerFactory loggerFactory) : Controller
|
||||
{
|
||||
private readonly ILogger<UserController> logger = loggerFactory.CreateLogger<UserController>();
|
||||
@@ -20,7 +21,7 @@ public class UserController(
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await userService.Login(model));
|
||||
return Ok(await userReadService.Login(model));
|
||||
}
|
||||
catch (UserInvalidException e)
|
||||
{
|
||||
@@ -45,7 +46,7 @@ public class UserController(
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await userService.GetRoles());
|
||||
return Ok(await userReadService.GetRoles());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -60,7 +61,7 @@ public class UserController(
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(await userService.GetUsers(filter));
|
||||
return Ok(await userReadService.GetUsers(filter));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -68,4 +69,49 @@ public class UserController(
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Roles = GlobalConstants.ADMINISTRATOR)]
|
||||
[HttpPost("Create")]
|
||||
public async Task<ActionResult<string>> CreateUser([FromBody] UserDto user)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Created("/Create", await userWriteService.CreateUser(user));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Internal error while create user");
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Roles = GlobalConstants.ADMINISTRATOR)]
|
||||
[HttpPut("Update/{userId}")]
|
||||
public async Task<ActionResult<string>> UpdateUser(string userId, [FromBody] UserDto user)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Created("/Update", await userWriteService.UpdateUser(userId, user));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Internal error while update user");
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Roles = GlobalConstants.ADMINISTRATOR)]
|
||||
[HttpDelete("Delete/{userId}")]
|
||||
public async Task<ActionResult<string>> DeleteUser(string userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Created("/Delete", await userWriteService.DeleteUser(userId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Internal error while delete user");
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user