aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/DatabaseExtensions.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-10-31 15:02:03 +0800
committerGitHub <noreply@github.com>2019-10-31 15:02:03 +0800
commit2de7fa95bb5ad0a10f74fb390bac464a250dee42 (patch)
treeba42530cf4f13621a7a3a7ff661e383117119883 /Timeline/Services/DatabaseExtensions.cs
parentf08f53d6fcd9baf9dd3b95209f7c7448ae8168d4 (diff)
parentcf2055f956695bc0b9ecdb6d8023d0d199b98462 (diff)
downloadtimeline-2de7fa95bb5ad0a10f74fb390bac464a250dee42.tar.gz
timeline-2de7fa95bb5ad0a10f74fb390bac464a250dee42.tar.bz2
timeline-2de7fa95bb5ad0a10f74fb390bac464a250dee42.zip
Merge pull request #53 from crupest/nickname
Add nickname support.
Diffstat (limited to 'Timeline/Services/DatabaseExtensions.cs')
-rw-r--r--Timeline/Services/DatabaseExtensions.cs6
1 files changed, 4 insertions, 2 deletions
diff --git a/Timeline/Services/DatabaseExtensions.cs b/Timeline/Services/DatabaseExtensions.cs
index 8cbc8fef..140c3146 100644
--- a/Timeline/Services/DatabaseExtensions.cs
+++ b/Timeline/Services/DatabaseExtensions.cs
@@ -9,6 +9,8 @@ namespace Timeline.Services
{
internal static class DatabaseExtensions
{
+ private static readonly UsernameValidator usernameValidator = new UsernameValidator();
+
/// <summary>
/// Check the existence and get the id of the user.
/// </summary>
@@ -17,11 +19,11 @@ namespace Timeline.Services
/// <exception cref="ArgumentNullException">Thrown if <paramref name="username"/> is null.</exception>
/// <exception cref="UsernameBadFormatException">Thrown if <paramref name="username"/> is of bad format.</exception>
/// <exception cref="UserNotExistException">Thrown if user does not exist.</exception>
- internal static async Task<long> CheckAndGetUser(DbSet<User> userDbSet, UsernameValidator validator, string username)
+ internal static async Task<long> CheckAndGetUser(DbSet<User> userDbSet, string? username)
{
if (username == null)
throw new ArgumentNullException(nameof(username));
- var (result, message) = validator.Validate(username);
+ var (result, message) = usernameValidator.Validate(username);
if (!result)
throw new UsernameBadFormatException(username, message);