aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Controllers/UserController.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-04-28 19:20:40 +0800
committercrupest <crupest@outlook.com>2021-04-28 19:20:40 +0800
commite16c958e5ba47834dc1624e09ed8e5074a60d1c6 (patch)
treeaf8de5669e0ade7d1425d7c5599d438a6cf1c38c /BackEnd/Timeline/Controllers/UserController.cs
parent29453339a7ba744dc19f730ffbd71d6bff01f25b (diff)
downloadtimeline-e16c958e5ba47834dc1624e09ed8e5074a60d1c6.tar.gz
timeline-e16c958e5ba47834dc1624e09ed8e5074a60d1c6.tar.bz2
timeline-e16c958e5ba47834dc1624e09ed8e5074a60d1c6.zip
refator: ...
Diffstat (limited to 'BackEnd/Timeline/Controllers/UserController.cs')
-rw-r--r--BackEnd/Timeline/Controllers/UserController.cs21
1 files changed, 9 insertions, 12 deletions
diff --git a/BackEnd/Timeline/Controllers/UserController.cs b/BackEnd/Timeline/Controllers/UserController.cs
index 38d5d70c..615eac2d 100644
--- a/BackEnd/Timeline/Controllers/UserController.cs
+++ b/BackEnd/Timeline/Controllers/UserController.cs
@@ -1,4 +1,3 @@
-using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -28,17 +27,15 @@ namespace Timeline.Controllers
private readonly IUserService _userService;
private readonly IUserPermissionService _userPermissionService;
private readonly IUserDeleteService _userDeleteService;
- private readonly UserMapper _userMapper;
- private readonly IMapper _mapper;
+ private readonly IGenericMapper _mapper;
/// <summary></summary>
- public UserController(ILogger<UserController> logger, IUserService userService, IUserPermissionService userPermissionService, IUserDeleteService userDeleteService, UserMapper userMapper, IMapper mapper)
+ public UserController(ILogger<UserController> logger, IUserService userService, IUserPermissionService userPermissionService, IUserDeleteService userDeleteService, IGenericMapper mapper)
{
_logger = logger;
_userService = userService;
_userPermissionService = userPermissionService;
_userDeleteService = userDeleteService;
- _userMapper = userMapper;
_mapper = mapper;
}
@@ -53,7 +50,7 @@ namespace Timeline.Controllers
public async Task<ActionResult<List<HttpUser>>> List()
{
var users = await _userService.GetUsersAsync();
- var result = await _userMapper.MapToHttp(users, Url);
+ var result = await _mapper.MapListAsync<HttpUser>(users, Url, User);
return result;
}
@@ -72,7 +69,7 @@ namespace Timeline.Controllers
{
var user = await _userService.CreateUserAsync(
new CreateUserParams(body.Username, body.Password) { Nickname = body.Nickname });
- return await _userMapper.MapToHttp(user, Url);
+ return await _mapper.MapAsync<HttpUser>(user, Url, User);
}
catch (EntityAlreadyExistException e) when (e.EntityName == EntityNames.User)
{
@@ -94,7 +91,7 @@ namespace Timeline.Controllers
{
var id = await _userService.GetUserIdByUsernameAsync(username);
var user = await _userService.GetUserAsync(id);
- return await _userMapper.MapToHttp(user, Url);
+ return await _mapper.MapAsync<HttpUser>(user, Url, User);
}
catch (UserNotExistException e)
{
@@ -122,8 +119,8 @@ namespace Timeline.Controllers
try
{
var id = await _userService.GetUserIdByUsernameAsync(username);
- var user = await _userService.ModifyUserAsync(id, _mapper.Map<ModifyUserParams>(body));
- return await _userMapper.MapToHttp(user, Url);
+ var user = await _userService.ModifyUserAsync(id, _mapper.AutoMapperMap<ModifyUserParams>(body));
+ return await _mapper.MapAsync<HttpUser>(user, Url, User);
}
catch (UserNotExistException e)
{
@@ -149,8 +146,8 @@ namespace Timeline.Controllers
return StatusCode(StatusCodes.Status403Forbidden,
ErrorResponse.Common.CustomMessage_Forbid(UserController_Patch_Forbid_Password));
- var user = await _userService.ModifyUserAsync(this.GetUserId(), _mapper.Map<ModifyUserParams>(body));
- return await _userMapper.MapToHttp(user, Url);
+ var user = await _userService.ModifyUserAsync(this.GetUserId(), _mapper.AutoMapperMap<ModifyUserParams>(body));
+ return await _mapper.MapAsync<HttpUser>(user, Url, User);
}
}