diff options
author | crupest <crupest@outlook.com> | 2021-02-13 15:46:02 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-13 15:46:02 +0800 |
commit | 4538aa0be40316a967d6fbcbc08bc9670b9bbcf0 (patch) | |
tree | 9a3b573c2325fa500b565f82f734bd7540f765c9 /BackEnd/Timeline/Controllers | |
parent | 01c3c5800f9b8a7b89d98b28ea748d496497c0b2 (diff) | |
download | timeline-4538aa0be40316a967d6fbcbc08bc9670b9bbcf0.tar.gz timeline-4538aa0be40316a967d6fbcbc08bc9670b9bbcf0.tar.bz2 timeline-4538aa0be40316a967d6fbcbc08bc9670b9bbcf0.zip |
feat: Add timeline manageable.
Diffstat (limited to 'BackEnd/Timeline/Controllers')
5 files changed, 38 insertions, 9 deletions
diff --git a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs index 16793de6..e2a08dcb 100644 --- a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs +++ b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
+using Timeline.Entities;
using Timeline.Models.Http;
using Timeline.Models.Mapper;
using Timeline.Models.Validation;
@@ -28,6 +29,11 @@ namespace Timeline.Controllers _timelineMapper = timelineMapper;
}
+ private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
+ {
+ return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), this.UserHasPermission(UserPermission.AllTimelineManagement));
+ }
+
/// <summary>
/// Get bookmark list in order.
/// </summary>
@@ -40,7 +46,7 @@ namespace Timeline.Controllers {
var ids = await _service.GetBookmarks(this.GetUserId());
var timelines = await _timelineService.GetTimelineList(ids);
- return await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
+ return await Map(timelines);
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index ea012f76..f582e74b 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Timeline.Auth;
+using Timeline.Entities;
using Timeline.Models.Http;
using Timeline.Models.Mapper;
using Timeline.Models.Validation;
@@ -28,6 +29,11 @@ namespace Timeline.Controllers _timelineMapper = timelineMapper;
}
+ private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
+ {
+ return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), this.UserHasPermission(UserPermission.AllTimelineManagement));
+ }
+
/// <summary>
/// Get all highlight timelines.
/// </summary>
@@ -38,7 +44,7 @@ namespace Timeline.Controllers {
var ids = await _service.GetHighlightTimelines();
var timelines = await _timelineService.GetTimelineList(ids);
- return await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
+ return await Map(timelines);
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/SearchController.cs b/BackEnd/Timeline/Controllers/SearchController.cs index dec876b6..b2266c18 100644 --- a/BackEnd/Timeline/Controllers/SearchController.cs +++ b/BackEnd/Timeline/Controllers/SearchController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
+using Timeline.Entities;
using Timeline.Models.Http;
using Timeline.Models.Mapper;
using Timeline.Services;
@@ -28,6 +29,11 @@ namespace Timeline.Controllers _userMapper = userMapper;
}
+ private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
+ {
+ return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), this.UserHasPermission(UserPermission.AllTimelineManagement));
+ }
+
/// <summary>
/// Search timelines whose name or title contains query string case-insensitively.
/// </summary>
@@ -40,7 +46,7 @@ namespace Timeline.Controllers {
var searchResult = await _service.SearchTimeline(query);
var timelines = searchResult.Items.Select(i => i.Item).ToList();
- return await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
+ return await Map(timelines);
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs index 8479ca83..b20ab227 100644 --- a/BackEnd/Timeline/Controllers/TimelineController.cs +++ b/BackEnd/Timeline/Controllers/TimelineController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+using Timeline.Entities;
using Timeline.Filters;
using Timeline.Models;
using Timeline.Models.Http;
@@ -43,6 +44,16 @@ namespace Timeline.Controllers private bool UserHasAllTimelineManagementPermission => this.UserHasPermission(UserPermission.AllTimelineManagement);
+ private Task<HttpTimeline> Map(TimelineEntity timeline)
+ {
+ return _timelineMapper.MapToHttp(timeline, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ }
+
+ private Task<List<HttpTimeline>> Map(List<TimelineEntity> timelines)
+ {
+ return _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ }
+
/// <summary>
/// List all timelines.
/// </summary>
@@ -102,7 +113,7 @@ namespace Timeline.Controllers }
var timelines = await _service.GetTimelines(relationship, visibilityFilter);
- var result = await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
+ var result = await Map(timelines);
return result;
}
@@ -118,7 +129,7 @@ namespace Timeline.Controllers {
var timelineId = await _service.GetTimelineIdByName(timeline);
var t = await _service.GetTimeline(timelineId);
- var result = await _timelineMapper.MapToHttp(t, Url, this.GetOptionalUserId());
+ var result = await Map(t);
return result;
}
@@ -147,7 +158,7 @@ namespace Timeline.Controllers {
await _service.ChangeProperty(timelineId, _mapper.Map<TimelineChangePropertyParams>(body));
var t = await _service.GetTimeline(timelineId);
- var result = await _timelineMapper.MapToHttp(t, Url, this.GetOptionalUserId());
+ var result = await Map(t);
return result;
}
catch (EntityAlreadyExistException)
@@ -237,7 +248,7 @@ namespace Timeline.Controllers try
{
var timeline = await _service.CreateTimeline(body.Name, userId);
- var result = await _timelineMapper.MapToHttp(timeline, Url, this.GetOptionalUserId());
+ var result = await Map(timeline);
return result;
}
catch (EntityAlreadyExistException e) when (e.EntityName == EntityNames.Timeline)
diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index 7e3d6900..4026d551 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -49,9 +49,9 @@ namespace Timeline.Controllers return _timelineMapper.MapToHttp(post, timelineName, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
}
- private Task<List<HttpTimelinePost>> Map(List<TimelinePostEntity> post, string timelineName)
+ private Task<List<HttpTimelinePost>> Map(List<TimelinePostEntity> posts, string timelineName)
{
- return _timelineMapper.MapToHttp(post, timelineName, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
+ return _timelineMapper.MapToHttp(posts, timelineName, Url, this.GetOptionalUserId(), UserHasAllTimelineManagementPermission);
}
/// <summary>
|