aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Services')
-rw-r--r--Timeline/Services/TimelineAlreadyExistException.cs17
-rw-r--r--Timeline/Services/TimelineMemberOperationUserException.cs28
-rw-r--r--Timeline/Services/TimelineService.cs63
-rw-r--r--Timeline/Services/TimelineUserNotMemberException.cs15
4 files changed, 101 insertions, 22 deletions
diff --git a/Timeline/Services/TimelineAlreadyExistException.cs b/Timeline/Services/TimelineAlreadyExistException.cs
new file mode 100644
index 00000000..c2dea1f9
--- /dev/null
+++ b/Timeline/Services/TimelineAlreadyExistException.cs
@@ -0,0 +1,17 @@
+using System;
+
+namespace Timeline.Services
+{
+ [Serializable]
+ public class TimelineAlreadyExistException : Exception
+ {
+ public TimelineAlreadyExistException() : base(Resources.Services.Exception.TimelineAlreadyExistException) { }
+ public TimelineAlreadyExistException(string name) : base(Resources.Services.Exception.TimelineAlreadyExistException) { Name = name; }
+ public TimelineAlreadyExistException(string name, Exception inner) : base(Resources.Services.Exception.TimelineAlreadyExistException, inner) { Name = name; }
+ protected TimelineAlreadyExistException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ public string? Name { get; set; }
+ }
+}
diff --git a/Timeline/Services/TimelineMemberOperationUserException.cs b/Timeline/Services/TimelineMemberOperationUserException.cs
new file mode 100644
index 00000000..998f1a6e
--- /dev/null
+++ b/Timeline/Services/TimelineMemberOperationUserException.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Globalization;
+
+namespace Timeline.Services
+{
+ [Serializable]
+ public class TimelineMemberOperationUserException : Exception
+ {
+ public TimelineMemberOperationUserException() : base(Resources.Services.Exception.TimelineMemberOperationException) { }
+ public TimelineMemberOperationUserException(string message) : base(message) { }
+ public TimelineMemberOperationUserException(string message, Exception inner) : base(message, inner) { }
+ protected TimelineMemberOperationUserException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ public TimelineMemberOperationUserException(int index, string username, Exception inner) : base(MakeIndexMessage(index), inner) { Index = index; Username = username; }
+
+ private static string MakeIndexMessage(int index) => string.Format(CultureInfo.CurrentCulture,
+ Resources.Services.Exception.TimelineMemberOperationExceptionIndex, index);
+
+ /// <summary>
+ /// The index of the member on which the operation failed.
+ /// </summary>
+ public int? Index { get; set; }
+
+ public string? Username { get; set; }
+ }
+}
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs
index cf130a70..9d309e7e 100644
--- a/Timeline/Services/TimelineService.cs
+++ b/Timeline/Services/TimelineService.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
@@ -8,25 +7,6 @@ using Timeline.Models;
namespace Timeline.Services
{
-
- [Serializable]
- public class TimelineMemberOperationException : Exception
- {
- public TimelineMemberOperationException() : base(Resources.Services.Exception.TimelineMemberOperationException) { }
- public TimelineMemberOperationException(string message) : base(message) { }
- public TimelineMemberOperationException(string message, Exception inner) : base(message, inner) { }
- protected TimelineMemberOperationException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
-
- public TimelineMemberOperationException(int index, Exception inner) : base(MakeIndexMessage(index), inner) { Index = index; }
-
- private static string MakeIndexMessage(int index) => string.Format(CultureInfo.CurrentCulture,
- Resources.Services.Exception.TimelineMemberOperationExceptionIndex, index);
-
- public int? Index { get; set; }
- }
-
/// <summary>
/// This define the common interface of both personal timeline
/// and normal timeline.
@@ -141,8 +121,12 @@ namespace Timeline.Services
/// For personal timeline, it means the user of that username does not exist
/// and the inner exception should be a <see cref="UserNotExistException"/>.
/// </exception>
- /// <exception cref="TimelineMemberOperationException">
- /// TODO! complete this documents.
+ /// <exception cref="TimelineMemberOperationUserException">
+ /// Thrown when an exception occurs on users in the list.
+ /// The inner exception is <see cref="UsernameBadFormatException"/>
+ /// when one of the username is not valid.
+ /// The inner exception is <see cref="UserNotExistException"/>
+ /// when one of the user does not exist.
/// </exception>
Task AddMember(string name, IList<string> usernames);
@@ -164,6 +148,13 @@ namespace Timeline.Services
/// For personal timeline, it means the user of that username does not exist
/// and the inner exception should be a <see cref="UserNotExistException"/>.
/// </exception>
+ /// <exception cref="TimelineMemberOperationUserException">
+ /// Thrown when an exception occurs on the user list.
+ /// The inner exception is <see cref="UsernameBadFormatException"/>
+ /// when one of the username is invalid.
+ /// The inner exception is <see cref="TimelineUserNotMemberException"/>
+ /// when one of the user is not a member of the timeline.
+ /// </exception>
Task RemoveMember(string name, IList<string> usernames);
}
@@ -177,6 +168,13 @@ namespace Timeline.Services
/// </summary>
/// <param name="name">The name of the timeline.</param>
/// <returns>The timeline info.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null.</exception>
+ /// <exception cref="TimelineNameBadFormatException">
+ /// Thrown when timeline name is invalid. Currently it means it is an empty string.
+ /// </exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when timeline with the name does not exist.
+ /// </exception>
Task<TimelineInfo> GetTimeline(string name);
/// <summary>
@@ -184,6 +182,18 @@ namespace Timeline.Services
/// </summary>
/// <param name="name">The name of the timeline.</param>
/// <param name="owner">The owner of the timeline.</param>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> or <paramref name="owner"/> is null.</exception>
+ /// <exception cref="TimelineNameBadFormatException">
+ /// Thrown when timeline name is invalid. Currently it means it is an empty string.
+ /// </exception>
+ /// <exception cref="TimelineAlreadyExistException">
+ /// Thrown when the timeline already exists.
+ /// </exception>
+ /// <exception cref="UsernameBadFormatException">
+ /// Thrown when the username of the owner is not valid.
+ /// </exception>
+ /// <exception cref="UserNotExistException">
+ /// Thrown when the owner user does not exist.</exception>
Task CreateTimeline(string name, string owner);
}
@@ -194,6 +204,15 @@ namespace Timeline.Services
/// </summary>
/// <param name="username">The username of the owner of the personal timeline.</param>
/// <returns>The timeline info.</returns>
+ /// <exception cref="ArgumentNullException">
+ /// Thrown when <paramref name="username"/> is null.
+ /// </exception>
+ /// <exception cref="TimelineNameBadFormatException">
+ /// Thrown when <paramref name="username"/> is of bad format. Inner exception MUST be <see cref="UsernameBadFormatException"/>.
+ /// </exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when the user does not exist. Inner exception MUST be <see cref="UserNotExistException"/>.
+ /// </exception>
Task<BaseTimelineInfo> GetTimeline(string username);
}
}
diff --git a/Timeline/Services/TimelineUserNotMemberException.cs b/Timeline/Services/TimelineUserNotMemberException.cs
new file mode 100644
index 00000000..260beb02
--- /dev/null
+++ b/Timeline/Services/TimelineUserNotMemberException.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Timeline.Services
+{
+ [Serializable]
+ public class TimelineUserNotMemberException : Exception
+ {
+ public TimelineUserNotMemberException() : base(Resources.Services.Exception.TimelineUserNotMemberException) { }
+ public TimelineUserNotMemberException(string message) : base(message) { }
+ public TimelineUserNotMemberException(string message, Exception inner) : base(message, inner) { }
+ protected TimelineUserNotMemberException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+ }
+}