aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-07 20:45:24 +0800
committercrupest <crupest@outlook.com>2022-04-07 20:45:24 +0800
commitf8eecd3d50dec23d23b2fa1b6223b9c99d974214 (patch)
tree38a1518a58ed571b0ecfecc1b65de1fb1c1ec6c0 /BackEnd/Timeline
parent97a2b834e5b2da14a54d12a9bef423a8607f0e94 (diff)
downloadtimeline-f8eecd3d50dec23d23b2fa1b6223b9c99d974214.tar.gz
timeline-f8eecd3d50dec23d23b2fa1b6223b9c99d974214.tar.bz2
timeline-f8eecd3d50dec23d23b2fa1b6223b9c99d974214.zip
...
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r--BackEnd/Timeline/Controllers/TimelineController.cs2
-rw-r--r--BackEnd/Timeline/Services/Timeline/ITimelineService.cs4
-rw-r--r--BackEnd/Timeline/Services/Timeline/TimelineService.cs25
3 files changed, 16 insertions, 15 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs
index 42b8f210..a6749706 100644
--- a/BackEnd/Timeline/Controllers/TimelineController.cs
+++ b/BackEnd/Timeline/Controllers/TimelineController.cs
@@ -218,7 +218,7 @@ namespace Timeline.Controllers
{
var userId = GetAuthUserId();
- var timeline = await _service.CreateTimelineAsync(body.Name, userId);
+ var timeline = await _service.CreateTimelineAsync(userId, body.Name);
var result = await Map(timeline);
return result;
}
diff --git a/BackEnd/Timeline/Services/Timeline/ITimelineService.cs b/BackEnd/Timeline/Services/Timeline/ITimelineService.cs
index 72bf8a69..847caf0d 100644
--- a/BackEnd/Timeline/Services/Timeline/ITimelineService.cs
+++ b/BackEnd/Timeline/Services/Timeline/ITimelineService.cs
@@ -142,14 +142,14 @@ namespace Timeline.Services.Timeline
/// <summary>
/// Create a timeline.
/// </summary>
- /// <param name="timelineName">The name of the timeline.</param>
/// <param name="ownerId">The id of owner of the timeline.</param>
+ /// <param name="timelineName">The name of the timeline.</param>
/// <returns>The info of the new timeline.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception>
/// <exception cref="ArgumentException">Thrown when timeline name is invalid.</exception>
/// <exception cref="EntityAlreadyExistException">Thrown when the timeline already exists.</exception>
/// <exception cref="EntityNotExistException">Thrown when the owner user does not exist.</exception>
- Task<TimelineEntity> CreateTimelineAsync(string timelineName, long ownerId);
+ Task<TimelineEntity> CreateTimelineAsync(long ownerId, string timelineName);
/// <summary>
/// Delete a timeline.
diff --git a/BackEnd/Timeline/Services/Timeline/TimelineService.cs b/BackEnd/Timeline/Services/Timeline/TimelineService.cs
index 88c6e2f8..bd838c7d 100644
--- a/BackEnd/Timeline/Services/Timeline/TimelineService.cs
+++ b/BackEnd/Timeline/Services/Timeline/TimelineService.cs
@@ -34,11 +34,12 @@ namespace Timeline.Services.Timeline
_clock = clock;
}
- private static EntityAlreadyExistException CreateTimelineConflictException(string name)
+ private static EntityAlreadyExistException CreateTimelineConflictException(long ownerId, string timelineName)
{
return new EntityAlreadyExistException(EntityTypes.Timeline, new Dictionary<string, object>
{
- ["name"] = name
+ [nameof(ownerId)] = ownerId,
+ [nameof(timelineName)] = timelineName
});
}
@@ -190,10 +191,10 @@ namespace Timeline.Services.Timeline
if (newProperties.Name is not null)
{
- var conflict = await _database.Timelines.AnyAsync(t => t.Name == newProperties.Name);
+ var conflict = await _database.Timelines.AnyAsync(t => t.OwnerId == entity.OwnerId && t.Name == newProperties.Name);
if (conflict)
- throw CreateTimelineConflictException(newProperties.Name);
+ throw CreateTimelineConflictException(entity.OwnerId, newProperties.Name);
entity.Name = newProperties.Name;
@@ -371,23 +372,23 @@ namespace Timeline.Services.Timeline
return entities;
}
- public async Task<TimelineEntity> CreateTimelineAsync(string name, long owner)
+ public async Task<TimelineEntity> CreateTimelineAsync(long ownerId, string timelineName)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
+ if (timelineName == null)
+ throw new ArgumentNullException(nameof(timelineName));
- CheckTimelineName(name, nameof(name));
+ CheckTimelineName(timelineName, nameof(timelineName));
- var conflict = await _database.Timelines.AnyAsync(t => t.Name == name);
+ var conflict = await _database.Timelines.AnyAsync(t => t.OwnerId == ownerId && t.Name == timelineName);
if (conflict)
- throw CreateTimelineConflictException(name);
+ throw CreateTimelineConflictException(ownerId, timelineName);
- var entity = CreateNewTimelineEntity(name, owner);
+ var entity = CreateNewTimelineEntity(timelineName, ownerId);
_database.Timelines.Add(entity);
await _database.SaveChangesAsync();
- _logger.LogInformation(Resource.LogTimelineCreate, name, entity.Id);
+ _logger.LogInformation(Resource.LogTimelineCreate, timelineName, entity.Id);
return entity;
}