diff options
author | 杨宇千 <crupest@outlook.com> | 2019-10-31 15:02:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-31 15:02:03 +0800 |
commit | 37a2e6340ab20de1f9e847d795c0cbec9846de97 (patch) | |
tree | ba42530cf4f13621a7a3a7ff661e383117119883 /Timeline/Controllers/UserDetailController.cs | |
parent | a175f8328d7a6c36464676d54fc50d03e64be0af (diff) | |
parent | 2c3744ab5db476b64a32c19b50153e3e6166b0e6 (diff) | |
download | timeline-37a2e6340ab20de1f9e847d795c0cbec9846de97.tar.gz timeline-37a2e6340ab20de1f9e847d795c0cbec9846de97.tar.bz2 timeline-37a2e6340ab20de1f9e847d795c0cbec9846de97.zip |
Merge pull request #53 from crupest/nickname
Add nickname support.
Diffstat (limited to 'Timeline/Controllers/UserDetailController.cs')
-rw-r--r-- | Timeline/Controllers/UserDetailController.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Timeline/Controllers/UserDetailController.cs b/Timeline/Controllers/UserDetailController.cs new file mode 100644 index 00000000..9de9899e --- /dev/null +++ b/Timeline/Controllers/UserDetailController.cs @@ -0,0 +1,49 @@ +using Microsoft.AspNetCore.Mvc;
+using System.Threading.Tasks;
+using Timeline.Filters;
+using Timeline.Models.Validation;
+using Timeline.Services;
+using System.ComponentModel.DataAnnotations;
+using Microsoft.AspNetCore.Authorization;
+
+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")]
+ [Authorize]
+ [SelfOrAdmin]
+ [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")]
+ [Authorize]
+ [SelfOrAdmin]
+ [CatchUserNotExistException]
+ public async Task<ActionResult> DeleteNickname([FromRoute][Username] string username)
+ {
+ await _service.SetNickname(username, null);
+ return Ok();
+ }
+ }
+}
|