diff options
Diffstat (limited to 'BackEnd/Timeline/Controllers')
7 files changed, 44 insertions, 55 deletions
diff --git a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs index d941013f..e7ffa5c5 100644 --- a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs +++ b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs @@ -8,7 +8,6 @@ using Timeline.Models.Validation; using Timeline.Services.Api;
using Timeline.Services.Mapper;
using Timeline.Services.Timeline;
-using Timeline.Services.User;
namespace Timeline.Controllers
{
@@ -21,18 +20,18 @@ namespace Timeline.Controllers {
private readonly IBookmarkTimelineService _service;
private readonly ITimelineService _timelineService;
- private readonly TimelineMapper _timelineMapper;
+ private readonly IGenericMapper _mapper;
- public BookmarkTimelineController(IBookmarkTimelineService service, ITimelineService timelineService, TimelineMapper timelineMapper)
+ public BookmarkTimelineController(IBookmarkTimelineService service, ITimelineService timelineService, IGenericMapper mapper)
{
_service = service;
_timelineService = timelineService;
- _timelineMapper = timelineMapper;
+ _mapper = mapper;
}
private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
{
- return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), this.UserHasPermission(UserPermission.AllTimelineManagement));
+ return _mapper.MapListAsync<HttpTimeline>(timelines, Url, User);
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index 4facc4a1..4e739056 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -21,18 +21,18 @@ namespace Timeline.Controllers {
private readonly IHighlightTimelineService _service;
private readonly ITimelineService _timelineService;
- private readonly TimelineMapper _timelineMapper;
+ private readonly IGenericMapper _mapper;
- public HighlightTimelineController(IHighlightTimelineService service, ITimelineService timelineService, TimelineMapper timelineMapper)
+ public HighlightTimelineController(IHighlightTimelineService service, ITimelineService timelineService, IGenericMapper mapper)
{
_service = service;
_timelineService = timelineService;
- _timelineMapper = timelineMapper;
+ _mapper = mapper;
}
private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
{
- return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), this.UserHasPermission(UserPermission.AllTimelineManagement));
+ return _mapper.MapListAsync<HttpTimeline>(timelines, Url, User);
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/SearchController.cs b/BackEnd/Timeline/Controllers/SearchController.cs index 33e50e59..76f3d8f2 100644 --- a/BackEnd/Timeline/Controllers/SearchController.cs +++ b/BackEnd/Timeline/Controllers/SearchController.cs @@ -7,7 +7,6 @@ using Timeline.Entities; using Timeline.Models.Http;
using Timeline.Services.Api;
using Timeline.Services.Mapper;
-using Timeline.Services.User;
namespace Timeline.Controllers
{
@@ -20,19 +19,17 @@ namespace Timeline.Controllers public class SearchController : Controller
{
private readonly ISearchService _service;
- private readonly TimelineMapper _timelineMapper;
- private readonly UserMapper _userMapper;
+ private readonly IGenericMapper _mapper;
- public SearchController(ISearchService service, TimelineMapper timelineMapper, UserMapper userMapper)
+ public SearchController(ISearchService service, IGenericMapper mapper)
{
_service = service;
- _timelineMapper = timelineMapper;
- _userMapper = userMapper;
+ _mapper = mapper;
}
private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
{
- return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), this.UserHasPermission(UserPermission.AllTimelineManagement));
+ return _mapper.MapListAsync<HttpTimeline>(timelines, Url, User);
}
/// <summary>
@@ -62,7 +59,7 @@ namespace Timeline.Controllers {
var searchResult = await _service.SearchUser(query);
var users = searchResult.Items.Select(i => i.Item).ToList();
- return await _userMapper.MapToHttp(users, Url);
+ return await _mapper.MapListAsync<HttpUser>(users, Url, User);
}
}
}
diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs index c6b1f9ad..497d7893 100644 --- a/BackEnd/Timeline/Controllers/TimelineController.cs +++ b/BackEnd/Timeline/Controllers/TimelineController.cs @@ -1,5 +1,4 @@ -using AutoMapper;
-using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
@@ -28,18 +27,15 @@ namespace Timeline.Controllers {
private readonly IUserService _userService;
private readonly ITimelineService _service;
-
- private readonly TimelineMapper _timelineMapper;
- private readonly IMapper _mapper;
+ private readonly IGenericMapper _mapper;
/// <summary>
///
/// </summary>
- public TimelineController(IUserService userService, ITimelineService service, TimelineMapper timelineMapper, IMapper mapper)
+ public TimelineController(IUserService userService, ITimelineService service, IGenericMapper mapper)
{
_userService = userService;
_service = service;
- _timelineMapper = timelineMapper;
_mapper = mapper;
}
@@ -47,12 +43,12 @@ namespace Timeline.Controllers private Task<HttpTimeline> Map(TimelineEntity timeline)
{
- return _timelineMapper.MapToHttp(timeline, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ return _mapper.MapAsync<HttpTimeline>(timeline, Url, User);
}
private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
{
- return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ return _mapper.MapListAsync<HttpTimeline>(timelines, Url, User);
}
/// <summary>
@@ -157,7 +153,7 @@ namespace Timeline.Controllers try
{
- await _service.ChangePropertyAsync(timelineId, _mapper.Map<TimelineChangePropertyParams>(body));
+ await _service.ChangePropertyAsync(timelineId, _mapper.AutoMapperMap<TimelineChangePropertyParams>(body));
var t = await _service.GetTimelineAsync(timelineId);
var result = await Map(t);
return result;
diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index cea873b0..2e1ed3a9 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -31,31 +31,31 @@ namespace Timeline.Controllers private readonly ITimelineService _timelineService;
private readonly ITimelinePostService _postService;
- private readonly TimelineMapper _timelineMapper;
+ private readonly IGenericMapper _mapper;
private readonly MarkdownProcessor _markdownProcessor;
/// <summary>
///
/// </summary>
- public TimelinePostController(ITimelineService timelineService, ITimelinePostService timelinePostService, TimelineMapper timelineMapper, MarkdownProcessor markdownProcessor)
+ public TimelinePostController(ITimelineService timelineService, ITimelinePostService timelinePostService, IGenericMapper mapper, MarkdownProcessor markdownProcessor)
{
_timelineService = timelineService;
_postService = timelinePostService;
- _timelineMapper = timelineMapper;
+ _mapper = mapper;
_markdownProcessor = markdownProcessor;
}
private bool UserHasAllTimelineManagementPermission => this.UserHasPermission(UserPermission.AllTimelineManagement);
- private Task<HttpTimelinePost> Map(TimelinePostEntity post, string timelineName)
+ private Task<HttpTimelinePost> Map(TimelinePostEntity post)
{
- return _timelineMapper.MapToHttp(post, timelineName, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ return _mapper.MapAsync<HttpTimelinePost>(post, Url, User);
}
- private Task<List<HttpTimelinePost>> Map(List<TimelinePostEntity> posts, string timelineName)
+ private Task<List<HttpTimelinePost>> Map(List<TimelinePostEntity> posts)
{
- return _timelineMapper.MapToHttp(posts, timelineName, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ return _mapper.MapListAsync<HttpTimelinePost>(posts, Url, User);
}
/// <summary>
@@ -80,7 +80,7 @@ namespace Timeline.Controllers var posts = await _postService.GetPostsAsync(timelineId, modifiedSince, includeDeleted ?? false);
- var result = await Map(posts, timeline);
+ var result = await Map(posts);
return result;
}
@@ -104,7 +104,7 @@ namespace Timeline.Controllers }
var post = await _postService.GetPostAsync(timelineId, postId);
- var result = await Map(post, timeline);
+ var result = await Map(post);
return result;
}
@@ -213,7 +213,7 @@ namespace Timeline.Controllers try
{
var post = await _postService.CreatePostAsync(timelineId, userId, createRequest);
- var result = await Map(post, timeline);
+ var result = await Map(post);
return result;
}
catch (TimelinePostCreateDataException e)
@@ -245,7 +245,7 @@ namespace Timeline.Controllers }
var entity = await _postService.PatchPostAsync(timelineId, post, new TimelinePostPatchRequest { Time = body.Time, Color = body.Color });
- var result = await Map(entity, timeline);
+ var result = await Map(entity);
return Ok(result);
}
diff --git a/BackEnd/Timeline/Controllers/TokenController.cs b/BackEnd/Timeline/Controllers/TokenController.cs index 3b35fa13..e728ae6d 100644 --- a/BackEnd/Timeline/Controllers/TokenController.cs +++ b/BackEnd/Timeline/Controllers/TokenController.cs @@ -25,15 +25,15 @@ namespace Timeline.Controllers {
private readonly IUserTokenManager _userTokenManager;
private readonly ILogger<TokenController> _logger;
- private readonly UserMapper _userMapper;
+ private readonly IGenericMapper _mapper;
private readonly IClock _clock;
/// <summary></summary>
- public TokenController(IUserTokenManager userTokenManager, ILogger<TokenController> logger, UserMapper userMapper, IClock clock)
+ public TokenController(IUserTokenManager userTokenManager, ILogger<TokenController> logger, IGenericMapper mapper, IClock clock)
{
_userTokenManager = userTokenManager;
_logger = logger;
- _userMapper = userMapper;
+ _mapper = mapper;
_clock = clock;
}
@@ -72,7 +72,7 @@ namespace Timeline.Controllers return new HttpCreateTokenResponse
{
Token = result.Token,
- User = await _userMapper.MapToHttp(result.User, Url)
+ User = await _mapper.MapAsync<HttpUser>(result.User, Url, User)
};
}
catch (UserNotExistException e)
@@ -113,7 +113,7 @@ namespace Timeline.Controllers ("Username", result.Username), ("Token", request.Token)));
return new HttpVerifyTokenResponse
{
- User = await _userMapper.MapToHttp(result, Url)
+ User = await _mapper.MapAsync<HttpUser>(result, Url, User)
};
}
catch (UserTokenTimeExpiredException e)
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);
}
}
|