aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-07 20:36:03 +0800
committercrupest <crupest@outlook.com>2022-04-07 20:36:03 +0800
commite2af7d31ac20037b50d5797b7a9b16ee65cbc0ea (patch)
tree308def4c666f15587e67eba3045f567f5b2a1c88 /BackEnd/Timeline
parent34305283aca89b8b2ebacd26ad3faf859a6a78b0 (diff)
downloadtimeline-e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea.tar.gz
timeline-e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea.tar.bz2
timeline-e2af7d31ac20037b50d5797b7a9b16ee65cbc0ea.zip
...
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r--BackEnd/Timeline/Services/Timeline/ITimelineService.cs31
-rw-r--r--BackEnd/Timeline/Services/Timeline/MultipleTimelineException.cs44
-rw-r--r--BackEnd/Timeline/Services/Timeline/TimelineService.cs24
-rw-r--r--BackEnd/Timeline/Timeline.csproj2
-rw-r--r--BackEnd/Timeline/packages.lock.json6
5 files changed, 93 insertions, 14 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();
+ }
}
}
diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj
index 0bf11e31..26e562e8 100644
--- a/BackEnd/Timeline/Timeline.csproj
+++ b/BackEnd/Timeline/Timeline.csproj
@@ -36,7 +36,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
- <PackageReference Include="Markdig" Version="0.28.0" />
+ <PackageReference Include="Markdig" Version="0.28.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="6.0.3" />
diff --git a/BackEnd/Timeline/packages.lock.json b/BackEnd/Timeline/packages.lock.json
index f3bbe4b3..258d3e8d 100644
--- a/BackEnd/Timeline/packages.lock.json
+++ b/BackEnd/Timeline/packages.lock.json
@@ -23,9 +23,9 @@
},
"Markdig": {
"type": "Direct",
- "requested": "[0.28.0, )",
- "resolved": "0.28.0",
- "contentHash": "gT6Sm14OaKQDwus5wFoI/v+Zxrgd2r70pkfq6dC1mIZaK1rvdEHtfnf3nD/Q/clrPFcvBIxZag79NXFjMkxhmA=="
+ "requested": "[0.28.1, )",
+ "resolved": "0.28.1",
+ "contentHash": "70CneXw2N/1t7v6OfZJqMKLPRB1YWTPddEIcHT/P6IL6X1zsXELIu/DHVt96kr83PIVLznMuXoFK6b9N9KTODg=="
},
"Microsoft.AspNetCore.SpaServices.Extensions": {
"type": "Direct",