aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Controllers
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-31 15:21:58 +0800
committercrupest <crupest@outlook.com>2020-01-31 15:21:58 +0800
commit45a6ca3a189a81060ae44d0764248547fe2b686c (patch)
treebbbac2fe1a6d3ce4c5d2c32553f6d06cb3209172 /Timeline/Controllers
parent038e8dcf461d4d4ebd51c8fdf7680497869f691c (diff)
downloadtimeline-45a6ca3a189a81060ae44d0764248547fe2b686c.tar.gz
timeline-45a6ca3a189a81060ae44d0764248547fe2b686c.tar.bz2
timeline-45a6ca3a189a81060ae44d0764248547fe2b686c.zip
Combine two user info types.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r--Timeline/Controllers/TokenController.cs4
-rw-r--r--Timeline/Controllers/UserController.cs22
2 files changed, 7 insertions, 19 deletions
diff --git a/Timeline/Controllers/TokenController.cs b/Timeline/Controllers/TokenController.cs
index a7f5fbde..1fb0b17a 100644
--- a/Timeline/Controllers/TokenController.cs
+++ b/Timeline/Controllers/TokenController.cs
@@ -59,7 +59,7 @@ namespace Timeline.Controllers
return Ok(new CreateTokenResponse
{
Token = result.Token,
- User = _mapper.Map<UserInfoForAdmin>(result.User)
+ User = _mapper.Map<UserInfo>(result.User)
});
}
catch (UserNotExistException e)
@@ -94,7 +94,7 @@ namespace Timeline.Controllers
("Username", result.Username), ("Token", request.Token)));
return Ok(new VerifyTokenResponse
{
- User = _mapper.Map<UserInfoForAdmin>(result)
+ User = _mapper.Map<UserInfo>(result)
});
}
catch (UserTokenTimeExpireException e)
diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs
index fa73c6f9..4572296b 100644
--- a/Timeline/Controllers/UserController.cs
+++ b/Timeline/Controllers/UserController.cs
@@ -29,35 +29,23 @@ namespace Timeline.Controllers
_mapper = mapper;
}
- private IUserInfo ConvertToUserInfo(User user, bool administrator)
- {
- if (administrator)
- return _mapper.Map<UserInfoForAdmin>(user);
- else
- return _mapper.Map<UserInfo>(user);
- }
+ private UserInfo ConvertToUserInfo(User user) => _mapper.Map<UserInfo>(user);
[HttpGet("users")]
- public async Task<ActionResult<IUserInfo[]>> List()
+ public async Task<ActionResult<UserInfo[]>> List()
{
var users = await _userService.GetUsers();
- var administrator = this.IsAdministrator();
- // Note: the (object) explicit conversion. If not convert,
- // then result is a IUserInfo array and JsonSerializer will
- // treat all element as IUserInfo and deserialize only properties
- // in IUserInfo. So we convert it to object to make an object
- // array so that JsonSerializer use the runtime type.
- var result = users.Select(u => (object)ConvertToUserInfo(u, administrator)).ToArray();
+ var result = users.Select(u => ConvertToUserInfo(u)).ToArray();
return Ok(result);
}
[HttpGet("users/{username}")]
- public async Task<ActionResult<IUserInfo>> Get([FromRoute][Username] string username)
+ public async Task<ActionResult<UserInfo>> Get([FromRoute][Username] string username)
{
try
{
var user = await _userService.GetUserByUsername(username);
- return Ok(ConvertToUserInfo(user, this.IsAdministrator()));
+ return Ok(ConvertToUserInfo(user));
}
catch (UserNotExistException e)
{