diff options
author | 杨宇千 <crupest@outlook.com> | 2019-10-28 23:35:00 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-10-28 23:35:00 +0800 |
commit | fbaa8cab95a91b887bbd2d108d27c5abb38e4e29 (patch) | |
tree | 97ed1fa767e1492cd3df292247d8fd3e47252882 /Timeline/Controllers | |
parent | 294807481dd42dc3c660e29630b36462e7bcfaaf (diff) | |
download | timeline-fbaa8cab95a91b887bbd2d108d27c5abb38e4e29.tar.gz timeline-fbaa8cab95a91b887bbd2d108d27c5abb38e4e29.tar.bz2 timeline-fbaa8cab95a91b887bbd2d108d27c5abb38e4e29.zip |
Add UserDetailController unit tests.
Diffstat (limited to 'Timeline/Controllers')
-rw-r--r-- | Timeline/Controllers/UserDetailController.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Timeline/Controllers/UserDetailController.cs b/Timeline/Controllers/UserDetailController.cs new file mode 100644 index 00000000..ef13b462 --- /dev/null +++ b/Timeline/Controllers/UserDetailController.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNetCore.Mvc;
+using System.Threading.Tasks;
+using Timeline.Filters;
+using Timeline.Models.Validation;
+using Timeline.Services;
+using System.ComponentModel.DataAnnotations;
+
+namespace Timeline.Controllers
+{
+ [ApiController]
+ public class UserDetailController : Controller
+ {
+ private readonly IUserDetailService _service;
+
+ public UserDetailController(IUserDetailService service)
+ {
+ _service = service;
+ }
+
+ [HttpGet("users/{username}/nickname")]
+ [CatchUserNotExistException]
+ public async Task<ActionResult<string>> GetNickname([FromRoute][Username] string username)
+ {
+ return Ok(await _service.GetNickname(username));
+ }
+
+ [HttpPut("users/{username}/nickname")]
+ [CatchUserNotExistException]
+ public async Task<ActionResult> PutNickname([FromRoute][Username] string username,
+ [FromBody][StringLength(10, MinimumLength = 1)] string body)
+ {
+ await _service.SetNickname(username, body);
+ return Ok();
+ }
+
+ [HttpDelete("users/{username}/nickname")]
+ [CatchUserNotExistException]
+ public async Task<ActionResult> DeleteNickname([FromRoute][Username] string username)
+ {
+ await _service.SetNickname(username, null);
+ return Ok();
+ }
+ }
+}
|