diff options
author | crupest <crupest@outlook.com> | 2022-04-07 20:36:03 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-07 20:36:03 +0800 |
commit | e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea (patch) | |
tree | 308def4c666f15587e67eba3045f567f5b2a1c88 /BackEnd/Timeline/Services | |
parent | 34305283aca89b8b2ebacd26ad3faf859a6a78b0 (diff) | |
download | timeline-e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea.tar.gz timeline-e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea.tar.bz2 timeline-e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Services')
3 files changed, 89 insertions, 10 deletions
diff --git a/BackEnd/Timeline/Services/Timeline/ITimelineService.cs b/BackEnd/Timeline/Services/Timeline/ITimelineService.cs index 62117903..72bf8a69 100644 --- a/BackEnd/Timeline/Services/Timeline/ITimelineService.cs +++ b/BackEnd/Timeline/Services/Timeline/ITimelineService.cs @@ -19,16 +19,37 @@ namespace Timeline.Services.Timeline Task<bool> CheckTimelineExistenceAsync(long id);
/// <summary>
- /// Get the timeline id by name.
+ /// Get the timeline id by name. Deprecated now because different users can have timeline with the same name now.
/// </summary>
/// <param name="timelineName">Timeline name.</param>
/// <returns>Id of the timeline.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception>
/// <exception cref="ArgumentException">Throw when <paramref name="timelineName"/> is of bad format.</exception>
- /// <exception cref="EntityNotExistException">
- /// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
- /// </exception>
- Task<long> GetTimelineIdByNameAsync(string timelineName);
+ /// <exception cref="EntityNotExistException">Thrown when timeline with name <paramref name="timelineName"/> does not exist.</exception>
+ /// <exception cref="MultipleTimelineException">Thrown when multiple timelines have that name.</exception>
+ Task<long> GetTimelineIdByNameAsync(string timelineName); + + /// <summary> + /// Get timeline id by owner id and timeline name. + /// </summary> + /// <param name="ownerId">The timeline owner id.</param> + /// <param name="timelineName">The timeline name.</param> + /// <returns>A task contains timeline id.</returns> + /// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception> + /// <exception cref="ArgumentException">Thrown when <paramref name="timelineName"/> is not a valid name.</exception> + Task<long> GetTimelineIdAsync(long ownerId, string timelineName); + + /// <summary> + /// Get timeline id by owner username and timeline name. + /// </summary> + /// <param name="ownerUsername">The timeline owner id.</param> + /// <param name="timelineName">The timeline name.</param> + /// <returns>A task contains timeline id.</returns> + /// <exception cref="ArgumentNullException">Thrown when <paramref name="ownerUsername"/> is null or <paramref name="timelineName"/> is null.</exception> + /// <exception cref="ArgumentException">Thrown when <paramref name="ownerUsername"/> is not a valid username or <paramref name="timelineName"/> is not a valid timeline name.</exception> + /// <exception cref="EntityNotExistException">Thrown when user with given username does not exist.</exception> + /// <exception cref="EntityNotExistException">Thrown when timeline with given name does not exist.</exception> + Task<long> GetTimelineIdAsync(string ownerUsername, string timelineName);
/// <summary>
/// Get the timeline info.
diff --git a/BackEnd/Timeline/Services/Timeline/MultipleTimelineException.cs b/BackEnd/Timeline/Services/Timeline/MultipleTimelineException.cs new file mode 100644 index 00000000..f7f80a31 --- /dev/null +++ b/BackEnd/Timeline/Services/Timeline/MultipleTimelineException.cs @@ -0,0 +1,44 @@ +using System; +namespace Timeline.Services.Timeline +{ + /// <summary> + /// Thrown when call <see cref="ITimelineService.GetTimelineIdByNameAsync(string)"/> and multiple timelines have that same name. + /// </summary> + [Serializable] + public class MultipleTimelineException : Exception + { + /// <summary> + /// Initializes a new instance of the <see cref="T:MultipleTimelineException"/> class + /// </summary> + public MultipleTimelineException() + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="T:MultipleTimelineException"/> class + /// </summary> + /// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param> + public MultipleTimelineException(string message) : base(message) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="T:MultipleTimelineException"/> class + /// </summary> + /// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param> + /// <param name="inner">The exception that is the cause of the current exception. </param> + public MultipleTimelineException(string message, System.Exception inner) : base(message, inner) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="T:MultipleTimelineException"/> class + /// </summary> + /// <param name="context">The contextual information about the source or destination.</param> + /// <param name="info">The object that holds the serialized object data.</param> + protected MultipleTimelineException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) + { + } + } +} + diff --git a/BackEnd/Timeline/Services/Timeline/TimelineService.cs b/BackEnd/Timeline/Services/Timeline/TimelineService.cs index 82713eb1..88c6e2f8 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelineService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelineService.cs @@ -135,15 +135,19 @@ namespace Timeline.Services.Timeline }
else
{
- var timelineEntity = await _database.Timelines.Where(t => t.Name == timelineName).Select(t => new { t.Id }).SingleOrDefaultAsync();
+ var timelineEntities = await _database.Timelines.Where(t => t.Name == timelineName).Select(t => new { t.Id }).ToListAsync();
- if (timelineEntity == null)
+ if (timelineEntities.Count == 0)
{
throw CreateTimelineNotExistException(timelineName);
}
- else
+ else if (timelineEntities.Count == 1)
{
- return timelineEntity.Id;
+ return timelineEntities[0].Id;
+ } + else + { + throw new MultipleTimelineException(String.Format("Multiple timelines have name '{}'.", timelineName)); }
}
}
@@ -398,6 +402,16 @@ namespace Timeline.Services.Timeline _database.Timelines.Remove(entity);
await _database.SaveChangesAsync();
_logger.LogWarning(Resource.LogTimelineDelete, id);
- }
+ } + + public Task<long> GetTimelineIdAsync(long ownerId, string timelineName) + { + throw new NotImplementedException(); + } + + public Task<long> GetTimelineIdAsync(string ownerUsername, string timelineName) + { + throw new NotImplementedException(); + } }
}
|