From 84079146cf4c179cfe2770386dcd9f1cd1e7b14a Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 Mar 2020 03:04:23 +0800 Subject: ... --- Timeline/Controllers/ControllerAuthExtensions.cs | 6 +-- Timeline/Controllers/PersonalTimelineController.cs | 10 ++--- .../Controllers/Testing/TestingAuthController.cs | 4 +- Timeline/Controllers/TimelineController.cs | 43 +++++++++++++--------- Timeline/Controllers/TokenController.cs | 10 ++--- Timeline/Controllers/UserAvatarController.cs | 18 ++++----- Timeline/Controllers/UserController.cs | 16 ++++---- 7 files changed, 58 insertions(+), 49 deletions(-) (limited to 'Timeline/Controllers') diff --git a/Timeline/Controllers/ControllerAuthExtensions.cs b/Timeline/Controllers/ControllerAuthExtensions.cs index 00a65454..9c7ea601 100644 --- a/Timeline/Controllers/ControllerAuthExtensions.cs +++ b/Timeline/Controllers/ControllerAuthExtensions.cs @@ -1,10 +1,10 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Security.Claims; -using Timeline.Auth; -using static Timeline.Resources.Controllers.ControllerAuthExtensions; +using TimelineApp.Auth; +using static TimelineApp.Resources.Controllers.ControllerAuthExtensions; -namespace Timeline.Controllers +namespace TimelineApp.Controllers { public static class ControllerAuthExtensions { diff --git a/Timeline/Controllers/PersonalTimelineController.cs b/Timeline/Controllers/PersonalTimelineController.cs index cef04a97..0c0694cb 100644 --- a/Timeline/Controllers/PersonalTimelineController.cs +++ b/Timeline/Controllers/PersonalTimelineController.cs @@ -4,12 +4,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Threading.Tasks; -using Timeline.Filters; -using Timeline.Models.Http; -using Timeline.Models.Validation; -using Timeline.Services; +using TimelineApp.Filters; +using TimelineApp.Models.Http; +using TimelineApp.Models.Validation; +using TimelineApp.Services; -namespace Timeline.Controllers +namespace TimelineApp.Controllers { [ApiController] [CatchTimelineNotExistException] diff --git a/Timeline/Controllers/Testing/TestingAuthController.cs b/Timeline/Controllers/Testing/TestingAuthController.cs index 4d3b3ec7..6061f003 100644 --- a/Timeline/Controllers/Testing/TestingAuthController.cs +++ b/Timeline/Controllers/Testing/TestingAuthController.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Timeline.Auth; +using TimelineApp.Auth; -namespace Timeline.Controllers.Testing +namespace TimelineApp.Controllers.Testing { [Route("testing/auth")] [ApiController] diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index 85ccb5c1..00e9a860 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using AutoMapper; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -6,12 +7,13 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; -using Timeline.Filters; -using Timeline.Models.Http; -using Timeline.Models.Validation; -using Timeline.Services; +using TimelineApp.Filters; +using TimelineApp.Models; +using TimelineApp.Models.Http; +using TimelineApp.Models.Validation; +using TimelineApp.Services; -namespace Timeline.Controllers +namespace TimelineApp.Controllers { [ApiController] [CatchTimelineNotExistException] @@ -22,11 +24,14 @@ namespace Timeline.Controllers private readonly IUserService _userService; private readonly ITimelineService _service; - public TimelineController(ILogger logger, IUserService userService, ITimelineService service) + private readonly IMapper _mapper; + + public TimelineController(ILogger logger, IUserService userService, ITimelineService service, IMapper mapper) { _logger = logger; _userService = userService; _service = service; + _mapper = mapper; } [HttpGet("timelines")] @@ -81,27 +86,31 @@ namespace Timeline.Controllers } } - var result = await _service.GetTimelines(relationship, visibilityFilter); - result.ForEach(t => t.FillLinks(Url)); - return Ok(result); + var timelines = await _service.GetTimelines(relationship, visibilityFilter); + var result = _mapper.Map>(timelines); + return result; } [HttpGet("timelines/{name}")] public async Task> TimelineGet([FromRoute][TimelineName] string name) { - var result = (await _service.GetTimeline(name)).FillLinks(Url); - return Ok(result); + var timeline = await _service.GetTimeline(name); + var result = _mapper.Map(timeline); + return result; } [HttpGet("timelines/{name}/posts")] - public async Task>> PostListGet([FromRoute][TimelineName] string name) + public async Task>> PostListGet([FromRoute][TimelineName] string name) { if (!this.IsAdministrator() && !await _service.HasReadPermission(name, this.GetOptionalUserId())) { return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } - return await _service.GetPosts(name); + var posts = await _service.GetPosts(name); + var result = _mapper.Map>(posts); + + return result; } [HttpPost("timelines/{name}/posts")] @@ -120,7 +129,7 @@ namespace Timeline.Controllers [HttpDelete("timelines/{name}/posts/{id}")] [Authorize] - public async Task PostDelete([FromRoute][TimelineName] string name, [FromRoute] long id) + public async Task> PostDelete([FromRoute][TimelineName] string name, [FromRoute] long id) { try { @@ -129,11 +138,11 @@ namespace Timeline.Controllers return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } await _service.DeletePost(name, id); - return Ok(CommonDeleteResponse.Delete()); + return CommonDeleteResponse.Delete(); } catch (TimelinePostNotExistException) { - return Ok(CommonDeleteResponse.NotExist()); + return CommonDeleteResponse.NotExist(); } } diff --git a/Timeline/Controllers/TokenController.cs b/Timeline/Controllers/TokenController.cs index 1fb0b17a..47dcc0aa 100644 --- a/Timeline/Controllers/TokenController.cs +++ b/Timeline/Controllers/TokenController.cs @@ -5,12 +5,12 @@ using Microsoft.Extensions.Logging; using System; using System.Globalization; using System.Threading.Tasks; -using Timeline.Helpers; -using Timeline.Models.Http; -using Timeline.Services; -using static Timeline.Resources.Controllers.TokenController; +using TimelineApp.Helpers; +using TimelineApp.Models.Http; +using TimelineApp.Services; +using static TimelineApp.Resources.Controllers.TokenController; -namespace Timeline.Controllers +namespace TimelineApp.Controllers { [Route("token")] [ApiController] diff --git a/Timeline/Controllers/UserAvatarController.cs b/Timeline/Controllers/UserAvatarController.cs index f4f3db3e..089cef94 100644 --- a/Timeline/Controllers/UserAvatarController.cs +++ b/Timeline/Controllers/UserAvatarController.cs @@ -6,15 +6,15 @@ using Microsoft.Net.Http.Headers; using System; using System.Linq; using System.Threading.Tasks; -using Timeline.Auth; -using Timeline.Filters; -using Timeline.Helpers; -using Timeline.Models.Http; -using Timeline.Models.Validation; -using Timeline.Services; -using static Timeline.Resources.Controllers.UserAvatarController; - -namespace Timeline.Controllers +using TimelineApp.Auth; +using TimelineApp.Filters; +using TimelineApp.Helpers; +using TimelineApp.Models.Http; +using TimelineApp.Models.Validation; +using TimelineApp.Services; +using static TimelineApp.Resources.Controllers.UserAvatarController; + +namespace TimelineApp.Controllers { [ApiController] public class UserAvatarController : Controller diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index a3e8d816..4106c750 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -5,15 +5,15 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Linq; using System.Threading.Tasks; -using Timeline.Auth; -using Timeline.Helpers; -using Timeline.Models.Http; -using Timeline.Models.Validation; -using Timeline.Services; -using static Timeline.Resources.Controllers.UserController; -using static Timeline.Resources.Messages; +using TimelineApp.Auth; +using TimelineApp.Helpers; +using TimelineApp.Models.Http; +using TimelineApp.Models.Validation; +using TimelineApp.Services; +using static TimelineApp.Resources.Controllers.UserController; +using static TimelineApp.Resources.Messages; -namespace Timeline.Controllers +namespace TimelineApp.Controllers { [ApiController] public class UserController : Controller -- cgit v1.2.3