From df1ef1e21d8d889a2c9abd440039533c6a43818f Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Jan 2021 16:23:20 +0800 Subject: 史诗级重构! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackEnd/Timeline/Services/BookmarkTimelineService.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'BackEnd/Timeline/Services/BookmarkTimelineService.cs') diff --git a/BackEnd/Timeline/Services/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/BookmarkTimelineService.cs index 2ec3af62..380e1909 100644 --- a/BackEnd/Timeline/Services/BookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/BookmarkTimelineService.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Timeline.Entities; -using Timeline.Models; using Timeline.Services.Exceptions; namespace Timeline.Services @@ -30,9 +29,9 @@ namespace Timeline.Services /// Get bookmarks of a user. /// /// User id of bookmark owner. - /// Bookmarks in order. + /// Id of Bookmark timelines in order. /// Thrown when user does not exist. - Task> GetBookmarks(long userId); + Task> GetBookmarks(long userId); /// /// Add a bookmark to tail to a user. @@ -75,9 +74,9 @@ namespace Timeline.Services { private readonly DatabaseContext _database; private readonly IBasicUserService _userService; - private readonly ITimelineService _timelineService; + private readonly IBasicTimelineService _timelineService; - public BookmarkTimelineService(DatabaseContext database, IBasicUserService userService, ITimelineService timelineService) + public BookmarkTimelineService(DatabaseContext database, IBasicUserService userService, IBasicTimelineService timelineService) { _database = database; _userService = userService; @@ -109,21 +108,14 @@ namespace Timeline.Services await _database.SaveChangesAsync(); } - public async Task> GetBookmarks(long userId) + public async Task> GetBookmarks(long userId) { if (!await _userService.CheckUserExistence(userId)) throw new UserNotExistException(userId); var entities = await _database.BookmarkTimelines.Where(t => t.UserId == userId).OrderBy(t => t.Rank).Select(t => new { t.TimelineId }).ToListAsync(); - List result = new(); - - foreach (var entity in entities) - { - result.Add(await _timelineService.GetTimelineById(entity.TimelineId)); - } - - return result; + return entities.Select(e => e.TimelineId).ToList(); } public async Task MoveBookmark(long userId, string timelineName, long newPosition) -- cgit v1.2.3