diff options
| author | crupest <crupest@outlook.com> | 2021-01-03 19:07:35 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2021-01-03 19:07:35 +0800 |
| commit | 69d56e560fc280e9a570e858c29878514b1b5575 (patch) | |
| tree | 1ac062fa80c8e6886f1eb86a4b1e4c5abc6d953d | |
| parent | 4f301a32778fb006bcf2cc183c7118ca5961f7ba (diff) | |
| download | timeline-69d56e560fc280e9a570e858c29878514b1b5575.tar.gz timeline-69d56e560fc280e9a570e858c29878514b1b5575.tar.bz2 timeline-69d56e560fc280e9a570e858c29878514b1b5575.zip | |
fix: Fix a critical bug in bookmark timeline service.
It used to create two entry with the same timeline. Now it will not create a duplicate one.
| -rw-r--r-- | BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs | 13 | ||||
| -rw-r--r-- | BackEnd/Timeline/Services/BookmarkTimelineService.cs | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs b/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs index 1b8bff63..849936ec 100644 --- a/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs +++ b/BackEnd/Timeline.Tests/Services/BookmarkTimelineServiceTest.cs @@ -85,5 +85,18 @@ namespace Timeline.Tests.Services await _service.RemoveBookmark(userId, "t3");
(await _service.GetBookmarks(userId)).Should().BeEmpty();
}
+
+ [Fact]
+ public async Task AddExist_Should_DoNothing()
+ {
+ var userId = await _userService.GetUserIdByUsername("user");
+
+ await _timelineService.CreateTimeline("t", userId);
+
+ await _service.AddBookmark(userId, "t");
+ await _service.AddBookmark(userId, "t");
+
+ (await _service.GetBookmarks(userId)).Should().HaveCount(1);
+ }
}
}
diff --git a/BackEnd/Timeline/Services/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/BookmarkTimelineService.cs index 09438193..2ec3af62 100644 --- a/BackEnd/Timeline/Services/BookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/BookmarkTimelineService.cs @@ -94,6 +94,11 @@ namespace Timeline.Services var timelineId = await _timelineService.GetTimelineIdByName(timelineName);
+ if (await _database.BookmarkTimelines.SingleOrDefaultAsync(t => t.TimelineId == timelineId) is not null)
+ {
+ return;
+ }
+
_database.BookmarkTimelines.Add(new BookmarkTimelineEntity
{
TimelineId = timelineId,
|
