diff options
author | crupest <crupest@outlook.com> | 2022-04-07 21:52:26 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-04-07 21:52:26 +0800 |
commit | a1f6b41accb47e4c1e1e0474148afa94732377da (patch) | |
tree | 019932d11ab14682f526b7cb9ab1be5a27fbbfdd /BackEnd/Timeline/Services | |
parent | f8eecd3d50dec23d23b2fa1b6223b9c99d974214 (diff) | |
download | timeline-a1f6b41accb47e4c1e1e0474148afa94732377da.tar.gz timeline-a1f6b41accb47e4c1e1e0474148afa94732377da.tar.bz2 timeline-a1f6b41accb47e4c1e1e0474148afa94732377da.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/TimelineService.cs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/BackEnd/Timeline/Services/Timeline/TimelineService.cs b/BackEnd/Timeline/Services/Timeline/TimelineService.cs index bd838c7d..cdea39fa 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelineService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelineService.cs @@ -82,6 +82,15 @@ namespace Timeline.Services.Timeline {
["id"] = id
});
+ } + + protected static EntityNotExistException CreateTimelineNotExistException(long ownerId, string timelineName)
+ {
+ return new EntityNotExistException(EntityTypes.Timeline, new Dictionary<string, object>
+ {
+ [nameof(ownerId)] = ownerId,
+ [nameof(timelineName)] = timelineName
+ });
}
protected void CheckGeneralTimelineName(string timelineName, string? paramName)
@@ -378,6 +387,10 @@ namespace Timeline.Services.Timeline throw new ArgumentNullException(nameof(timelineName));
CheckTimelineName(timelineName, nameof(timelineName));
+ if (timelineName == "self") + { + throw new ArgumentException("Timeline name can't be 'self'."); + } var conflict = await _database.Timelines.AnyAsync(t => t.OwnerId == ownerId && t.Name == timelineName);
@@ -405,14 +418,25 @@ namespace Timeline.Services.Timeline _logger.LogWarning(Resource.LogTimelineDelete, id);
} - public Task<long> GetTimelineIdAsync(long ownerId, string timelineName) + public async Task<long> GetTimelineIdAsync(long ownerId, string timelineName) { - throw new NotImplementedException(); + if (timelineName is null) + throw new ArgumentNullException(nameof(timelineName)); + CheckTimelineName(timelineName, nameof(timelineName)); + + string? tn = timelineName == "self" ? null : timelineName; + + var entity = await _database.Timelines.Where(t => t.OwnerId == ownerId && t.Name == tn).SingleOrDefaultAsync(); + if (entity is null) + throw CreateTimelineNotExistException(ownerId, timelineName); + + return entity.Id; } - public Task<long> GetTimelineIdAsync(string ownerUsername, string timelineName) + public async Task<long> GetTimelineIdAsync(string ownerUsername, string timelineName) { - throw new NotImplementedException(); + var ownerId = await _userService.GetUserIdByUsernameAsync(ownerUsername); + return await GetTimelineIdAsync(ownerId, timelineName); } }
}
|