diff options
author | crupest <crupest@outlook.com> | 2022-04-07 20:45:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-07 20:45:24 +0800 |
commit | f8eecd3d50dec23d23b2fa1b6223b9c99d974214 (patch) | |
tree | 38a1518a58ed571b0ecfecc1b65de1fb1c1ec6c0 /BackEnd | |
parent | 97a2b834e5b2da14a54d12a9bef423a8607f0e94 (diff) | |
download | timeline-f8eecd3d50dec23d23b2fa1b6223b9c99d974214.tar.gz timeline-f8eecd3d50dec23d23b2fa1b6223b9c99d974214.tar.bz2 timeline-f8eecd3d50dec23d23b2fa1b6223b9c99d974214.zip |
...
Diffstat (limited to 'BackEnd')
5 files changed, 19 insertions, 19 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs index d7832b60..72553248 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -383,7 +383,6 @@ namespace Timeline.Tests.IntegratedTests using (var client = await CreateClientAsUser())
{
await client.TestPatchAssertInvalidModelAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "!!!" });
- await client.TestPatchAssertErrorAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "t2" }, errorCode: ErrorCodes.Conflict.Timeline);
await client.TestPatchAsync("timelines/t1", new HttpTimelinePatchRequest { Name = "newt" });
diff --git a/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs b/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs index 6e3c0f40..9195ef4f 100644 --- a/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs +++ b/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs @@ -19,10 +19,10 @@ namespace Timeline.Tests.Services [Fact]
public async Task TimelineSearch_Should_Work()
{
- await TimelineService.CreateTimelineAsync("hahaha", UserId);
- var t2 = await TimelineService.CreateTimelineAsync("bababa", UserId);
+ await TimelineService.CreateTimelineAsync(UserId, "hahaha");
+ var t2 = await TimelineService.CreateTimelineAsync(UserId, "bababa");
await TimelineService.ChangePropertyAsync(t2.Id, new TimelineChangePropertyParams { Title = "hahaha" });
- await TimelineService.CreateTimelineAsync("bbbbbb", UserId);
+ await TimelineService.CreateTimelineAsync(UserId, "bbbbbb");
var searchResult = await _service.SearchTimelineAsync("hah");
searchResult.Items.Should().HaveCount(2);
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;
}
|