aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/BasicUserService.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-10 19:17:08 +0800
committercrupest <crupest@outlook.com>2021-02-10 19:17:08 +0800
commit02beb8b7fa3b8e5fe33307dd63de92d1c9bfaf0a (patch)
treee9aa1c65da78f643cad2b716f4b0dbf3506cc7aa /BackEnd/Timeline/Services/BasicUserService.cs
parent872f0e9f094f37db9ff208d178ad5bea2fafc1a7 (diff)
downloadtimeline-02beb8b7fa3b8e5fe33307dd63de92d1c9bfaf0a.tar.gz
timeline-02beb8b7fa3b8e5fe33307dd63de92d1c9bfaf0a.tar.bz2
timeline-02beb8b7fa3b8e5fe33307dd63de92d1c9bfaf0a.zip
...
Diffstat (limited to 'BackEnd/Timeline/Services/BasicUserService.cs')
-rw-r--r--BackEnd/Timeline/Services/BasicUserService.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/BasicUserService.cs b/BackEnd/Timeline/Services/BasicUserService.cs
index fbbb6677..de0829ee 100644
--- a/BackEnd/Timeline/Services/BasicUserService.cs
+++ b/BackEnd/Timeline/Services/BasicUserService.cs
@@ -29,6 +29,14 @@ namespace Timeline.Services
/// <exception cref="ArgumentException">Thrown when <paramref name="username"/> is of bad format.</exception>
/// <exception cref="UserNotExistException">Thrown when the user with given username does not exist.</exception>
Task<long> GetUserIdByUsername(string username);
+
+ /// <summary>
+ /// Get the username modified time of a user.
+ /// </summary>
+ /// <param name="userId">User id.</param>
+ /// <returns>The time.</returns>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ Task<DateTime> GetUsernameLastModifiedTime(long userId);
}
public class BasicUserService : IBasicUserService
@@ -62,5 +70,26 @@ namespace Timeline.Services
return entity.Id;
}
+
+ public async Task<DateTime> GetUsernameLastModifiedTime(long userId)
+ {
+ var entity = await _database.Users.Where(u => u.Id == userId).Select(u => new { u.UsernameChangeTime }).SingleOrDefaultAsync();
+
+ if (entity is null)
+ throw new UserNotExistException(userId);
+
+ return entity.UsernameChangeTime;
+ }
+ }
+
+ public static class BasicUserServiceExtensions
+ {
+ public static async Task ThrowIfUserNotExist(this IBasicUserService service, long userId)
+ {
+ if (!await service.CheckUserExistence(userId))
+ {
+ throw new UserNotExistException(userId);
+ }
+ }
}
}