From a6150c487e7a0eb3fb1d9874d2fa7de61cdbfd30 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Apr 2021 19:29:20 +0800 Subject: refactor: ... --- BackEnd/Timeline/Services/User/BasicUserService.cs | 39 +++------------------- 1 file changed, 4 insertions(+), 35 deletions(-) (limited to 'BackEnd/Timeline/Services/User/BasicUserService.cs') diff --git a/BackEnd/Timeline/Services/User/BasicUserService.cs b/BackEnd/Timeline/Services/User/BasicUserService.cs index a3763ef6..1f1b25f5 100644 --- a/BackEnd/Timeline/Services/User/BasicUserService.cs +++ b/BackEnd/Timeline/Services/User/BasicUserService.cs @@ -7,37 +7,6 @@ using Timeline.Models.Validation; namespace Timeline.Services.User { - /// - /// This service provide some basic user features, which should be used internally for other services. - /// - public interface IBasicUserService - { - /// - /// Check if a user exists. - /// - /// The id of the user. - /// True if exists. Otherwise false. - Task CheckUserExistence(long id); - - /// - /// Get the user id of given username. - /// - /// Username of the user. - /// The id of the user. - /// Thrown when is null. - /// Thrown when is of bad format. - /// Thrown when the user with given username does not exist. - Task GetUserIdByUsername(string username); - - /// - /// Get the username modified time of a user. - /// - /// User id. - /// The time. - /// Thrown when user does not exist. - Task GetUsernameLastModifiedTime(long userId); - } - public class BasicUserService : IBasicUserService { private readonly DatabaseContext _database; @@ -49,12 +18,12 @@ namespace Timeline.Services.User _database = database; } - public async Task CheckUserExistence(long id) + public async Task CheckUserExistenceAsync(long id) { return await _database.Users.AnyAsync(u => u.Id == id); } - public async Task GetUserIdByUsername(string username) + public async Task GetUserIdByUsernameAsync(string username) { if (username == null) throw new ArgumentNullException(nameof(username)); @@ -70,7 +39,7 @@ namespace Timeline.Services.User return entity.Id; } - public async Task GetUsernameLastModifiedTime(long userId) + public async Task GetUsernameLastModifiedTimeAsync(long userId) { var entity = await _database.Users.Where(u => u.Id == userId).Select(u => new { u.UsernameChangeTime }).SingleOrDefaultAsync(); @@ -85,7 +54,7 @@ namespace Timeline.Services.User { public static async Task ThrowIfUserNotExist(this IBasicUserService service, long userId) { - if (!await service.CheckUserExistence(userId)) + if (!await service.CheckUserExistenceAsync(userId)) { throw new UserNotExistException(userId); } -- cgit v1.2.3