diff options
author | crupest <crupest@outlook.com> | 2022-03-25 20:20:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-25 20:20:47 +0800 |
commit | 34305283aca89b8b2ebacd26ad3faf859a6a78b0 (patch) | |
tree | 7eb0d518111a4714056fe50b538bc0dd6311b4e3 /BackEnd/Timeline/Services/User/BasicUserService.cs | |
parent | 65b2e7f6984b8776e603bd8ae847c9e2a9bd5ad6 (diff) | |
download | timeline-34305283aca89b8b2ebacd26ad3faf859a6a78b0.tar.gz timeline-34305283aca89b8b2ebacd26ad3faf859a6a78b0.tar.bz2 timeline-34305283aca89b8b2ebacd26ad3faf859a6a78b0.zip |
…
Diffstat (limited to 'BackEnd/Timeline/Services/User/BasicUserService.cs')
-rw-r--r-- | BackEnd/Timeline/Services/User/BasicUserService.cs | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/BackEnd/Timeline/Services/User/BasicUserService.cs b/BackEnd/Timeline/Services/User/BasicUserService.cs deleted file mode 100644 index 0ee8dabd..00000000 --- a/BackEnd/Timeline/Services/User/BasicUserService.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Microsoft.EntityFrameworkCore;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Timeline.Entities;
-using Timeline.Models.Validation;
-
-namespace Timeline.Services.User
-{
- public class BasicUserService : IBasicUserService
- {
- private readonly DatabaseContext _database;
-
- private readonly UsernameValidator _usernameValidator = new UsernameValidator();
-
- public BasicUserService(DatabaseContext database)
- {
- _database = database;
- }
-
- protected static EntityNotExistException CreateUserNotExistException(string username)
- {
- return new EntityNotExistException(EntityTypes.User,
- new Dictionary<string, object> { ["username"] = username });
- }
-
- protected static EntityNotExistException CreateUserNotExistException(long id)
- {
- return new EntityNotExistException(EntityTypes.User,
- new Dictionary<string, object> { ["id"] = id });
- }
-
- public async Task<bool> CheckUserExistenceAsync(long id)
- {
- return await _database.Users.AnyAsync(u => u.Id == id);
- }
-
- public async Task<long> GetUserIdByUsernameAsync(string username)
- {
- if (username == null)
- throw new ArgumentNullException(nameof(username));
-
- if (!_usernameValidator.Validate(username, out var message))
- throw new ArgumentException(message);
-
- var entity = await _database.Users.Where(user => user.Username == username).Select(u => new { u.Id }).SingleOrDefaultAsync();
-
- if (entity == null)
- throw CreateUserNotExistException(username);
-
- return entity.Id;
- }
-
- public async Task<DateTime> GetUsernameLastModifiedTimeAsync(long userId)
- {
- var entity = await _database.Users.Where(u => u.Id == userId).Select(u => new { u.UsernameChangeTime }).SingleOrDefaultAsync();
-
- if (entity is null)
- throw CreateUserNotExistException(userId);
-
- return entity.UsernameChangeTime;
- }
- }
-}
|