diff options
Diffstat (limited to 'BackEnd')
-rw-r--r-- | BackEnd/Timeline.Tests/Timeline.Tests.csproj | 2 | ||||
-rw-r--r-- | BackEnd/Timeline.Tests/packages.lock.json | 12 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/ITimelineService.cs | 31 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/MultipleTimelineException.cs | 44 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/TimelineService.cs | 24 | ||||
-rw-r--r-- | BackEnd/Timeline/Timeline.csproj | 2 | ||||
-rw-r--r-- | BackEnd/Timeline/packages.lock.json | 6 |
7 files changed, 100 insertions, 21 deletions
diff --git a/BackEnd/Timeline.Tests/Timeline.Tests.csproj b/BackEnd/Timeline.Tests/Timeline.Tests.csproj index b699eb49..82dc4d6a 100644 --- a/BackEnd/Timeline.Tests/Timeline.Tests.csproj +++ b/BackEnd/Timeline.Tests/Timeline.Tests.csproj @@ -12,7 +12,7 @@ <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="FluentAssertions" Version="6.5.1" />
+ <PackageReference Include="FluentAssertions" Version="6.6.0" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.2.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.3" />
diff --git a/BackEnd/Timeline.Tests/packages.lock.json b/BackEnd/Timeline.Tests/packages.lock.json index 6098e0ba..5c71f593 100644 --- a/BackEnd/Timeline.Tests/packages.lock.json +++ b/BackEnd/Timeline.Tests/packages.lock.json @@ -10,9 +10,9 @@ }, "FluentAssertions": { "type": "Direct", - "requested": "[6.5.1, )", - "resolved": "6.5.1", - "contentHash": "hdY/upTFYEc7SFJQ+pKsMZP1J5bELh9feB8kXzk6FKAGE/tvAPDzHd76Z+nIYdgnqkocthaDUq+tKPsGD0um2A==", + "requested": "[6.6.0, )", + "resolved": "6.6.0", + "contentHash": "gBsgPrNRkzUQfnxZSKnU0oVILIc5dr+dmdKXscyYKD5URcwNVQ72a7uuCvTyBzRZW98MZQNolSYC0y/MQTJ03A==", "dependencies": { "System.Configuration.ConfigurationManager": "4.4.0" } @@ -130,8 +130,8 @@ }, "Markdig": { "type": "Transitive", - "resolved": "0.28.0", - "contentHash": "gT6Sm14OaKQDwus5wFoI/v+Zxrgd2r70pkfq6dC1mIZaK1rvdEHtfnf3nD/Q/clrPFcvBIxZag79NXFjMkxhmA==" + "resolved": "0.28.1", + "contentHash": "70CneXw2N/1t7v6OfZJqMKLPRB1YWTPddEIcHT/P6IL6X1zsXELIu/DHVt96kr83PIVLznMuXoFK6b9N9KTODg==" }, "Microsoft.AspNetCore.Connections.Abstractions": { "type": "Transitive", @@ -1755,7 +1755,7 @@ "dependencies": { "AutoMapper": "11.0.1", "AutoMapper.Extensions.Microsoft.DependencyInjection": "11.0.0", - "Markdig": "0.28.0", + "Markdig": "0.28.1", "Microsoft.AspNetCore.SpaServices.Extensions": "6.0.3", "Microsoft.EntityFrameworkCore": "6.0.3", "Microsoft.EntityFrameworkCore.Analyzers": "6.0.3", 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", |