aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/Api
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-04-29 19:29:35 +0800
committercrupest <crupest@outlook.com>2021-04-29 19:29:35 +0800
commitb87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f (patch)
treebf8c16169dce15e78fd41c00a364b028771433e5 /BackEnd/Timeline/Services/Api
parentb4c08ef8e7eb7d3f7d8a37d04fd478326cb75d2c (diff)
downloadtimeline-b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f.tar.gz
timeline-b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f.tar.bz2
timeline-b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f.zip
...
Diffstat (limited to 'BackEnd/Timeline/Services/Api')
-rw-r--r--BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs79
-rw-r--r--BackEnd/Timeline/Services/Api/HighlightTimelineService.cs77
-rw-r--r--BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs64
-rw-r--r--BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs61
-rw-r--r--BackEnd/Timeline/Services/Api/ISearchService.cs33
-rw-r--r--BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs15
-rw-r--r--BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs15
-rw-r--r--BackEnd/Timeline/Services/Api/SearchResult.cs11
-rw-r--r--BackEnd/Timeline/Services/Api/SearchResultItem.cs18
-rw-r--r--BackEnd/Timeline/Services/Api/SearchService.cs55
10 files changed, 229 insertions, 199 deletions
diff --git a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs
index 37b55199..4fc20ecb 100644
--- a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs
+++ b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -10,74 +9,6 @@ using Timeline.Services.User;
namespace Timeline.Services.Api
{
- [Serializable]
- public class InvalidBookmarkException : Exception
- {
- public InvalidBookmarkException() { }
- public InvalidBookmarkException(string message) : base(message) { }
- public InvalidBookmarkException(string message, Exception inner) : base(message, inner) { }
- protected InvalidBookmarkException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
- }
-
- /// <summary>
- /// Service interface that manages timeline bookmarks.
- /// </summary>
- public interface IBookmarkTimelineService
- {
- /// <summary>
- /// Get bookmarks of a user.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <returns>Id of Bookmark timelines in order.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- Task<List<long>> GetBookmarks(long userId);
-
- /// <summary>
- /// Check if a timeline is a bookmark.
- /// </summary>
- /// <param name="userId">The user id.</param>
- /// <param name="timelineId">Timeline id.</param>
- /// <param name="checkUserExistence">If true it will throw when user does not exist.</param>
- /// <param name="checkTimelineExistence">If true it will throw when timeline does not exist.</param>
- /// <returns>True if timeline is a bookmark. Otherwise false.</returns>
- /// <exception cref="UserNotExistException">Throw if user does not exist and <paramref name="checkUserExistence"/> is true.</exception>
- /// <exception cref="TimelineNotExistException">Thrown if timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
- Task<bool> IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true);
-
- /// <summary>
- /// Add a bookmark to tail to a user.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <param name="timelineId">Timeline id.</param>
- /// <returns>True if timeline is added to bookmark. False if it already is.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
- Task<bool> AddBookmark(long userId, long timelineId);
-
- /// <summary>
- /// Remove a bookmark from a user.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <param name="timelineId">Timeline id.</param>
- /// <returns>True if deletion is performed. False if bookmark does not exist.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
- Task<bool> RemoveBookmark(long userId, long timelineId);
-
- /// <summary>
- /// Move bookmark to a new position.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <param name="timelineId">Timeline name.</param>
- /// <param name="newPosition">New position. Starts at 1.</param>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
- /// <exception cref="InvalidBookmarkException">Thrown when the timeline is not a bookmark.</exception>
- Task MoveBookmark(long userId, long timelineId, long newPosition);
- }
-
public class BookmarkTimelineService : IBookmarkTimelineService
{
private readonly DatabaseContext _database;
@@ -91,7 +22,7 @@ namespace Timeline.Services.Api
_timelineService = timelineService;
}
- public async Task<bool> AddBookmark(long userId, long timelineId)
+ public async Task<bool> AddBookmarkAsync(long userId, long timelineId)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -113,7 +44,7 @@ namespace Timeline.Services.Api
return true;
}
- public async Task<List<long>> GetBookmarks(long userId)
+ public async Task<List<long>> GetBookmarksAsync(long userId)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -123,7 +54,7 @@ namespace Timeline.Services.Api
return entities.Select(e => e.TimelineId).ToList();
}
- public async Task<bool> IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true)
+ public async Task<bool> IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true)
{
if (checkUserExistence && !await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -134,7 +65,7 @@ namespace Timeline.Services.Api
return await _database.BookmarkTimelines.AnyAsync(b => b.TimelineId == timelineId && b.UserId == userId);
}
- public async Task MoveBookmark(long userId, long timelineId, long newPosition)
+ public async Task MoveBookmarkAsync(long userId, long timelineId, long newPosition)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -176,7 +107,7 @@ namespace Timeline.Services.Api
await transaction.CommitAsync();
}
- public async Task<bool> RemoveBookmark(long userId, long timelineId)
+ public async Task<bool> RemoveBookmarkAsync(long userId, long timelineId)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
diff --git a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs
index 8224f1fe..a9d831ab 100644
--- a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs
+++ b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs
@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -9,72 +8,6 @@ using Timeline.Services.User;
namespace Timeline.Services.Api
{
-
- [Serializable]
- public class InvalidHighlightTimelineException : Exception
- {
- public InvalidHighlightTimelineException() { }
- public InvalidHighlightTimelineException(string message) : base(message) { }
- public InvalidHighlightTimelineException(string message, Exception inner) : base(message, inner) { }
- protected InvalidHighlightTimelineException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
- }
-
- /// <summary>
- /// Service that controls highlight timeline.
- /// </summary>
- public interface IHighlightTimelineService
- {
- /// <summary>
- /// Get all highlight timelines in order.
- /// </summary>
- /// <returns>Id list of all highlight timelines.</returns>
- Task<List<long>> GetHighlightTimelines();
-
- /// <summary>
- /// Check if a timeline is highlight timeline.
- /// </summary>
- /// <param name="timelineId">Timeline id.</param>
- /// <param name="checkTimelineExistence">If true it will throw if timeline does not exist.</param>
- /// <returns>True if timeline is highlight. Otherwise false.</returns>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
- Task<bool> IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true);
-
- /// <summary>
- /// Add a timeline to highlight list.
- /// </summary>
- /// <param name="timelineId">The timeline id.</param>
- /// <param name="operatorId">The user id of operator.</param>
- /// <returns>True if timeline is actually added to highligh. False if it already is.</returns>
- /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
- /// <exception cref="UserNotExistException">Thrown when user with given operator id does not exist.</exception>
- Task<bool> AddHighlightTimeline(long timelineId, long? operatorId);
-
- /// <summary>
- /// Remove a timeline from highlight list.
- /// </summary>
- /// <param name="timelineId">The timeline id.</param>
- /// <param name="operatorId">The user id of operator.</param>
- /// <returns>True if deletion is actually performed. Otherwise false (timeline was not in the list).</returns>
- /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
- /// <exception cref="UserNotExistException">Thrown when user with given operator id does not exist.</exception>
- Task<bool> RemoveHighlightTimeline(long timelineId, long? operatorId);
-
- /// <summary>
- /// Move a highlight timeline to a new position.
- /// </summary>
- /// <param name="timelineId">The timeline name.</param>
- /// <param name="newPosition">The new position. Starts at 1.</param>
- /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
- /// <exception cref="InvalidHighlightTimelineException">Thrown when given timeline is not a highlight timeline.</exception>
- /// <remarks>
- /// If <paramref name="newPosition"/> is smaller than 1. Then move the timeline to head.
- /// If <paramref name="newPosition"/> is bigger than total count. Then move the timeline to tail.
- /// </remarks>
- Task MoveHighlightTimeline(long timelineId, long newPosition);
- }
-
public class HighlightTimelineService : IHighlightTimelineService
{
private readonly DatabaseContext _database;
@@ -90,7 +23,7 @@ namespace Timeline.Services.Api
_clock = clock;
}
- public async Task<bool> AddHighlightTimeline(long timelineId, long? operatorId)
+ public async Task<bool> AddHighlightTimelineAsync(long timelineId, long? operatorId)
{
if (!await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
@@ -109,14 +42,14 @@ namespace Timeline.Services.Api
return true;
}
- public async Task<List<long>> GetHighlightTimelines()
+ public async Task<List<long>> GetHighlightTimelinesAsync()
{
var entities = await _database.HighlightTimelines.OrderBy(t => t.Order).Select(t => new { t.TimelineId }).ToListAsync();
return entities.Select(e => e.TimelineId).ToList();
}
- public async Task<bool> RemoveHighlightTimeline(long timelineId, long? operatorId)
+ public async Task<bool> RemoveHighlightTimelineAsync(long timelineId, long? operatorId)
{
if (!await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
@@ -144,7 +77,7 @@ namespace Timeline.Services.Api
return true;
}
- public async Task MoveHighlightTimeline(long timelineId, long newPosition)
+ public async Task MoveHighlightTimelineAsync(long timelineId, long newPosition)
{
if (!await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
@@ -183,7 +116,7 @@ namespace Timeline.Services.Api
await transaction.CommitAsync();
}
- public async Task<bool> IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true)
+ public async Task<bool> IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true)
{
if (checkTimelineExistence && !await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
diff --git a/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs
new file mode 100644
index 00000000..18feee54
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs
@@ -0,0 +1,64 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Timeline.Services.Timeline;
+using Timeline.Services.User;
+
+namespace Timeline.Services.Api
+{
+ /// <summary>
+ /// Service interface that manages timeline bookmarks.
+ /// </summary>
+ public interface IBookmarkTimelineService
+ {
+ /// <summary>
+ /// Get bookmarks of a user.
+ /// </summary>
+ /// <param name="userId">User id of bookmark owner.</param>
+ /// <returns>Id of Bookmark timelines in order.</returns>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ Task<List<long>> GetBookmarksAsync(long userId);
+
+ /// <summary>
+ /// Check if a timeline is a bookmark.
+ /// </summary>
+ /// <param name="userId">The user id.</param>
+ /// <param name="timelineId">Timeline id.</param>
+ /// <param name="checkUserExistence">If true it will throw when user does not exist.</param>
+ /// <param name="checkTimelineExistence">If true it will throw when timeline does not exist.</param>
+ /// <returns>True if timeline is a bookmark. Otherwise false.</returns>
+ /// <exception cref="UserNotExistException">Throw if user does not exist and <paramref name="checkUserExistence"/> is true.</exception>
+ /// <exception cref="TimelineNotExistException">Thrown if timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
+ Task<bool> IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true);
+
+ /// <summary>
+ /// Add a bookmark to tail to a user.
+ /// </summary>
+ /// <param name="userId">User id of bookmark owner.</param>
+ /// <param name="timelineId">Timeline id.</param>
+ /// <returns>True if timeline is added to bookmark. False if it already is.</returns>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
+ Task<bool> AddBookmarkAsync(long userId, long timelineId);
+
+ /// <summary>
+ /// Remove a bookmark from a user.
+ /// </summary>
+ /// <param name="userId">User id of bookmark owner.</param>
+ /// <param name="timelineId">Timeline id.</param>
+ /// <returns>True if deletion is performed. False if bookmark does not exist.</returns>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
+ Task<bool> RemoveBookmarkAsync(long userId, long timelineId);
+
+ /// <summary>
+ /// Move bookmark to a new position.
+ /// </summary>
+ /// <param name="userId">User id of bookmark owner.</param>
+ /// <param name="timelineId">Timeline name.</param>
+ /// <param name="newPosition">New position. Starts at 1.</param>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
+ /// <exception cref="InvalidBookmarkException">Thrown when the timeline is not a bookmark.</exception>
+ Task MoveBookmarkAsync(long userId, long timelineId, long newPosition);
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs
new file mode 100644
index 00000000..4f14d19b
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs
@@ -0,0 +1,61 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Timeline.Services.Timeline;
+using Timeline.Services.User;
+
+namespace Timeline.Services.Api
+{
+ /// <summary>
+ /// Service that controls highlight timeline.
+ /// </summary>
+ public interface IHighlightTimelineService
+ {
+ /// <summary>
+ /// Get all highlight timelines in order.
+ /// </summary>
+ /// <returns>Id list of all highlight timelines.</returns>
+ Task<List<long>> GetHighlightTimelinesAsync();
+
+ /// <summary>
+ /// Check if a timeline is highlight timeline.
+ /// </summary>
+ /// <param name="timelineId">Timeline id.</param>
+ /// <param name="checkTimelineExistence">If true it will throw if timeline does not exist.</param>
+ /// <returns>True if timeline is highlight. Otherwise false.</returns>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
+ Task<bool> IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true);
+
+ /// <summary>
+ /// Add a timeline to highlight list.
+ /// </summary>
+ /// <param name="timelineId">The timeline id.</param>
+ /// <param name="operatorId">The user id of operator.</param>
+ /// <returns>True if timeline is actually added to highligh. False if it already is.</returns>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
+ /// <exception cref="UserNotExistException">Thrown when user with given operator id does not exist.</exception>
+ Task<bool> AddHighlightTimelineAsync(long timelineId, long? operatorId);
+
+ /// <summary>
+ /// Remove a timeline from highlight list.
+ /// </summary>
+ /// <param name="timelineId">The timeline id.</param>
+ /// <param name="operatorId">The user id of operator.</param>
+ /// <returns>True if deletion is actually performed. Otherwise false (timeline was not in the list).</returns>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
+ /// <exception cref="UserNotExistException">Thrown when user with given operator id does not exist.</exception>
+ Task<bool> RemoveHighlightTimelineAsync(long timelineId, long? operatorId);
+
+ /// <summary>
+ /// Move a highlight timeline to a new position.
+ /// </summary>
+ /// <param name="timelineId">The timeline name.</param>
+ /// <param name="newPosition">The new position. Starts at 1.</param>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
+ /// <exception cref="InvalidHighlightTimelineException">Thrown when given timeline is not a highlight timeline.</exception>
+ /// <remarks>
+ /// If <paramref name="newPosition"/> is smaller than 1. Then move the timeline to head.
+ /// If <paramref name="newPosition"/> is bigger than total count. Then move the timeline to tail.
+ /// </remarks>
+ Task MoveHighlightTimelineAsync(long timelineId, long newPosition);
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/ISearchService.cs b/BackEnd/Timeline/Services/Api/ISearchService.cs
new file mode 100644
index 00000000..d8b4bb44
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/ISearchService.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Threading.Tasks;
+using Timeline.Entities;
+
+namespace Timeline.Services.Api
+{
+ public interface ISearchService
+ {
+ /// <summary>
+ /// Search timelines whose name or title contains query string.
+ /// </summary>
+ /// <param name="query">String to contain.</param>
+ /// <returns>Search results.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="query"/> is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when <paramref name="query"/> is empty.</exception>
+ /// <remarks>
+ /// Implementation should promise high score is at first.
+ /// </remarks>
+ Task<SearchResult<TimelineEntity>> SearchTimelineAsync(string query);
+
+ /// <summary>
+ /// Search users whose username or nickname contains query string.
+ /// </summary>
+ /// <param name="query">String to contain.</param>
+ /// <returns>Search results.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="query"/> is null.</exception>
+ /// <exception cref="ArgumentException">Thrown when <paramref name="query"/> is empty.</exception>
+ /// <remarks>
+ /// Implementation should promise high score is at first.
+ /// </remarks>
+ Task<SearchResult<UserEntity>> SearchUserAsync(string query);
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs b/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs
new file mode 100644
index 00000000..39572b38
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Timeline.Services.Api
+{
+ [Serializable]
+ public class InvalidBookmarkException : Exception
+ {
+ public InvalidBookmarkException() { }
+ public InvalidBookmarkException(string message) : base(message) { }
+ public InvalidBookmarkException(string message, Exception inner) : base(message, inner) { }
+ protected InvalidBookmarkException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs b/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs
new file mode 100644
index 00000000..13b04a6b
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Timeline.Services.Api
+{
+ [Serializable]
+ public class InvalidHighlightTimelineException : Exception
+ {
+ public InvalidHighlightTimelineException() { }
+ public InvalidHighlightTimelineException(string message) : base(message) { }
+ public InvalidHighlightTimelineException(string message, Exception inner) : base(message, inner) { }
+ protected InvalidHighlightTimelineException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/SearchResult.cs b/BackEnd/Timeline/Services/Api/SearchResult.cs
new file mode 100644
index 00000000..7c95ae5d
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/SearchResult.cs
@@ -0,0 +1,11 @@
+using System.Collections.Generic;
+
+namespace Timeline.Services.Api
+{
+ public class SearchResult<TItem>
+ {
+#pragma warning disable CA2227 // Collection properties should be read only
+ public List<SearchResultItem<TItem>> Items { get; set; } = new();
+#pragma warning restore CA2227 // Collection properties should be read only
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/SearchResultItem.cs b/BackEnd/Timeline/Services/Api/SearchResultItem.cs
new file mode 100644
index 00000000..ac40281f
--- /dev/null
+++ b/BackEnd/Timeline/Services/Api/SearchResultItem.cs
@@ -0,0 +1,18 @@
+namespace Timeline.Services.Api
+{
+ public class SearchResultItem<TItem>
+ {
+ public SearchResultItem(TItem item, int score)
+ {
+ Item = item;
+ Score = score;
+ }
+
+ public TItem Item { get; set; } = default!;
+
+ /// <summary>
+ /// Bigger is better.
+ /// </summary>
+ public int Score { get; set; }
+ }
+}
diff --git a/BackEnd/Timeline/Services/Api/SearchService.cs b/BackEnd/Timeline/Services/Api/SearchService.cs
index eec5001f..037f0490 100644
--- a/BackEnd/Timeline/Services/Api/SearchService.cs
+++ b/BackEnd/Timeline/Services/Api/SearchService.cs
@@ -1,62 +1,11 @@
using Microsoft.EntityFrameworkCore;
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
namespace Timeline.Services.Api
{
- public class SearchResultItem<TItem>
- {
- public SearchResultItem(TItem item, int score)
- {
- Item = item;
- Score = score;
- }
-
- public TItem Item { get; set; } = default!;
-
- /// <summary>
- /// Bigger is better.
- /// </summary>
- public int Score { get; set; }
- }
-
- public class SearchResult<TItem>
- {
-#pragma warning disable CA2227 // Collection properties should be read only
- public List<SearchResultItem<TItem>> Items { get; set; } = new();
-#pragma warning restore CA2227 // Collection properties should be read only
- }
-
- public interface ISearchService
- {
- /// <summary>
- /// Search timelines whose name or title contains query string.
- /// </summary>
- /// <param name="query">String to contain.</param>
- /// <returns>Search results.</returns>
- /// <exception cref="ArgumentNullException">Thrown when <paramref name="query"/> is null.</exception>
- /// <exception cref="ArgumentException">Thrown when <paramref name="query"/> is empty.</exception>
- /// <remarks>
- /// Implementation should promise high score is at first.
- /// </remarks>
- Task<SearchResult<TimelineEntity>> SearchTimeline(string query);
-
- /// <summary>
- /// Search users whose username or nickname contains query string.
- /// </summary>
- /// <param name="query">String to contain.</param>
- /// <returns>Search results.</returns>
- /// <exception cref="ArgumentNullException">Thrown when <paramref name="query"/> is null.</exception>
- /// <exception cref="ArgumentException">Thrown when <paramref name="query"/> is empty.</exception>
- /// <remarks>
- /// Implementation should promise high score is at first.
- /// </remarks>
- Task<SearchResult<UserEntity>> SearchUser(string query);
- }
-
public class SearchService : ISearchService
{
private readonly DatabaseContext _database;
@@ -66,7 +15,7 @@ namespace Timeline.Services.Api
_database = database;
}
- public async Task<SearchResult<TimelineEntity>> SearchTimeline(string query)
+ public async Task<SearchResult<TimelineEntity>> SearchTimelineAsync(string query)
{
if (query is null)
throw new ArgumentNullException(nameof(query));
@@ -83,7 +32,7 @@ namespace Timeline.Services.Api
return searchResult;
}
- public async Task<SearchResult<UserEntity>> SearchUser(string query)
+ public async Task<SearchResult<UserEntity>> SearchUserAsync(string query)
{
if (query is null)
throw new ArgumentNullException(nameof(query));