From a3d73a6ba0972878a2044afe9c95d49876f386eb Mon Sep 17 00:00:00 2001 From: KotDimos Date: Thu, 23 Jun 2022 14:51:45 +0300 Subject: [PATCH 01/45] refactor: when add user, assigned base role --- Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs | 2 +- Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs index 7f6f6f1..69c7a74 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs @@ -92,7 +92,7 @@ public override ChatUser AddUser(MessengerUser user) if (user is null) throw new ArgumentNullException(nameof(user), $"User to add in chat {Name} is null"); - ChatUser newUser = CreateChatUser(user, _baseAdminRole); + ChatUser newUser = CreateChatUser(user, _baseUserRole); if (IsUserExist(user)) throw new Do_Svyazi_User_InnerLogicException($"User {user.Name} to add already exists in chat {Name}"); diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs index 28b705f..f0214c5 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs @@ -97,7 +97,7 @@ public override ChatUser AddUser(MessengerUser user) if (user is null) throw new ArgumentNullException(nameof(user), $"User to add in chat {Name} is null"); - ChatUser newUser = CreateChatUser(user, _baseAdminRole); + ChatUser newUser = CreateChatUser(user, _baseUserRole); if (IsUserExist(user)) throw new Do_Svyazi_User_InnerLogicException($"User {user.Name} to add already exists in chat {Name}"); From 89ab5ede33d7c02f923b496bec31e740d50e6c12 Mon Sep 17 00:00:00 2001 From: KotDimos Date: Thu, 23 Jun 2022 14:53:54 +0300 Subject: [PATCH 02/45] fix: bug, when add and remove chat from user --- .../Chats/Handlers/ChatsCommandHandler.cs | 15 ++++++++++++++ .../Users/MessengerUser.cs | 20 ++++++++++++++++++- .../DoSvaziDbContext.cs | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index d68e2a2..1e82ac9 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -89,6 +89,7 @@ await _context.Users.SingleOrDefaultAsync(user => user.Id == request.userId, can public async Task Handle(AddUserToChat request, CancellationToken cancellationToken) { Chat chat = await _context.Chats + .Include(chat => chat.Creator) .Include(chat => chat.Users) .ThenInclude(user => user.User) .Include(chat => chat.Users) @@ -102,9 +103,16 @@ public async Task Handle(AddUserToChat request, CancellationToken cancella throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.userId} to be added into chat with id = {request.chatId} not found"); + /* + if (chat.CreatorId == messengerUser.Id) + throw new Do_Svyazi_User_BusinessLogicException($"User {messengerUser.Name} is the creator"); + */ + ChatUser newChatUser = chat.AddUser(messengerUser); + MessengerUser m = messengerUser.AddChat(chat); await _context.ChatUsers.AddAsync(newChatUser, cancellationToken); + _context.Users.Update(m); await _context.SaveChangesAsync(cancellationToken); return Unit.Value; @@ -113,6 +121,7 @@ public async Task Handle(AddUserToChat request, CancellationToken cancella public async Task Handle(DeleteUserFromChat request, CancellationToken cancellationToken) { Chat chat = await _context.Chats + .Include(chat => chat.Creator) .Include(chat => chat.Users) .ThenInclude(user => user.User) .Include(chat => chat.Users) @@ -125,7 +134,13 @@ public async Task Handle(DeleteUserFromChat request, CancellationToken can throw new Do_Svyazi_User_NotFoundException( $"User with id {request.userId} not found"); + /* + if (chat.CreatorId == messengerUser.Id) + throw new Do_Svyazi_User_BusinessLogicException($"User {messengerUser.Name} is the creator"); + */ + chat.RemoveUser(messengerUser); + messengerUser.RemoveChat(chat); // TODO: debug, if chat removes from user's List property _context.Chats.Update(chat); diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs index d4e7164..74cfa3a 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs @@ -25,7 +25,7 @@ public MessengerUser() { } public string NickName { get; private set; } public string Description { get; private set; } - public IReadOnlyCollection Chats { get; } = new List(); + public List Chats { get; } = new (); public virtual void ChangeNickName(string nickName) { @@ -51,6 +51,24 @@ public virtual void ChangeDescription(string description) Description = description; } + public MessengerUser AddChat(Chat chat) + { + if (chat is null) + throw new ArgumentNullException(nameof(chat), $"Chat to add in user {Name} is null"); + + Chats.Add(chat); + + return this; + } + + public void RemoveChat(Chat chat) + { + if (chat is null) + throw new ArgumentNullException(nameof(chat), $"Chat to remove in user {Name} is null"); + + Chats.Remove(chat); + } + public override bool Equals(object? obj) => Equals(obj as MessengerUser); public override int GetHashCode() => HashCode.Combine(Id, Name); diff --git a/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs b/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs index b8acb65..121f524 100644 --- a/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs +++ b/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs @@ -11,6 +11,7 @@ public class DoSvaziDbContext : DbContext, IDbContext public DoSvaziDbContext(DbContextOptions options) : base(options) { + Database.EnsureCreated(); } protected DoSvaziDbContext() { } From f731ed1a2e32a7d5f15117d96183e075a2b4c27c Mon Sep 17 00:00:00 2001 From: KotDimos Date: Thu, 23 Jun 2022 15:49:42 +0300 Subject: [PATCH 03/45] refactor: delete creator in chat --- .../CQRS/Chats/Handlers/ChatsCommandHandler.cs | 15 ++------------- .../CQRS/Chats/Handlers/ChatsQueryHandler.cs | 2 -- .../Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs | 1 - .../Domain/Do-Svyazi.User.Domain/Chats/Channel.cs | 4 ++-- Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs | 2 -- .../Do-Svyazi.User.Domain/Chats/GroupChat.cs | 4 ++-- .../Do-Svyazi.User.Domain/Chats/PersonalChat.cs | 5 ++--- .../Do-Svyazi.User.Domain/Chats/SavedMessages.cs | 4 ++-- .../Do-Svyazi.User.Domain/Users/MessengerUser.cs | 4 +++- .../Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs | 3 --- 10 files changed, 13 insertions(+), 31 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index 1e82ac9..d08b1be 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -89,7 +89,6 @@ await _context.Users.SingleOrDefaultAsync(user => user.Id == request.userId, can public async Task Handle(AddUserToChat request, CancellationToken cancellationToken) { Chat chat = await _context.Chats - .Include(chat => chat.Creator) .Include(chat => chat.Users) .ThenInclude(user => user.User) .Include(chat => chat.Users) @@ -103,11 +102,6 @@ public async Task Handle(AddUserToChat request, CancellationToken cancella throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.userId} to be added into chat with id = {request.chatId} not found"); - /* - if (chat.CreatorId == messengerUser.Id) - throw new Do_Svyazi_User_BusinessLogicException($"User {messengerUser.Name} is the creator"); - */ - ChatUser newChatUser = chat.AddUser(messengerUser); MessengerUser m = messengerUser.AddChat(chat); @@ -121,7 +115,6 @@ public async Task Handle(AddUserToChat request, CancellationToken cancella public async Task Handle(DeleteUserFromChat request, CancellationToken cancellationToken) { Chat chat = await _context.Chats - .Include(chat => chat.Creator) .Include(chat => chat.Users) .ThenInclude(user => user.User) .Include(chat => chat.Users) @@ -134,16 +127,12 @@ public async Task Handle(DeleteUserFromChat request, CancellationToken can throw new Do_Svyazi_User_NotFoundException( $"User with id {request.userId} not found"); - /* - if (chat.CreatorId == messengerUser.Id) - throw new Do_Svyazi_User_BusinessLogicException($"User {messengerUser.Name} is the creator"); - */ - chat.RemoveUser(messengerUser); - messengerUser.RemoveChat(chat); + MessengerUser m = messengerUser.RemoveChat(chat); // TODO: debug, if chat removes from user's List property _context.Chats.Update(chat); + _context.Users.Update(m); await _context.SaveChangesAsync(cancellationToken); return Unit.Value; diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs index 689b048..6065df6 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs @@ -28,7 +28,6 @@ public ChatsQueryHandler(IDbContext context, IMapper mapper) public async Task Handle(GetChatById request, CancellationToken cancellationToken) { Chat chat = await _context.Chats - .Include(chat => chat.Creator) .Include(chat => chat.Users) .Include(chat => chat.Roles) .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? @@ -40,7 +39,6 @@ public async Task Handle(GetChatById request, CancellationToke public async Task> Handle(GetChats request, CancellationToken cancellationToken) { List chats = await _context.Chats - .Include(chat => chat.Creator) .Include(chat => chat.Users) .Include(chat => chat.Roles) .ToListAsync(cancellationToken: cancellationToken); diff --git a/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs b/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs index 72cf373..cf0d5ce 100644 --- a/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs +++ b/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs @@ -8,7 +8,6 @@ public record MessengerChatDto public Guid Id { get; init; } public string? Name { get; init; } public string? Description { get; init; } - public MessengerUserDto? Creator { get; init; } public IReadOnlyCollection Users { get; init; } = new List(); public IReadOnlyCollection Roles { get; init; } = new List(); } \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs index 69c7a74..9179358 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs @@ -48,8 +48,8 @@ public Channel(MessengerUser creator, string name, string description) BaseAdminRole = _baseAdminRole; BaseUserRole = _baseUserRole; - Creator = creator; - CreatorId = Creator.Id; + ChatUser user = CreateChatUser(creator, _baseAdminRole); + Users.Add(user); } protected Channel() diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs index e20c1f6..0e568e2 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs @@ -23,8 +23,6 @@ protected Chat(string name, string description) public Guid Id { get; protected init; } = Guid.NewGuid(); public string Name { get; protected set; } public string Description { get; protected set; } - public MessengerUser Creator { get; init; } - public Guid CreatorId { get; init; } public int MaxUsersAmount { get; init; } public List Users { get; init; } = new (); public List Roles { get; init; } = new (); diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs index f0214c5..0a0b230 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs @@ -51,8 +51,8 @@ public GroupChat(MessengerUser creator, string name, string description) BaseAdminRole = _baseAdminRole; BaseUserRole = _baseUserRole; - Creator = creator; - CreatorId = creator.Id; + ChatUser user = CreateChatUser(creator, _baseAdminRole); + Users.Add(user); } protected GroupChat() diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs index 6593f2a..f4da923 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs @@ -52,11 +52,10 @@ public PersonalChat(MessengerUser firstMessengerUser, MessengerUser secondMessen BaseAdminRole = _baseAdminRole; BaseUserRole = _baseUserRole; - Creator = firstMessengerUser; - CreatorId = firstMessengerUser.Id; + ChatUser firstUser = CreateChatUser(secondMessengerUser, _baseAdminRole); ChatUser secondUser = CreateChatUser(secondMessengerUser, _baseAdminRole); - Users.AddRange(new[] { secondUser }); + Users.AddRange(new[] { firstUser, secondUser }); } protected PersonalChat() diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/SavedMessages.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/SavedMessages.cs index ffc83d4..1af02c7 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/SavedMessages.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/SavedMessages.cs @@ -51,8 +51,8 @@ public SavedMessages(MessengerUser messengerUser, string name, string descriptio BaseAdminRole = _baseAdminRole; BaseUserRole = _baseUserRole; - Creator = messengerUser; - CreatorId = Creator.Id; + ChatUser user = CreateChatUser(messengerUser, _baseAdminRole); + Users.Add(user); } protected SavedMessages() diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs index 74cfa3a..898117f 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs @@ -61,12 +61,14 @@ public MessengerUser AddChat(Chat chat) return this; } - public void RemoveChat(Chat chat) + public MessengerUser RemoveChat(Chat chat) { if (chat is null) throw new ArgumentNullException(nameof(chat), $"Chat to remove in user {Name} is null"); Chats.Remove(chat); + + return this; } public override bool Equals(object? obj) => Equals(obj as MessengerUser); diff --git a/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs b/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs index 121f524..aa6ebd6 100644 --- a/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs +++ b/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs @@ -25,9 +25,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { ArgumentNullException.ThrowIfNull(modelBuilder); - modelBuilder.Entity() - .HasOne(chatUser => chatUser.Creator); - modelBuilder.Entity() .HasOne(chatUser => chatUser.Chat) .WithMany(chat => chat.Users) From c8786b9acc12e0eadc5555cb9950c0352d7312e6 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Thu, 23 Jun 2022 22:53:37 +0300 Subject: [PATCH 04/45] feat: AuthenticateByJwt scenario supported --- .../Handlers/AuthenticateCommandHandler.cs | 58 +++++++++---------- .../Handlers/AuthenticateQueryHandler.cs | 15 ++++- .../Authenticate/Queries/AuthenticateByJwt.cs | 6 ++ .../Extensions/ClaimsPrincipalExtensions.cs | 34 +++++++++++ .../Do-Svyazi.User.Web.Api/Startup.cs | 4 +- .../AuthenticateController.cs | 11 ++++ 6 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs create mode 100644 Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs index 94c446d..eee13b2 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs @@ -1,72 +1,67 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Handlers; +using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Exceptions; using MediatR; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; -public class AuthenticateCommandHandler - : ICommandHandler, - ICommandHandler +public class AuthenticateCommandHandler : + ICommandHandler, + ICommandHandler { private readonly UserManager _userManager; private readonly RoleManager _roleManager; + private readonly IDbContext _context; - public AuthenticateCommandHandler(UserManager userManager, RoleManager roleManager) + public AuthenticateCommandHandler( + UserManager userManager, + RoleManager roleManager, + IDbContext context) { _userManager = userManager; _roleManager = roleManager; + _context = context; } public async Task Handle(Register request, CancellationToken cancellationToken) { - MessageIdentityUser? userExists = await _userManager.FindByNameAsync(request.model.NickName); + if (await _userManager.FindByNameAsync(request.model.NickName) is not null) + throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - if (userExists != null) - { - throw new Do_Svyazi_User_BusinessLogicException( - "User already exists"); - } + var userId = await GetMessengerUserIdByNickName(request.model.NickName, cancellationToken); MessageIdentityUser user = new () { - SecurityStamp = Guid.NewGuid().ToString(), + SecurityStamp = userId.ToString(), UserName = request.model.NickName, Email = request.model.Email, }; - IdentityResult? result = await _userManager.CreateAsync(user, request.model.Password); - if (!result.Succeeded) - { - throw new Do_Svyazi_User_BusinessLogicException( - "User creation failed! Please check user details and try again."); - } + if (!(await _userManager.CreateAsync(user, request.model.Password)).Succeeded) + throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); return Unit.Value; } public async Task Handle(RegisterAdmin request, CancellationToken cancellationToken) { - MessageIdentityUser userExists = await _userManager.FindByNameAsync(request.model.NickName); - if (userExists != null) - { - throw new Do_Svyazi_User_BusinessLogicException( - "User already exists"); - } + if (await _userManager.FindByNameAsync(request.model.NickName) is not null) + throw new Do_Svyazi_User_BusinessLogicException("User already exists"); + + var userId = await GetMessengerUserIdByNickName(request.model.NickName, cancellationToken); MessageIdentityUser user = new () { - SecurityStamp = Guid.NewGuid().ToString(), + SecurityStamp = userId.ToString(), UserName = request.model.NickName, }; - IdentityResult? result = await _userManager.CreateAsync(user, request.model.Password); - if (!result.Succeeded) - { - throw new Do_Svyazi_User_BusinessLogicException( - "User creation failed! Please check user details and try again."); - } + + if (!(await _userManager.CreateAsync(user, request.model.Password)).Succeeded) + throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); if (await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) { @@ -82,4 +77,7 @@ public async Task Handle(RegisterAdmin request, CancellationToken cancella return Unit.Value; } + + private async Task GetMessengerUserIdByNickName(string nickName, CancellationToken cancellationToken) => + (await _context.Users.SingleAsync(user => user.NickName == nickName, cancellationToken: cancellationToken)).Id; } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs index c123b69..a531ba2 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs @@ -10,8 +10,9 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; -public class AuthenticateQueryHandler - : IQueryHandler +public class AuthenticateQueryHandler : + IQueryHandler, + IQueryHandler { private readonly UserManager _userManager; private readonly IConfiguration _configuration; @@ -45,6 +46,16 @@ public async Task Handle(Login request, CancellationToken canc return token; } + public async Task Handle(AuthenticateByJwt request, CancellationToken cancellationToken) + { + var token = new JwtSecurityToken(request.jwtToken); + string userNickName = token.Claims.First(x => x.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value; + + var identityUser = await _userManager.FindByNameAsync(userNickName); + + return identityUser.Id; + } + private JwtSecurityToken GetToken(List authClaims) { var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"])); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs new file mode 100644 index 0000000..8718ec7 --- /dev/null +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs @@ -0,0 +1,6 @@ +using MediatR; + +namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; + +public record AuthenticateByJwt(string jwtToken) + : IRequest; \ No newline at end of file diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs new file mode 100644 index 0000000..98011d1 --- /dev/null +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs @@ -0,0 +1,34 @@ +using System.Security.Claims; + +namespace Do_Svyazi.User.Web.Api.Extensions; + +public static class ClaimsPrincipalExtensions +{ + public static T GetLoggedInUserId(this ClaimsPrincipal principal) + { + if (principal == null) + throw new ArgumentNullException(nameof(principal)); + + var loggedInUserId = principal.FindFirstValue(ClaimTypes.NameIdentifier); + + if (typeof(T) == typeof(string)) + { + return (T)Convert.ChangeType(loggedInUserId, typeof(T)); + } + + if (typeof(T) == typeof(int) || typeof(T) == typeof(long)) + { + return loggedInUserId != null + ? (T)Convert.ChangeType(loggedInUserId, typeof(T)) + : (T)Convert.ChangeType(0, typeof(T)); + } + + throw new Exception("Invalid type provided"); + } + + public static string GetLoggedInUserName(this ClaimsPrincipal principal) => + principal.FindFirstValue(ClaimTypes.Name) ?? throw new ArgumentNullException(nameof(principal)); + + public static string GetLoggedInUserEmail(this ClaimsPrincipal principal) => + principal.FindFirstValue(ClaimTypes.Email) ?? throw new ArgumentNullException(nameof(principal)); +} \ No newline at end of file diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs index 745be87..3483a83 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs @@ -1,10 +1,10 @@ +using System.IdentityModel.Tokens.Jwt; using System.Text; using Do_Svyazi.User.Application.CQRS.Users.Queries; using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.DataAccess; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Dtos.Mapping; -using Do_Svyazi.User.Web.Controllers; using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -44,6 +44,8 @@ public void ConfigureServices(IServiceCollection services) options.UseSqlite(Configuration.GetConnectionString("Identity")); }); + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); + services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index 08af849..4143fcf 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -1,7 +1,9 @@ using System.IdentityModel.Tokens.Jwt; using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; +using Do_Svyazi.User.Domain.Authenticate; using MediatR; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; namespace Do_Svyazi.User.Web.Controllers; @@ -34,6 +36,15 @@ public async Task Register([FromBody] Register model, Cancellation return Ok(); } + [HttpGet] + [Route("AuthenticateUserByJwt")] + public async Task> AuthenticateByJwt( + [FromHeader] string jwtToken, CancellationToken cancellationToken) + { + var result = await _mediator.Send(new AuthenticateByJwt(jwtToken), cancellationToken); + return Ok(result); + } + [HttpPost] [Route("register-admin")] public async Task RegisterAdmin([FromBody] RegisterAdmin model, CancellationToken cancellationToken) From 7dba6ac69d273d7b8309beac5d8c399f87237db4 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Fri, 24 Jun 2022 00:05:06 +0300 Subject: [PATCH 05/45] fix: small codefix --- .../Handlers/AuthenticateCommandHandler.cs | 26 +++++++++++-------- .../Handlers/AuthenticateQueryHandler.cs | 13 ++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs index eee13b2..032e839 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs @@ -29,19 +29,21 @@ public AuthenticateCommandHandler( public async Task Handle(Register request, CancellationToken cancellationToken) { - if (await _userManager.FindByNameAsync(request.model.NickName) is not null) + var userModel = request.model; + + if (await _userManager.FindByNameAsync(userModel.NickName) is not null) throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - var userId = await GetMessengerUserIdByNickName(request.model.NickName, cancellationToken); + var userId = await GetMessengerUserIdByNickName(userModel.NickName, cancellationToken); MessageIdentityUser user = new () { - SecurityStamp = userId.ToString(), - UserName = request.model.NickName, - Email = request.model.Email, + SecurityStamp = $"{userId}", + UserName = userModel.NickName, + Email = userModel.Email, }; - if (!(await _userManager.CreateAsync(user, request.model.Password)).Succeeded) + if (!(await _userManager.CreateAsync(user, userModel.Password)).Succeeded) throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); return Unit.Value; @@ -49,18 +51,20 @@ public async Task Handle(Register request, CancellationToken cancellationT public async Task Handle(RegisterAdmin request, CancellationToken cancellationToken) { - if (await _userManager.FindByNameAsync(request.model.NickName) is not null) + var userModel = request.model; + + if (await _userManager.FindByNameAsync(userModel.NickName) is not null) throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - var userId = await GetMessengerUserIdByNickName(request.model.NickName, cancellationToken); + var userId = await GetMessengerUserIdByNickName(userModel.NickName, cancellationToken); MessageIdentityUser user = new () { - SecurityStamp = userId.ToString(), - UserName = request.model.NickName, + SecurityStamp = $"{userId}", + UserName = userModel.NickName, }; - if (!(await _userManager.CreateAsync(user, request.model.Password)).Succeeded) + if (!(await _userManager.CreateAsync(user, userModel.Password)).Succeeded) throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); if (await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs index a531ba2..86d7e6d 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs @@ -3,8 +3,10 @@ using System.Text; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using Do_Svyazi.User.Application.CQRS.Handlers; +using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Authenticate; using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.IdentityModel.Tokens; @@ -16,17 +18,21 @@ public class AuthenticateQueryHandler : { private readonly UserManager _userManager; private readonly IConfiguration _configuration; + private readonly IDbContext _context; - public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration) + public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration, IDbContext context) { _userManager = userManager; _configuration = configuration; + _context = context; } public async Task Handle(Login request, CancellationToken cancellationToken) { var token = new JwtSecurityToken(); MessageIdentityUser user = await _userManager.FindByNameAsync(request.model.NickName); + var userId = await GetMessengerUserIdByNickName(request.model.NickName, cancellationToken); + if (user != null && await _userManager.CheckPasswordAsync(user, request.model.Password)) { IList? userRoles = await _userManager.GetRolesAsync(user); @@ -34,7 +40,7 @@ public async Task Handle(Login request, CancellationToken canc var authClaims = new List { new Claim(ClaimTypes.Name, user.UserName), - new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), + new Claim(JwtRegisteredClaimNames.Jti, $"{userId}"), }; authClaims .AddRange(userRoles @@ -69,4 +75,7 @@ private JwtSecurityToken GetToken(List authClaims) return token; } + + private async Task GetMessengerUserIdByNickName(string nickName, CancellationToken cancellationToken) => + (await _context.Users.SingleAsync(user => user.NickName == nickName, cancellationToken: cancellationToken)).Id; } \ No newline at end of file From f392bb36d46e800a26b024f21285c7445b4bd101 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Fri, 24 Jun 2022 01:14:19 +0300 Subject: [PATCH 06/45] chore: stuff linked with auth --- .../Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs | 1 + .../Do-Svyazi.User.Web.Controllers/AuthenticateController.cs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs index 80859d1..ecb03f6 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs @@ -6,6 +6,7 @@ public record RegisterModel { [Required(ErrorMessage = "Name is required")] public string Name { get; init; } + [Required(ErrorMessage = "NickName is required")] public string NickName { get; init; } diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index 4143fcf..f9f453e 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -1,9 +1,7 @@ using System.IdentityModel.Tokens.Jwt; using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; -using Do_Svyazi.User.Domain.Authenticate; using MediatR; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; namespace Do_Svyazi.User.Web.Controllers; From 997b7d78355e4f10bc26ea412137d000888b8beb Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Fri, 24 Jun 2022 02:45:05 +0300 Subject: [PATCH 07/45] feat: auth supported in controllers --- .../AuthenticateController.cs | 14 ++++++-------- .../ChatController.cs | 2 ++ .../RolesController.cs | 2 ++ .../UserController.cs | 3 +++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index f9f453e..f323be6 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -2,6 +2,7 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Do_Svyazi.User.Web.Controllers; @@ -14,8 +15,7 @@ public class AuthenticateController : ControllerBase public AuthenticateController(IMediator mediator) => _mediator = mediator; - [HttpPost] - [Route("login")] + [HttpPost("login")] public async Task Login([FromBody] Login model, CancellationToken cancellationToken) { JwtSecurityToken token = await _mediator.Send(model, cancellationToken); @@ -26,16 +26,14 @@ public async Task Login([FromBody] Login model, CancellationToken }); } - [HttpPost] - [Route("register")] + [HttpPost("register")] public async Task Register([FromBody] Register model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); return Ok(); } - [HttpGet] - [Route("AuthenticateUserByJwt")] + [HttpGet("AuthenticateUserByJwt")] public async Task> AuthenticateByJwt( [FromHeader] string jwtToken, CancellationToken cancellationToken) { @@ -43,8 +41,8 @@ public async Task> AuthenticateByJwt( return Ok(result); } - [HttpPost] - [Route("register-admin")] + [HttpPost("register-admin")] + [Authorize] public async Task RegisterAdmin([FromBody] RegisterAdmin model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index d16035b..14d532c 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -3,6 +3,7 @@ using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -10,6 +11,7 @@ namespace Do_Svyazi.User.Web.Controllers; [Route("api/[controller]")] [ApiController] +[Authorize] public class ChatController : ControllerBase { private readonly IMediator _mediator; diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs index 36c9696..a8b8e93 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs @@ -1,5 +1,6 @@ using Do_Svyazi.User.Application.CQRS.Roles.Commands; using Do_Svyazi.User.Application.CQRS.Roles.Queries; +using Do_Svyazi.User.Application.Extensions; using Do_Svyazi.User.Dtos.Roles; using MediatR; using Microsoft.AspNetCore.Http; @@ -9,6 +10,7 @@ namespace Do_Svyazi.User.Web.Controllers; [Route("api/[controller]")] [ApiController] +[Authorize] public class RolesController : ControllerBase { private readonly IMediator _mediator; diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index 23d530d..0dafcde 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -4,6 +4,7 @@ using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Users; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,6 +12,7 @@ namespace Do_Svyazi.User.Web.Controllers; [Route("api/[controller]")] [ApiController] +[Authorize] public class UserController : ControllerBase { private readonly IMediator _mediator; @@ -71,6 +73,7 @@ public async Task DeleteUser(DeleteUser deleteUser, CancellationTo [HttpPost(nameof(AddUser))] [ProducesResponseType(StatusCodes.Status200OK)] + [AllowAnonymous] public async Task> AddUser(AddUser addUser, CancellationToken cancellationToken) { var response = await _mediator.Send(addUser, cancellationToken); From 9e102fcf6bfe3148e6ab7cff61cc0ef0a55b0ef3 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Fri, 24 Jun 2022 02:46:51 +0300 Subject: [PATCH 08/45] feat: auth supported in swagger --- .../Extensions/ServiceCollectionExtensions.cs | 123 ++++++++++++++++++ .../Do-Svyazi.User.Web.Api/Startup.cs | 79 ++--------- 2 files changed, 136 insertions(+), 66 deletions(-) create mode 100644 Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..d9e03a8 --- /dev/null +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,123 @@ +using System.Text; +using Do_Svyazi.User.Application.DbContexts; +using Do_Svyazi.User.DataAccess; +using Do_Svyazi.User.Domain.Authenticate; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using OpenApiInfo = Microsoft.OpenApi.Models.OpenApiInfo; +using OpenApiSecurityRequirement = Microsoft.OpenApi.Models.OpenApiSecurityRequirement; +using OpenApiSecurityScheme = Microsoft.OpenApi.Models.OpenApiSecurityScheme; + +namespace Do_Svyazi.User.Web.Api.Extensions; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddAuthServices(this IServiceCollection services, IConfiguration configuration) + { + services.AddIdentity(options => + { + options.Password = new PasswordOptions + { + RequireDigit = true, + RequireNonAlphanumeric = false, + RequireUppercase = true, + RequireLowercase = true, + RequiredLength = 6, + }; + + options.User = new UserOptions + { + RequireUniqueEmail = true, + }; + }) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; + }).AddJwtBearer(options => + { + options.SaveToken = true; + options.RequireHttpsMetadata = false; + options.TokenValidationParameters = new TokenValidationParameters() + { + ValidateIssuer = true, + ValidateAudience = true, + ValidAudience = configuration["JWT:ValidAudience"], + ValidIssuer = configuration["JWT:ValidIssuer"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JWT:Secret"])), + }; + }); + + services.AddAuthorization(); + + return services; + } + + public static IServiceCollection AddDomainServices(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext(optionsBuilder => + { + optionsBuilder.EnableSensitiveDataLogging(); + optionsBuilder.UseSqlite(configuration.GetConnectionString("Database")); + }); + + services.AddDbContext(options => + { + options.EnableSensitiveDataLogging(); + options.UseSqlite(configuration.GetConnectionString("Identity")); + }); + + return services; + } + + public static IServiceCollection AddSwaggerServices(this IServiceCollection services) + { + services.AddSwaggerGen(opt => + { + opt.UseInlineDefinitionsForEnums(); + + opt.SwaggerDoc("v1", new OpenApiInfo + { + Title = "Do Svyazi", + Version = "v1", + Description = "Do Svyazi API", + }); + + opt.AddSecurityDefinition("Bearer (value: SecretKey)", new OpenApiSecurityScheme + { + Description = "JWT Authorization header using the bearer scheme", + Name = "Authorization", + In = ParameterLocation.Header, + Scheme = "Bearer", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT", + }); + + opt.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Id = "Bearer (value: SecretKey)", + Type = ReferenceType.SecurityScheme, + }, + }, + new List() + }, + }); + }); + + return services; + } +} \ No newline at end of file diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs index 3483a83..ec4444a 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs @@ -1,21 +1,13 @@ -using System.IdentityModel.Tokens.Jwt; -using System.Text; using Do_Svyazi.User.Application.CQRS.Users.Queries; -using Do_Svyazi.User.Application.DbContexts; -using Do_Svyazi.User.DataAccess; -using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Dtos.Mapping; +using Do_Svyazi.User.Web.Api.Extensions; using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.IdentityModel.Tokens; namespace Do_Svyazi.User.Web.Api; @@ -27,81 +19,36 @@ public class Startup public void ConfigureServices(IServiceCollection services) { - services.AddControllers() + services + .AddControllers() .AddDo_SvyaziControllers() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); - services.AddDbContext(optionsBuilder => - { - optionsBuilder.EnableSensitiveDataLogging(); - optionsBuilder.UseSqlite(Configuration.GetConnectionString("Database")); - }); - - services.AddDbContext(options => - { - options.EnableSensitiveDataLogging(); - options.UseSqlite(Configuration.GetConnectionString("Identity")); - }); - - JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); - - services.AddIdentity() - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); - - services.AddAuthentication(options => - { - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; - }).AddJwtBearer(options => - { - options.SaveToken = true; - options.RequireHttpsMetadata = false; - options.TokenValidationParameters = new TokenValidationParameters() - { - ValidateIssuer = true, - ValidateAudience = true, - ValidAudience = Configuration["JWT:ValidAudience"], - ValidIssuer = Configuration["JWT:ValidIssuer"], - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT:Secret"])), - }; - }); - - services.AddEndpointsApiExplorer(); - services.AddSwaggerDocument(settings => - { - settings.Title = "Do-Svyazi.User"; - settings.PostProcess = document => - { - document.Info.Version = "v1"; - document.Info.Title = "Do-Svyazi.User"; - document.Info.Description = "Do-Svyazi.User module"; - }; - }); + services + .AddDomainServices(Configuration) + .AddAuthServices(Configuration) + .AddSwaggerServices() + .AddEndpointsApiExplorer(); services.AddMediatR(typeof(GetUsers).Assembly); services.AddAutoMapper(typeof(MappingProfile).Assembly); } + [Obsolete("Obsolete")] public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); - app.UseOpenApi(); - app.UseSwaggerUi3(c => - { - c.DocumentTitle = "Do-Svyazi.User"; - c.DocumentPath = "/swagger/v1/swagger.json"; - }); + app.UseSwagger(settings => { settings.RouteTemplate = "/swagger/{documentName}/swagger.json"; }); + app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Do Svyazi API")); app.UseHttpsRedirection(); + + app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); - app.UseRouting(); - app.UseEndpoints(endpoints => endpoints.MapControllers()); } } \ No newline at end of file From 450193ecd2ed0250871225063b48aed870050e1f Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Fri, 24 Jun 2022 02:48:54 +0300 Subject: [PATCH 09/45] style: redundant usings removed --- .../Extensions/ServiceCollectionExtensions.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs index d9e03a8..4ace5d4 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs @@ -9,9 +9,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; -using OpenApiInfo = Microsoft.OpenApi.Models.OpenApiInfo; -using OpenApiSecurityRequirement = Microsoft.OpenApi.Models.OpenApiSecurityRequirement; -using OpenApiSecurityScheme = Microsoft.OpenApi.Models.OpenApiSecurityScheme; namespace Do_Svyazi.User.Web.Api.Extensions; From 2a8045039bf80390ddf3dab63fe6540b611bf568 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Fri, 24 Jun 2022 03:08:21 +0300 Subject: [PATCH 10/45] fix: api versions updated in swagger --- .../Extensions/ServiceCollectionExtensions.cs | 8 ++++---- Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs index 4ace5d4..99b955c 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs @@ -82,11 +82,11 @@ public static IServiceCollection AddSwaggerServices(this IServiceCollection serv { opt.UseInlineDefinitionsForEnums(); - opt.SwaggerDoc("v1", new OpenApiInfo + opt.SwaggerDoc("v2.1.0", new OpenApiInfo { - Title = "Do Svyazi", - Version = "v1", - Description = "Do Svyazi API", + Title = "Do-Svyazi User module", + Version = "v2.1.0", + Description = "Do Svyazi User API", }); opt.AddSecurityDefinition("Bearer (value: SecretKey)", new OpenApiSecurityScheme diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs index ec4444a..26537b9 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs @@ -42,7 +42,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseDeveloperExceptionPage(); app.UseSwagger(settings => { settings.RouteTemplate = "/swagger/{documentName}/swagger.json"; }); - app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Do Svyazi API")); + app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v2.1.0/swagger.json", "Do-Svyazi User API")); app.UseHttpsRedirection(); From 1597e467efc183c2137b7b23dfc342c648bfdf3d Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:20:35 +0300 Subject: [PATCH 11/45] style: CQRS classes renamed with Command/Request suffix --- ...gisterAdmin.cs => RegisterAdminCommand.cs} | 2 +- .../{Register.cs => RegisterCommand.cs} | 2 +- ...teByJwt.cs => AuthenticateByJwtRequest.cs} | 2 +- .../Queries/{Login.cs => LoginRequest.cs} | 2 +- .../{AddGroupChat.cs => AddChannelCommand.cs} | 2 +- ...avedMessages.cs => AddGroupChatCommand.cs} | 2 +- .../CQRS/Chats/Commands/AddPersonalChat.cs | 6 ----- .../Chats/Commands/AddPersonalChatCommand.cs | 6 +++++ ...dChannel.cs => AddSavedMessagesCommand.cs} | 2 +- ...dUserToChat.cs => AddUserToChatCommand.cs} | 2 +- ...omChat.cs => DeleteUserFromChatCommand.cs} | 2 +- .../Chats/Handlers/ChatsCommandHandler.cs | 24 +++++++++---------- .../CQRS/Chats/Handlers/ChatsQueryHandler.cs | 16 ++++++------- .../{GetChatById.cs => GetChatByIdQuery.cs} | 2 +- .../Queries/{GetChats.cs => GetChatsQuery.cs} | 2 +- ...ByChatId.cs => GetUserIdsByChatIdQuery.cs} | 2 +- ...rsByChatId.cs => GetUsersByChatIdQuery.cs} | 2 +- .../Roles/Commands/ChangeUserRoleInChat.cs | 2 +- ...ForChat.cs => CreateRoleForChatCommand.cs} | 2 +- .../Roles/Handlers/RolesCommandHandler.cs | 8 +++---- .../CQRS/Roles/Handlers/RolesQueryHandler.cs | 4 ++-- ...oleByUserId.cs => GetRoleByUserIdQuery.cs} | 2 +- .../{AddUser.cs => AddUserCommand.cs} | 2 +- ...cs => ChangeUserDescriptionByIdCommand.cs} | 2 +- ...meById.cs => ChangeUserNameByIdCommand.cs} | 2 +- .../Users/Commands/ChangeUserNickNameById.cs | 2 +- .../{DeleteUser.cs => DeleteUserCommand.cs} | 2 +- .../Users/Handlers/UsersCommandHandler.cs | 20 ++++++++-------- .../CQRS/Users/Handlers/UsersQueryHandler.cs | 16 ++++++------- ...yUserId.cs => GetAllChatsByUserIdQuery.cs} | 2 +- ...erId.cs => GetAllChatsIdsByUserIdQuery.cs} | 2 +- .../Queries/{GetUser.cs => GetUserQuery.cs} | 2 +- .../Queries/{GetUsers.cs => GetUsersQuery.cs} | 2 +- Source/Tests/CQRS.Tests/ChatTests.cs | 6 ++--- Source/Tests/CQRS.Tests/UserTests.cs | 4 ++-- 35 files changed, 80 insertions(+), 80 deletions(-) rename Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/{RegisterAdmin.cs => RegisterAdminCommand.cs} (71%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/{Register.cs => RegisterCommand.cs} (73%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/{AuthenticateByJwt.cs => AuthenticateByJwtRequest.cs} (64%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/{Login.cs => LoginRequest.cs} (81%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/{AddGroupChat.cs => AddChannelCommand.cs} (54%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/{AddSavedMessages.cs => AddGroupChatCommand.cs} (54%) delete mode 100644 Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChat.cs create mode 100644 Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChatCommand.cs rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/{AddChannel.cs => AddSavedMessagesCommand.cs} (53%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/{AddUserToChat.cs => AddUserToChatCommand.cs} (61%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/{DeleteUserFromChat.cs => DeleteUserFromChatCommand.cs} (57%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/{GetChatById.cs => GetChatByIdQuery.cs} (76%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/{GetChats.cs => GetChatsQuery.cs} (85%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/{GetUserIdsByChatId.cs => GetUserIdsByChatIdQuery.cs} (69%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/{GetUsersByChatId.cs => GetUsersByChatIdQuery.cs} (76%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/{CreateRoleForChat.cs => CreateRoleForChatCommand.cs} (65%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/{GetRoleByUserId.cs => GetRoleByUserIdQuery.cs} (68%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/{AddUser.cs => AddUserCommand.cs} (54%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/{ChangeUserDescriptionById.cs => ChangeUserDescriptionByIdCommand.cs} (52%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/{ChangeUserNameById.cs => ChangeUserNameByIdCommand.cs} (57%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/{DeleteUser.cs => DeleteUserCommand.cs} (66%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/{GetAllChatsByUserId.cs => GetAllChatsByUserIdQuery.cs} (74%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/{GetAllChatsIdsByUserId.cs => GetAllChatsIdsByUserIdQuery.cs} (66%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/{GetUser.cs => GetUserQuery.cs} (77%) rename Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/{GetUsers.cs => GetUsersQuery.cs} (85%) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterAdmin.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterAdminCommand.cs similarity index 71% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterAdmin.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterAdminCommand.cs index 2804a68..8ec3564 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterAdmin.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterAdminCommand.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Commands; -public record RegisterAdmin(RegisterModel model) +public record RegisterAdminCommand(RegisterModel model) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/Register.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs similarity index 73% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/Register.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs index 80f109e..2efb426 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/Register.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Commands; -public record Register(RegisterModel model) +public record RegisterCommand(RegisterModel model) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs similarity index 64% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs index 8718ec7..05647a0 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwt.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; -public record AuthenticateByJwt(string jwtToken) +public record AuthenticateByJwtRequest(string jwtToken) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/Login.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/LoginRequest.cs similarity index 81% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/Login.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/LoginRequest.cs index 8ba61cb..296ad9c 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/Login.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/LoginRequest.cs @@ -4,5 +4,5 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; -public record Login(LoginModel model) +public record LoginRequest(LoginModel model) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddGroupChat.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddChannelCommand.cs similarity index 54% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddGroupChat.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddChannelCommand.cs index 5e8f593..ee392ff 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddGroupChat.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddChannelCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; -public record AddGroupChat(Guid adminId, string name, string description) +public record AddChannelCommand(Guid adminId, string name, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddSavedMessages.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddGroupChatCommand.cs similarity index 54% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddSavedMessages.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddGroupChatCommand.cs index 9868dbe..baa9869 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddSavedMessages.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddGroupChatCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; -public record AddSavedMessages(Guid userId, string name, string description) +public record AddGroupChatCommand(Guid adminId, string name, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChat.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChat.cs deleted file mode 100644 index 51f18f0..0000000 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChat.cs +++ /dev/null @@ -1,6 +0,0 @@ -using MediatR; - -namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; - -public record AddPersonalChat(Guid firstUserId, Guid secondUserId, string name, string description) - : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChatCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChatCommand.cs new file mode 100644 index 0000000..b233078 --- /dev/null +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddPersonalChatCommand.cs @@ -0,0 +1,6 @@ +using MediatR; + +namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; + +public record AddPersonalChatCommand(Guid firstUserId, Guid secondUserId, string name, string description) + : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddChannel.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddSavedMessagesCommand.cs similarity index 53% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddChannel.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddSavedMessagesCommand.cs index 5886aff..e5d0b1f 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddChannel.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddSavedMessagesCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; -public record AddChannel(Guid adminId, string name, string description) +public record AddSavedMessagesCommand(Guid userId, string name, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddUserToChat.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddUserToChatCommand.cs similarity index 61% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddUserToChat.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddUserToChatCommand.cs index 44b3250..103bfc0 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddUserToChat.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/AddUserToChatCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; -public record AddUserToChat(Guid userId, Guid chatId) +public record AddUserToChatCommand(Guid userId, Guid chatId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/DeleteUserFromChat.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/DeleteUserFromChatCommand.cs similarity index 57% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/DeleteUserFromChat.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/DeleteUserFromChatCommand.cs index 6a9410d..dd04423 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/DeleteUserFromChat.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Commands/DeleteUserFromChatCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Commands; -public record DeleteUserFromChat(Guid userId, Guid chatId) +public record DeleteUserFromChatCommand(Guid userId, Guid chatId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index d08b1be..e66d3d6 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -10,18 +10,18 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Handlers; public class ChatsCommandHandler : - ICommandHandler, - ICommandHandler, - ICommandHandler, - ICommandHandler, - ICommandHandler, - ICommandHandler + ICommandHandler, + ICommandHandler, + ICommandHandler, + ICommandHandler, + ICommandHandler, + ICommandHandler { private readonly IDbContext _context; public ChatsCommandHandler(IDbContext context) => _context = context; - public async Task Handle(AddChannel request, CancellationToken cancellationToken) + public async Task Handle(AddChannelCommand request, CancellationToken cancellationToken) { MessengerUser user = await _context.Users .SingleOrDefaultAsync(user => user.Id == request.adminId, cancellationToken) ?? @@ -36,7 +36,7 @@ public async Task Handle(AddChannel request, CancellationToken cancellatio return chat.Id; } - public async Task Handle(AddGroupChat request, CancellationToken cancellationToken) + public async Task Handle(AddGroupChatCommand request, CancellationToken cancellationToken) { MessengerUser user = await _context.Users .SingleOrDefaultAsync(user => user.Id == request.adminId, cancellationToken) ?? @@ -51,7 +51,7 @@ public async Task Handle(AddGroupChat request, CancellationToken cancellat return chat.Id; } - public async Task Handle(AddPersonalChat request, CancellationToken cancellationToken) + public async Task Handle(AddPersonalChatCommand request, CancellationToken cancellationToken) { MessengerUser firstUser = await _context.Users.SingleOrDefaultAsync(user => user.Id == request.firstUserId, cancellationToken) ?? @@ -71,7 +71,7 @@ await _context.Users.SingleOrDefaultAsync(user => user.Id == request.secondUserI return chat.Id; } - public async Task Handle(AddSavedMessages request, CancellationToken cancellationToken) + public async Task Handle(AddSavedMessagesCommand request, CancellationToken cancellationToken) { MessengerUser user = await _context.Users.SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? @@ -86,7 +86,7 @@ await _context.Users.SingleOrDefaultAsync(user => user.Id == request.userId, can return chat.Id; } - public async Task Handle(AddUserToChat request, CancellationToken cancellationToken) + public async Task Handle(AddUserToChatCommand request, CancellationToken cancellationToken) { Chat chat = await _context.Chats .Include(chat => chat.Users) @@ -112,7 +112,7 @@ public async Task Handle(AddUserToChat request, CancellationToken cancella return Unit.Value; } - public async Task Handle(DeleteUserFromChat request, CancellationToken cancellationToken) + public async Task Handle(DeleteUserFromChatCommand request, CancellationToken cancellationToken) { Chat chat = await _context.Chats .Include(chat => chat.Users) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs index 6065df6..c415a76 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs @@ -11,10 +11,10 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Handlers; public class ChatsQueryHandler : - IQueryHandler, - IQueryHandler>, - IQueryHandler>, - IQueryHandler> + IQueryHandler, + IQueryHandler>, + IQueryHandler>, + IQueryHandler> { private readonly IDbContext _context; private readonly IMapper _mapper; @@ -25,7 +25,7 @@ public ChatsQueryHandler(IDbContext context, IMapper mapper) _mapper = mapper; } - public async Task Handle(GetChatById request, CancellationToken cancellationToken) + public async Task Handle(GetChatByIdQuery request, CancellationToken cancellationToken) { Chat chat = await _context.Chats .Include(chat => chat.Users) @@ -36,7 +36,7 @@ public async Task Handle(GetChatById request, CancellationToke return _mapper.Map(chat); } - public async Task> Handle(GetChats request, CancellationToken cancellationToken) + public async Task> Handle(GetChatsQuery request, CancellationToken cancellationToken) { List chats = await _context.Chats .Include(chat => chat.Users) @@ -46,7 +46,7 @@ public async Task> Handle(GetChats request return _mapper.Map>(chats); } - public async Task> Handle(GetUserIdsByChatId request, CancellationToken cancellationToken) + public async Task> Handle(GetUserIdsByChatIdQuery request, CancellationToken cancellationToken) { Chat chat = await _context.Chats .Include(chat => chat.Users) @@ -58,7 +58,7 @@ public async Task> Handle(GetUserIdsByChatId request, return _mapper.Map>(userIds); } - public async Task> Handle(GetUsersByChatId request, CancellationToken cancellationToken) + public async Task> Handle(GetUsersByChatIdQuery request, CancellationToken cancellationToken) { Chat chat = await _context.Chats .Include(chat => chat.Users) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatById.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatByIdQuery.cs similarity index 76% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatById.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatByIdQuery.cs index a7308cf..6dd8016 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatById.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatByIdQuery.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Queries; -public record GetChatById(Guid chatId) +public record GetChatByIdQuery(Guid chatId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChats.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatsQuery.cs similarity index 85% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChats.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatsQuery.cs index 7b4ab43..7c29859 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChats.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetChatsQuery.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Queries; -public record GetChats +public record GetChatsQuery : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUserIdsByChatId.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUserIdsByChatIdQuery.cs similarity index 69% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUserIdsByChatId.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUserIdsByChatIdQuery.cs index b115b78..318e57b 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUserIdsByChatId.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUserIdsByChatIdQuery.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Queries; using MediatR; -public record GetUserIdsByChatId(Guid chatId) +public record GetUserIdsByChatIdQuery(Guid chatId) : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatId.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs similarity index 76% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatId.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs index 807fd77..d312dc3 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatId.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs @@ -4,5 +4,5 @@ namespace Do_Svyazi.User.Application.CQRS.Chats.Queries; using MediatR; -public record GetUsersByChatId(Guid chatId) +public record GetUsersByChatIdQuery(Guid chatId) : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/ChangeUserRoleInChat.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/ChangeUserRoleInChat.cs index d0fee20..4608e44 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/ChangeUserRoleInChat.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/ChangeUserRoleInChat.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Roles.Commands; -public record ChangeRoleForUserById(Guid userId, Guid chatId, RoleDto role) +public record ChangeRoleForUserByIdCommand(Guid userId, Guid chatId, RoleDto role) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/CreateRoleForChat.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/CreateRoleForChatCommand.cs similarity index 65% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/CreateRoleForChat.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/CreateRoleForChatCommand.cs index 6c38645..4292cb8 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/CreateRoleForChat.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Commands/CreateRoleForChatCommand.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Roles.Commands; -public record CreateRoleForChat(RoleDto role, Guid chatId) +public record CreateRoleForChatCommand(RoleDto role, Guid chatId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesCommandHandler.cs index d7ea98c..deb5f15 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesCommandHandler.cs @@ -11,13 +11,13 @@ namespace Do_Svyazi.User.Application.CQRS.Roles.Handlers; public class RolesCommandHandler : - ICommandHandler, - IRequestHandler + ICommandHandler, + IRequestHandler { private readonly IDbContext _context; public RolesCommandHandler(IDbContext context) => _context = context; - public async Task Handle(ChangeRoleForUserById request, CancellationToken cancellationToken) + public async Task Handle(ChangeRoleForUserByIdCommand request, CancellationToken cancellationToken) { ChatUser chatUser = await _context.ChatUsers @@ -60,7 +60,7 @@ await _context.ChatUsers return Unit.Value; } - public async Task Handle(CreateRoleForChat request, CancellationToken cancellationToken) + public async Task Handle(CreateRoleForChatCommand request, CancellationToken cancellationToken) { Chat chat = await _context.Chats.FindAsync(request.chatId) ?? throw new Do_Svyazi_User_NotFoundException( diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesQueryHandler.cs index 82e010c..4e26f27 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Handlers/RolesQueryHandler.cs @@ -10,7 +10,7 @@ namespace Do_Svyazi.User.Application.CQRS.Roles.Handlers; public class RolesQueryHandler - : IQueryHandler + : IQueryHandler { private readonly IDbContext _context; private readonly IMapper _mapper; @@ -21,7 +21,7 @@ public RolesQueryHandler(IDbContext context, IMapper mapper) _mapper = mapper; } - public async Task Handle(GetRoleByUserId request, CancellationToken cancellationToken) + public async Task Handle(GetRoleByUserIdQuery request, CancellationToken cancellationToken) { ChatUser chatUser = await _context.ChatUsers diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/GetRoleByUserId.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/GetRoleByUserIdQuery.cs similarity index 68% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/GetRoleByUserId.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/GetRoleByUserIdQuery.cs index fdd3230..a13911d 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/GetRoleByUserId.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Roles/Queries/GetRoleByUserIdQuery.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Roles.Queries; -public record GetRoleByUserId(Guid userId, Guid chatId) +public record GetRoleByUserIdQuery(Guid userId, Guid chatId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/AddUser.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/AddUserCommand.cs similarity index 54% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/AddUser.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/AddUserCommand.cs index 0c0c053..94fc899 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/AddUser.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/AddUserCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record AddUser(string name, string nickName, string description) +public record AddUserCommand(string name, string nickName, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionById.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs similarity index 52% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionById.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs index 03b8997..daa01e2 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionById.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record ChangeUserDescriptionById(Guid userId, string description) +public record ChangeUserDescriptionByIdCommand(Guid userId, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameById.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs similarity index 57% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameById.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs index c1f2125..e82f5e3 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameById.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record ChangeUserNameById(Guid userId, string name) +public record ChangeUserNameByIdCommand(Guid userId, string name) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs index 4631a5c..8e78b60 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record SetUserNickNameById(Guid userId, string nickName) +public record SetUserNickNameByIdCommand(Guid userId, string nickName) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUser.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs similarity index 66% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUser.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs index 7cec04d..a4121a8 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUser.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record DeleteUser(Guid userId) +public record DeleteUserCommand(Guid userId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs index 1ea6c0c..905a600 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs @@ -8,16 +8,16 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Handlers; public class UsersCommandHandler : - IQueryHandler, - IQueryHandler, - IQueryHandler, - IQueryHandler, - IQueryHandler + IQueryHandler, + IQueryHandler, + IQueryHandler, + IQueryHandler, + IQueryHandler { private readonly IDbContext _context; public UsersCommandHandler(IDbContext context) => _context = context; - public async Task Handle(AddUser request, CancellationToken cancellationToken) + public async Task Handle(AddUserCommand request, CancellationToken cancellationToken) { if (NickNameExists(request.nickName)) { @@ -33,7 +33,7 @@ public async Task Handle(AddUser request, CancellationToken cancellationTo return messengerUser.Id; } - public async Task Handle(ChangeUserDescriptionById request, CancellationToken cancellationToken) + public async Task Handle(ChangeUserDescriptionByIdCommand request, CancellationToken cancellationToken) { MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException( @@ -47,7 +47,7 @@ public async Task Handle(ChangeUserDescriptionById request, CancellationTo return Unit.Value; } - public async Task Handle(ChangeUserNameById request, CancellationToken cancellationToken) + public async Task Handle(ChangeUserNameByIdCommand request, CancellationToken cancellationToken) { MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException($"User with id {request.userId} to change name was not found"); @@ -60,7 +60,7 @@ public async Task Handle(ChangeUserNameById request, CancellationToken can return Unit.Value; } - public async Task Handle(SetUserNickNameById request, CancellationToken cancellationToken) + public async Task Handle(SetUserNickNameByIdCommand request, CancellationToken cancellationToken) { MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException( @@ -77,7 +77,7 @@ public async Task Handle(SetUserNickNameById request, CancellationToken ca return Unit.Value; } - public async Task Handle(DeleteUser request, CancellationToken cancellationToken) + public async Task Handle(DeleteUserCommand request, CancellationToken cancellationToken) { MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException($"Can't find user with id = {request.userId} to delete"); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs index 4d64c73..fa584b5 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs @@ -11,10 +11,10 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Handlers; public class UsersQueryHandler : - IQueryHandler>, - IQueryHandler>, - IQueryHandler, - IQueryHandler> + IQueryHandler>, + IQueryHandler>, + IQueryHandler, + IQueryHandler> { private readonly IDbContext _context; private readonly IMapper _mapper; @@ -25,7 +25,7 @@ public UsersQueryHandler(IDbContext context, IMapper mapper) _mapper = mapper; } - public async Task> Handle(GetAllChatsByUserId request, CancellationToken cancellationToken) + public async Task> Handle(GetAllChatsByUserIdQuery request, CancellationToken cancellationToken) { MessengerUser messengerUser = await _context.Users .Include(user => user.Chats) @@ -37,7 +37,7 @@ public async Task> Handle(GetAllChatsByUserId re return chats; } - public async Task> Handle(GetAllChatsIdsByUserId request, CancellationToken cancellationToken) + public async Task> Handle(GetAllChatsIdsByUserIdQuery request, CancellationToken cancellationToken) { MessengerUser messengerUser = await _context.Users .Include(user => user.Chats) @@ -49,7 +49,7 @@ public async Task> Handle(GetAllChatsIdsByUserId request, Ca return chatIds; } - public async Task Handle(GetUser request, CancellationToken cancellationToken) + public async Task Handle(GetUserQuery request, CancellationToken cancellationToken) { MessengerUser user = await _context.Users .Include(user => user.Chats) @@ -59,7 +59,7 @@ public async Task Handle(GetUser request, CancellationToken cance return user; } - public async Task> Handle(GetUsers request, CancellationToken cancellationToken) + public async Task> Handle(GetUsersQuery request, CancellationToken cancellationToken) { List users = await _context.Users .ToListAsync(cancellationToken: cancellationToken); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsByUserId.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsByUserIdQuery.cs similarity index 74% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsByUserId.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsByUserIdQuery.cs index 7da9958..969b95a 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsByUserId.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsByUserIdQuery.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Queries; -public record GetAllChatsByUserId(Guid userId) +public record GetAllChatsByUserIdQuery(Guid userId) : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsIdsByUserId.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsIdsByUserIdQuery.cs similarity index 66% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsIdsByUserId.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsIdsByUserIdQuery.cs index ea991e0..46dc476 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsIdsByUserId.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetAllChatsIdsByUserIdQuery.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Queries; -public record GetAllChatsIdsByUserId(Guid userId) +public record GetAllChatsIdsByUserIdQuery(Guid userId) : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUser.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs similarity index 77% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUser.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs index c4dc1ca..104f50f 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUser.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Queries; -public record GetUser(Guid userId) +public record GetUserQuery(Guid userId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUsers.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUsersQuery.cs similarity index 85% rename from Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUsers.cs rename to Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUsersQuery.cs index 4c2eaf3..cf2688d 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUsers.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUsersQuery.cs @@ -3,5 +3,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Queries; -public record GetUsers +public record GetUsersQuery : IRequest>; \ No newline at end of file diff --git a/Source/Tests/CQRS.Tests/ChatTests.cs b/Source/Tests/CQRS.Tests/ChatTests.cs index 5e90180..2f4e2a7 100644 --- a/Source/Tests/CQRS.Tests/ChatTests.cs +++ b/Source/Tests/CQRS.Tests/ChatTests.cs @@ -29,7 +29,7 @@ public async Task AddUserToChat_UserAdded( dbContextMock.CreateDbSetMock(x => x.ChatUsers); var addUserToChatHandler = new ChatsCommandHandler(dbContextMock.Object); - var addUserToChatCommand = new AddUserToChat(user.Id, chat.Id); + var addUserToChatCommand = new AddUserToChatCommand(user.Id, chat.Id); chat.Users.Should().HaveCount(0); @@ -60,12 +60,12 @@ public async Task DeleteUserFromChat_UsersListEmpty( var chatsCommandHandler = new ChatsCommandHandler(dbContextMock.Object); - var addUserToChatCommand = new AddUserToChat(user.Id, chat.Id); + var addUserToChatCommand = new AddUserToChatCommand(user.Id, chat.Id); await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); chat.Users.Should().HaveCount(1); - var deleteUserToChatCommand = new DeleteUserFromChat(user.Id, chat.Id); + var deleteUserToChatCommand = new DeleteUserFromChatCommand(user.Id, chat.Id); await chatsCommandHandler.Handle(deleteUserToChatCommand, CancellationToken.None); chat.Users.Should().HaveCount(0); diff --git a/Source/Tests/CQRS.Tests/UserTests.cs b/Source/Tests/CQRS.Tests/UserTests.cs index 396374f..dfd608d 100644 --- a/Source/Tests/CQRS.Tests/UserTests.cs +++ b/Source/Tests/CQRS.Tests/UserTests.cs @@ -23,7 +23,7 @@ public async Task AddUser_UserAdded([Greedy] MessengerUser user) var usersCommandHandler = new UsersCommandHandler(dbContextMock.Object); - var addUserCommand = new AddUser(user.Name, user.NickName, user.Description); + var addUserCommand = new AddUserCommand(user.Name, user.NickName, user.Description); await usersCommandHandler.Handle(addUserCommand, CancellationToken.None); MessengerUser gainMessengerUser = dbContextMock.Object.Users.Single(); @@ -43,7 +43,7 @@ public async Task ChangeUserNameById_UserNameChanged( var usersCommandHandler = new UsersCommandHandler(dbContextMock.Object); - var changeUserNameCommand = new ChangeUserNameById(user.Id, newName); + var changeUserNameCommand = new ChangeUserNameByIdCommand(user.Id, newName); await usersCommandHandler.Handle(changeUserNameCommand, CancellationToken.None); MessengerUser gainMessengerUser = dbContextMock.Object.Users.Single(); From 3efc7a016ba5c4a573a9a8a410fa45060c6d7467 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:23:10 +0300 Subject: [PATCH 12/45] fix: auth redeveloped again... --- .../Handlers/AuthenticateCommandHandler.cs | 45 +++++++------ .../Handlers/AuthenticateQueryHandler.cs | 65 +++++++++++-------- .../Authenticate/Queries/GetUsersRequest.cs | 7 ++ .../Authenticate/LoginModel.cs | 18 ++--- .../Authenticate/RegisterModel.cs | 8 +-- .../AuthenticateController.cs | 25 ++++--- .../ChatController.cs | 28 ++++---- .../Helpers/AuthorizeAttribute.cs | 20 ++++++ .../Middlewares/AuthorizationMiddleware.cs | 65 +++++++++++++++++++ .../RolesController.cs | 14 ++-- .../UserController.cs | 34 +++++----- 11 files changed, 214 insertions(+), 115 deletions(-) create mode 100644 Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs create mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs create mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs index 032e839..8aa0ce9 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs @@ -10,8 +10,8 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; public class AuthenticateCommandHandler : - ICommandHandler, - ICommandHandler + ICommandHandler, + ICommandHandler { private readonly UserManager _userManager; private readonly RoleManager _roleManager; @@ -27,44 +27,35 @@ public AuthenticateCommandHandler( _context = context; } - public async Task Handle(Register request, CancellationToken cancellationToken) + public async Task Handle(RegisterCommand request, CancellationToken cancellationToken) { - var userModel = request.model; + RegisterModel registerModel = request.model; - if (await _userManager.FindByNameAsync(userModel.NickName) is not null) + if (await _userManager.FindByNameAsync(registerModel.NickName) is not null) throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - var userId = await GetMessengerUserIdByNickName(userModel.NickName, cancellationToken); + Guid userId = await GetMessengerUserIdByNickName(registerModel.NickName, cancellationToken); - MessageIdentityUser user = new () - { - SecurityStamp = $"{userId}", - UserName = userModel.NickName, - Email = userModel.Email, - }; + MessageIdentityUser user = CreateIdentityUser(registerModel, userId); - if (!(await _userManager.CreateAsync(user, userModel.Password)).Succeeded) + if (!(await _userManager.CreateAsync(user, registerModel.Password)).Succeeded) throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); return Unit.Value; } - public async Task Handle(RegisterAdmin request, CancellationToken cancellationToken) + public async Task Handle(RegisterAdminCommand request, CancellationToken cancellationToken) { - var userModel = request.model; + RegisterModel registerModel = request.model; - if (await _userManager.FindByNameAsync(userModel.NickName) is not null) + if (await _userManager.FindByNameAsync(registerModel.NickName) is not null) throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - var userId = await GetMessengerUserIdByNickName(userModel.NickName, cancellationToken); + Guid userId = await GetMessengerUserIdByNickName(registerModel.NickName, cancellationToken); - MessageIdentityUser user = new () - { - SecurityStamp = $"{userId}", - UserName = userModel.NickName, - }; + MessageIdentityUser user = CreateIdentityUser(registerModel, userId); - if (!(await _userManager.CreateAsync(user, userModel.Password)).Succeeded) + if (!(await _userManager.CreateAsync(user, registerModel.Password)).Succeeded) throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); if (await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) @@ -84,4 +75,12 @@ public async Task Handle(RegisterAdmin request, CancellationToken cancella private async Task GetMessengerUserIdByNickName(string nickName, CancellationToken cancellationToken) => (await _context.Users.SingleAsync(user => user.NickName == nickName, cancellationToken: cancellationToken)).Id; + + private MessageIdentityUser CreateIdentityUser(RegisterModel userModel, Guid userId) => new () + { + Id = userId, + UserName = userModel.NickName, + Email = userModel.Email, + PhoneNumber = userModel.PhoneNumber, + }; } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs index 86d7e6d..f5d2cc7 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs @@ -3,8 +3,8 @@ using System.Text; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using Do_Svyazi.User.Application.CQRS.Handlers; -using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Authenticate; +using Do_Svyazi.User.Domain.Exceptions; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -13,55 +13,56 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; public class AuthenticateQueryHandler : - IQueryHandler, - IQueryHandler + IQueryHandler, + IQueryHandler, + IQueryHandler> { + private const string NameType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; + private readonly UserManager _userManager; private readonly IConfiguration _configuration; - private readonly IDbContext _context; - public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration, IDbContext context) + public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration) { _userManager = userManager; _configuration = configuration; - _context = context; } - public async Task Handle(Login request, CancellationToken cancellationToken) + public async Task Handle(LoginRequest request, CancellationToken cancellationToken) { var token = new JwtSecurityToken(); - MessageIdentityUser user = await _userManager.FindByNameAsync(request.model.NickName); - var userId = await GetMessengerUserIdByNickName(request.model.NickName, cancellationToken); + LoginModel loginModel = request.model; + MessageIdentityUser user = await GetUserByUsernameOrEmail(loginModel); - if (user != null && await _userManager.CheckPasswordAsync(user, request.model.Password)) - { - IList? userRoles = await _userManager.GetRolesAsync(user); + if (!await _userManager.CheckPasswordAsync(user, loginModel.Password)) return token; + + IList? userRoles = await _userManager.GetRolesAsync(user); - var authClaims = new List - { - new Claim(ClaimTypes.Name, user.UserName), - new Claim(JwtRegisteredClaimNames.Jti, $"{userId}"), - }; - authClaims - .AddRange(userRoles - .Select(userRole => new Claim(ClaimTypes.Role, userRole))); + var authClaims = new List + { + new Claim(ClaimTypes.Name, user.UserName), + new Claim(JwtRegisteredClaimNames.Jti, $"{user.Id}"), + }; - token = GetToken(authClaims); - } + authClaims + .AddRange(userRoles + .Select(userRole => new Claim(ClaimTypes.Role, userRole))); - return token; + return GetToken(authClaims); } - public async Task Handle(AuthenticateByJwt request, CancellationToken cancellationToken) + public async Task Handle(AuthenticateByJwtRequest request, CancellationToken cancellationToken) { var token = new JwtSecurityToken(request.jwtToken); - string userNickName = token.Claims.First(x => x.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name").Value; + string userNickName = token.Claims.First(x => x.Type == NameType).Value; var identityUser = await _userManager.FindByNameAsync(userNickName); - return identityUser.Id; } + public async Task> Handle(GetUsersRequest request, CancellationToken cancellationToken) + => await _userManager.Users.ToListAsync(cancellationToken: cancellationToken); + private JwtSecurityToken GetToken(List authClaims) { var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"])); @@ -76,6 +77,14 @@ private JwtSecurityToken GetToken(List authClaims) return token; } - private async Task GetMessengerUserIdByNickName(string nickName, CancellationToken cancellationToken) => - (await _context.Users.SingleAsync(user => user.NickName == nickName, cancellationToken: cancellationToken)).Id; + private async Task GetUserByUsernameOrEmail(LoginModel loginModel) + { + if (loginModel.NickName is not null) + return await _userManager.FindByNameAsync(loginModel.NickName); + + if (loginModel.Email is not null) + return await _userManager.FindByEmailAsync(loginModel.Email); + + throw new Do_Svyazi_User_NotFoundException("User to login was not found"); + } } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs new file mode 100644 index 0000000..4a33a75 --- /dev/null +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs @@ -0,0 +1,7 @@ +using Do_Svyazi.User.Domain.Authenticate; +using MediatR; + +namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; + +public record GetUsersRequest + : IRequest>; \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs index b73ceb9..4776b33 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs @@ -2,21 +2,13 @@ namespace Do_Svyazi.User.Domain.Authenticate; -public class LoginModel +public record LoginModel { - public Guid Id { get; protected init; } = Guid.NewGuid(); - - [Required(ErrorMessage = "NickName is required")] - public string NickName { get; set; } + public string? NickName { get; init; } + public string? Email { get; init; } [Required(ErrorMessage = "Password is required")] - public string? Password { get; set; } - - public override int GetHashCode() => HashCode.Combine(Id, NickName); - public override bool Equals(object? obj) => Equals(obj as LoginModel); + public string? Password { get; init; } - private bool Equals(LoginModel? login) => - login is not null && - Id.Equals(login.Id) && - NickName.Equals(login.NickName); + public override int GetHashCode() => HashCode.Combine(NickName, Email); } \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs index ecb03f6..e276170 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs @@ -4,16 +4,14 @@ namespace Do_Svyazi.User.Domain.Authenticate; public record RegisterModel { - [Required(ErrorMessage = "Name is required")] - public string Name { get; init; } - [Required(ErrorMessage = "NickName is required")] public string NickName { get; init; } [Required(ErrorMessage = "Email is required")] - public string? Email { get; set; } + public string Email { get; init; } [Required(ErrorMessage = "Password is required")] - public string? Password { get; set; } + public string Password { get; init; } + public string PhoneNumber { get; init; } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index f323be6..c553500 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -1,6 +1,7 @@ using System.IdentityModel.Tokens.Jwt; using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; +using Do_Svyazi.User.Domain.Authenticate; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -15,8 +16,16 @@ public class AuthenticateController : ControllerBase public AuthenticateController(IMediator mediator) => _mediator = mediator; - [HttpPost("login")] - public async Task Login([FromBody] Login model, CancellationToken cancellationToken) + [HttpGet(nameof(GetAll))] + [Authorize] + public async Task> GetAll(CancellationToken cancellationToken) + { + var response = await _mediator.Send(new GetUsersRequest(), cancellationToken); + return response; + } + + [HttpPost(nameof(Login))] + public async Task Login([FromBody] LoginRequest model, CancellationToken cancellationToken) { JwtSecurityToken token = await _mediator.Send(model, cancellationToken); return Ok(new @@ -26,24 +35,24 @@ public async Task Login([FromBody] Login model, CancellationToken }); } - [HttpPost("register")] - public async Task Register([FromBody] Register model, CancellationToken cancellationToken) + [HttpPost(nameof(Register))] + public async Task Register([FromBody] RegisterCommand model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); return Ok(); } - [HttpGet("AuthenticateUserByJwt")] + [HttpGet(nameof(AuthenticateByJwt))] public async Task> AuthenticateByJwt( [FromHeader] string jwtToken, CancellationToken cancellationToken) { - var result = await _mediator.Send(new AuthenticateByJwt(jwtToken), cancellationToken); + var result = await _mediator.Send(new AuthenticateByJwtRequest(jwtToken), cancellationToken); return Ok(result); } - [HttpPost("register-admin")] + [HttpPost(nameof(RegisterAdmin))] [Authorize] - public async Task RegisterAdmin([FromBody] RegisterAdmin model, CancellationToken cancellationToken) + public async Task RegisterAdmin([FromBody] RegisterAdminCommand model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); return Ok(); diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index 14d532c..83e7b27 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -2,8 +2,8 @@ using Do_Svyazi.User.Application.CQRS.Chats.Queries; using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; +using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -22,41 +22,41 @@ public class ChatController : ControllerBase [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetChats(CancellationToken cancellationToken) { - var response = await _mediator.Send(new GetChats(), cancellationToken); + var response = await _mediator.Send(new GetChatsQuery(), cancellationToken); return Ok(response); } [HttpGet(nameof(GetChatById))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetChatById( - [FromQuery] GetChatById getChatById, CancellationToken cancellationToken) + [FromQuery] GetChatByIdQuery getChatByIdQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getChatById, cancellationToken); + var response = await _mediator.Send(getChatByIdQuery, cancellationToken); return Ok(response); } [HttpGet(nameof(GetUserIdsByChatId))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetUserIdsByChatId( - [FromQuery] GetUserIdsByChatId getUserIdsByChatId, CancellationToken cancellationToken) + [FromQuery] GetUserIdsByChatIdQuery getUserIdsByChatIdQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getUserIdsByChatId, cancellationToken); + var response = await _mediator.Send(getUserIdsByChatIdQuery, cancellationToken); return Ok(response); } [HttpGet(nameof(GetUsersByChatId))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetUsersByChatId( - [FromQuery] GetUsersByChatId getUsersByChatId, CancellationToken cancellationToken) + [FromQuery] GetUsersByChatIdQuery getUsersByChatIdQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getUsersByChatId, cancellationToken); + var response = await _mediator.Send(getUsersByChatIdQuery, cancellationToken); return Ok(response); } [HttpPost(nameof(AddChannel))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddChannel( - AddChannel addChannelCommand, CancellationToken cancellationToken) + AddChannelCommand addChannelCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addChannelCommand, cancellationToken); return Ok(response); @@ -65,7 +65,7 @@ public async Task AddChannel( [HttpPost(nameof(AddGroupChat))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddGroupChat( - AddGroupChat addGroupChatCommand, CancellationToken cancellationToken) + AddGroupChatCommand addGroupChatCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addGroupChatCommand, cancellationToken); return Ok(response); @@ -74,7 +74,7 @@ public async Task AddGroupChat( [HttpPost(nameof(AddPersonalChat))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddPersonalChat( - AddPersonalChat addPersonalChatCommand, CancellationToken cancellationToken) + AddPersonalChatCommand addPersonalChatCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addPersonalChatCommand, cancellationToken); return Ok(response); @@ -83,7 +83,7 @@ public async Task AddPersonalChat( [HttpPost(nameof(AddSavedMessages))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddSavedMessages( - AddSavedMessages addSavedMessagesCommand, CancellationToken cancellationToken) + AddSavedMessagesCommand addSavedMessagesCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addSavedMessagesCommand, cancellationToken); return Ok(response); @@ -92,7 +92,7 @@ public async Task AddSavedMessages( [HttpPost(nameof(AddUserToChat))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task AddUserToChat( - AddUserToChat addUserToChatCommand, CancellationToken cancellationToken) + AddUserToChatCommand addUserToChatCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addUserToChatCommand, cancellationToken); return Ok(response); @@ -101,7 +101,7 @@ public async Task AddUserToChat( [HttpDelete(nameof(DeleteUserFromChat))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task DeleteUserFromChat( - DeleteUserFromChat deleteUserFromChatCommand, CancellationToken cancellationToken) + DeleteUserFromChatCommand deleteUserFromChatCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(deleteUserFromChatCommand, cancellationToken); return Ok(response); diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs new file mode 100644 index 0000000..ca1348a --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs @@ -0,0 +1,20 @@ +using Do_Svyazi.User.Domain.Authenticate; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Do_Svyazi.User.Web.Controllers.Helpers; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] +public class AuthorizeAttribute : Attribute, IAuthorizationFilter +{ + public void OnAuthorization(AuthorizationFilterContext context) + { + var user = context.HttpContext.Items["User"] as MessageIdentityUser; + + if (user == null) + { + context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized }; + } + } +} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs new file mode 100644 index 0000000..d9b0a9d --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs @@ -0,0 +1,65 @@ +using System.IdentityModel.Tokens.Jwt; +using System.Text; +using Do_Svyazi.User.Domain.Authenticate; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; + +namespace Do_Svyazi.User.Web.Controllers.Middlewares; + +public class AuthorizationMiddleware +{ + private readonly RequestDelegate _next; + private readonly IConfiguration _configuration; + private readonly UserManager _userManager; + + public AuthorizationMiddleware( + RequestDelegate next, IConfiguration configuration, UserManager userManager) + { + _next = next; + _configuration = configuration; + _userManager = userManager; + } + + public async Task Invoke(HttpContext context) + { + var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last(); + + if (token != null) + await AttachUserToContext(context, token); + + await _next(context); + } + + private async Task AttachUserToContext(HttpContext context, string token) + { + try + { + var tokenHandler = new JwtSecurityTokenHandler(); + var key = Encoding.UTF8.GetBytes(_configuration["JWT:Secret"]); + tokenHandler.ValidateToken( + token, + new TokenValidationParameters + { + ValidateIssuerSigningKey = true, + IssuerSigningKey = new SymmetricSecurityKey(key), + ValidateIssuer = false, + ValidateAudience = false, + ClockSkew = TimeSpan.Zero, + }, out SecurityToken validatedToken); + + var jwtToken = validatedToken as JwtSecurityToken; + string? userId = jwtToken?.Claims.First(x => x.Type == "jti").Value; + + // attach user to context on successful jwt validation + var user = await _userManager.FindByIdAsync(userId); + context.Items["User"] = user; + } + catch + { + context.Response.StatusCode = 401; + await context.Response.WriteAsync("Wrong auth credentials"); + } + } +} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs index a8b8e93..73d1a97 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs @@ -1,8 +1,8 @@ using Do_Svyazi.User.Application.CQRS.Roles.Commands; using Do_Svyazi.User.Application.CQRS.Roles.Queries; -using Do_Svyazi.User.Application.Extensions; using Do_Svyazi.User.Dtos.Roles; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -20,27 +20,27 @@ public class RolesController : ControllerBase [HttpGet(nameof(GetRoleByUserId))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetRoleByUserId( - [FromQuery] GetRoleByUserId getRoleByUserId, CancellationToken cancellationToken) + [FromQuery] GetRoleByUserIdQuery getRoleByUserIdQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getRoleByUserId, cancellationToken); + var response = await _mediator.Send(getRoleByUserIdQuery, cancellationToken); return Ok(response); } [HttpPost(nameof(CreateRoleForChat))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task CreateRoleForChat( - CreateRoleForChat createRoleForChat, CancellationToken cancellationToken) + CreateRoleForChatCommand createRoleForChatCommand, CancellationToken cancellationToken) { - await _mediator.Send(createRoleForChat, cancellationToken); + await _mediator.Send(createRoleForChatCommand, cancellationToken); return Ok(); } [HttpPost(nameof(ChangeRoleForUserById))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task ChangeRoleForUserById( - ChangeRoleForUserById changeRoleForUserById, CancellationToken cancellationToken) + ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, CancellationToken cancellationToken) { - await _mediator.Send(changeRoleForUserById, cancellationToken); + await _mediator.Send(changeRoleForUserByIdCommand, cancellationToken); return Ok(); } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index 0dafcde..dde57af 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -23,77 +23,77 @@ public class UserController : ControllerBase [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetUsers(CancellationToken cancellationToken) { - var response = await _mediator.Send(new GetUsers(), cancellationToken); + var response = await _mediator.Send(new GetUsersQuery(), cancellationToken); return Ok(response); } [HttpGet(nameof(GetUser))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetUser( - [FromQuery] GetUser getUser, CancellationToken cancellationToken) + [FromQuery] GetUserQuery getUserQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getUser, cancellationToken); + var response = await _mediator.Send(getUserQuery, cancellationToken); return Ok(response); } [HttpGet(nameof(GetAllChatsByUserId))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetAllChatsByUserId( - [FromQuery] GetAllChatsByUserId getAllChatsByUserId, CancellationToken cancellationToken) + [FromQuery] GetAllChatsByUserIdQuery getAllChatsByUserIdQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getAllChatsByUserId, cancellationToken); + var response = await _mediator.Send(getAllChatsByUserIdQuery, cancellationToken); return Ok(response); } [HttpGet(nameof(GetAllChatsIdsByUserId))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetAllChatsIdsByUserId( - [FromQuery] GetAllChatsIdsByUserId getAllChatsIdsByUserId, CancellationToken cancellationToken) + [FromQuery] GetAllChatsIdsByUserIdQuery getAllChatsIdsByUserIdQuery, CancellationToken cancellationToken) { - var response = await _mediator.Send(getAllChatsIdsByUserId, cancellationToken); + var response = await _mediator.Send(getAllChatsIdsByUserIdQuery, cancellationToken); return Ok(response); } [HttpPost(nameof(SetNickNameById))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task SetNickNameById( - SetUserNickNameById setUserNickNameById, CancellationToken cancellationToken) + SetUserNickNameByIdCommand setUserNickNameByIdCommand, CancellationToken cancellationToken) { - await _mediator.Send(setUserNickNameById, cancellationToken); + await _mediator.Send(setUserNickNameByIdCommand, cancellationToken); return Ok(); } [HttpPost(nameof(DeleteUser))] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task DeleteUser(DeleteUser deleteUser, CancellationToken cancellationToken) + public async Task DeleteUser(DeleteUserCommand deleteUserCommand, CancellationToken cancellationToken) { - await _mediator.Send(deleteUser, cancellationToken); + await _mediator.Send(deleteUserCommand, cancellationToken); return Ok(); } [HttpPost(nameof(AddUser))] [ProducesResponseType(StatusCodes.Status200OK)] [AllowAnonymous] - public async Task> AddUser(AddUser addUser, CancellationToken cancellationToken) + public async Task> AddUser(AddUserCommand addUserCommand, CancellationToken cancellationToken) { - var response = await _mediator.Send(addUser, cancellationToken); + var response = await _mediator.Send(addUserCommand, cancellationToken); return Ok(response); } [HttpPost(nameof(ChangeDescription))] [ProducesResponseType(StatusCodes.Status200OK)] public async Task ChangeDescription( - ChangeUserDescriptionById changeUserDescriptionById, CancellationToken cancellationToken) + ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, CancellationToken cancellationToken) { - await _mediator.Send(changeUserDescriptionById, cancellationToken); + await _mediator.Send(changeUserDescriptionByIdCommand, cancellationToken); return Ok(); } [HttpPost(nameof(ChangeName))] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task ChangeName(ChangeUserNameById changeUserNameById, CancellationToken cancellationToken) + public async Task ChangeName(ChangeUserNameByIdCommand changeUserNameByIdCommand, CancellationToken cancellationToken) { - await _mediator.Send(changeUserNameById, cancellationToken); + await _mediator.Send(changeUserNameByIdCommand, cancellationToken); return Ok(); } } \ No newline at end of file From 28ef062e44fe04c9bb073af258b850fc86c1c00e Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:24:55 +0300 Subject: [PATCH 13/45] style: codestyle tips in controllers --- .../AuthenticateController.cs | 14 ++++++++++---- .../UserController.cs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index c553500..e37980c 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -4,6 +4,7 @@ using Do_Svyazi.User.Domain.Authenticate; using MediatR; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Do_Svyazi.User.Web.Controllers; @@ -16,15 +17,17 @@ public class AuthenticateController : ControllerBase public AuthenticateController(IMediator mediator) => _mediator = mediator; - [HttpGet(nameof(GetAll))] [Authorize] - public async Task> GetAll(CancellationToken cancellationToken) + [HttpGet(nameof(GetAll))] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task>> GetAll(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetUsersRequest(), cancellationToken); - return response; + return Ok(response); } [HttpPost(nameof(Login))] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task Login([FromBody] LoginRequest model, CancellationToken cancellationToken) { JwtSecurityToken token = await _mediator.Send(model, cancellationToken); @@ -36,6 +39,7 @@ public async Task Login([FromBody] LoginRequest model, Cancellatio } [HttpPost(nameof(Register))] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task Register([FromBody] RegisterCommand model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); @@ -43,6 +47,7 @@ public async Task Register([FromBody] RegisterCommand model, Cance } [HttpGet(nameof(AuthenticateByJwt))] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task> AuthenticateByJwt( [FromHeader] string jwtToken, CancellationToken cancellationToken) { @@ -50,8 +55,9 @@ public async Task> AuthenticateByJwt( return Ok(result); } - [HttpPost(nameof(RegisterAdmin))] [Authorize] + [HttpPost(nameof(RegisterAdmin))] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task RegisterAdmin([FromBody] RegisterAdminCommand model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index dde57af..711095e 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -71,9 +71,9 @@ public async Task DeleteUser(DeleteUserCommand deleteUserCommand, return Ok(); } + [AllowAnonymous] [HttpPost(nameof(AddUser))] [ProducesResponseType(StatusCodes.Status200OK)] - [AllowAnonymous] public async Task> AddUser(AddUserCommand addUserCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addUserCommand, cancellationToken); From 7f8535d50f7863138d61db081782abba3764d273 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:37:07 +0300 Subject: [PATCH 14/45] feat: error-codes throwing and handling supported --- .../AuthenticateController.cs | 16 ++++---- .../ChatController.cs | 39 +++++++++---------- .../Middlewares/ErrorHandlingMiddleware.cs | 34 ++++++++++++++++ .../RolesController.cs | 16 ++++---- .../UserController.cs | 31 +++++++-------- 5 files changed, 85 insertions(+), 51 deletions(-) create mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index e37980c..4da9b87 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -9,8 +9,11 @@ namespace Do_Svyazi.User.Web.Controllers; -[Route("api/[controller]")] [ApiController] +[Route("api/[controller]")] +[ProducesResponseType(StatusCodes.Status200OK)] +[ProducesResponseType(StatusCodes.Status401Unauthorized)] +[ProducesResponseType(StatusCodes.Status500InternalServerError)] public class AuthenticateController : ControllerBase { private readonly IMediator _mediator; @@ -19,7 +22,6 @@ public class AuthenticateController : ControllerBase [Authorize] [HttpGet(nameof(GetAll))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetAll(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetUsersRequest(), cancellationToken); @@ -27,7 +29,6 @@ public async Task>> GetAll } [HttpPost(nameof(Login))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task Login([FromBody] LoginRequest model, CancellationToken cancellationToken) { JwtSecurityToken token = await _mediator.Send(model, cancellationToken); @@ -39,15 +40,14 @@ public async Task Login([FromBody] LoginRequest model, Cancellatio } [HttpPost(nameof(Register))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Register([FromBody] RegisterCommand model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); - return Ok(); + return NoContent(); } [HttpGet(nameof(AuthenticateByJwt))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task> AuthenticateByJwt( [FromHeader] string jwtToken, CancellationToken cancellationToken) { @@ -57,10 +57,10 @@ public async Task> AuthenticateByJwt( [Authorize] [HttpPost(nameof(RegisterAdmin))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task RegisterAdmin([FromBody] RegisterAdminCommand model, CancellationToken cancellationToken) { await _mediator.Send(model, cancellationToken); - return Ok(); + return NoContent(); } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index 83e7b27..67f160b 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -9,9 +9,12 @@ namespace Do_Svyazi.User.Web.Controllers; -[Route("api/[controller]")] -[ApiController] [Authorize] +[ApiController] +[Route("api/[controller]")] +[ProducesResponseType(StatusCodes.Status200OK)] +[ProducesResponseType(StatusCodes.Status401Unauthorized)] +[ProducesResponseType(StatusCodes.Status500InternalServerError)] public class ChatController : ControllerBase { private readonly IMediator _mediator; @@ -19,7 +22,6 @@ public class ChatController : ControllerBase public ChatController(IMediator mediator) => _mediator = mediator; [HttpGet(nameof(GetChats))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetChats(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetChatsQuery(), cancellationToken); @@ -27,7 +29,6 @@ public async Task>> GetChats( } [HttpGet(nameof(GetChatById))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetChatById( [FromQuery] GetChatByIdQuery getChatByIdQuery, CancellationToken cancellationToken) { @@ -36,7 +37,6 @@ public async Task> GetChatById( } [HttpGet(nameof(GetUserIdsByChatId))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetUserIdsByChatId( [FromQuery] GetUserIdsByChatIdQuery getUserIdsByChatIdQuery, CancellationToken cancellationToken) { @@ -45,7 +45,6 @@ public async Task>> GetUserIdsByChatId( } [HttpGet(nameof(GetUsersByChatId))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetUsersByChatId( [FromQuery] GetUsersByChatIdQuery getUsersByChatIdQuery, CancellationToken cancellationToken) { @@ -54,56 +53,56 @@ public async Task>> GetUsersByChatId( } [HttpPost(nameof(AddChannel))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task AddChannel( AddChannelCommand addChannelCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addChannelCommand, cancellationToken); - return Ok(response); + return Created(nameof(AddChannel), response); } [HttpPost(nameof(AddGroupChat))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task AddGroupChat( AddGroupChatCommand addGroupChatCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addGroupChatCommand, cancellationToken); - return Ok(response); + return Created(nameof(AddGroupChat), response); } [HttpPost(nameof(AddPersonalChat))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task AddPersonalChat( AddPersonalChatCommand addPersonalChatCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addPersonalChatCommand, cancellationToken); - return Ok(response); + return Created(nameof(AddPersonalChat), response); } [HttpPost(nameof(AddSavedMessages))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task AddSavedMessages( AddSavedMessagesCommand addSavedMessagesCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addSavedMessagesCommand, cancellationToken); - return Ok(response); + return Created(nameof(AddSavedMessages), response); } [HttpPost(nameof(AddUserToChat))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task AddUserToChat( AddUserToChatCommand addUserToChatCommand, CancellationToken cancellationToken) { - var response = await _mediator.Send(addUserToChatCommand, cancellationToken); - return Ok(response); + await _mediator.Send(addUserToChatCommand, cancellationToken); + return NoContent(); } [HttpDelete(nameof(DeleteUserFromChat))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task DeleteUserFromChat( DeleteUserFromChatCommand deleteUserFromChatCommand, CancellationToken cancellationToken) { - var response = await _mediator.Send(deleteUserFromChatCommand, cancellationToken); - return Ok(response); + await _mediator.Send(deleteUserFromChatCommand, cancellationToken); + return NoContent(); } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs new file mode 100644 index 0000000..1d41c52 --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs @@ -0,0 +1,34 @@ +using Do_Svyazi.User.Domain.Exceptions; +using Microsoft.AspNetCore.Http; + +namespace Do_Svyazi.User.Web.Controllers.Middlewares; + +public class ErrorHandlingMiddleware +{ + private readonly RequestDelegate _next; + + public ErrorHandlingMiddleware(RequestDelegate next) => _next = next; + + public async Task Invoke(HttpContext context) + { + try + { + await _next(context); + } + catch (Do_Svyazi_User_BusinessLogicException e) + { + context.Response.StatusCode = 400; + await context.Response.WriteAsync(e.Message); + } + catch (Do_Svyazi_User_NotFoundException e) + { + context.Response.StatusCode = 404; + await context.Response.WriteAsync(e.Message); + } + catch (Exception e) + { + context.Response.StatusCode = 500; + await context.Response.WriteAsJsonAsync(e.Message); + } + } +} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs index 73d1a97..7dac829 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs @@ -8,9 +8,12 @@ namespace Do_Svyazi.User.Web.Controllers; -[Route("api/[controller]")] -[ApiController] [Authorize] +[ApiController] +[Route("api/[controller]")] +[ProducesResponseType(StatusCodes.Status200OK)] +[ProducesResponseType(StatusCodes.Status401Unauthorized)] +[ProducesResponseType(StatusCodes.Status500InternalServerError)] public class RolesController : ControllerBase { private readonly IMediator _mediator; @@ -18,7 +21,6 @@ public class RolesController : ControllerBase public RolesController(IMediator mediator) => _mediator = mediator; [HttpGet(nameof(GetRoleByUserId))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetRoleByUserId( [FromQuery] GetRoleByUserIdQuery getRoleByUserIdQuery, CancellationToken cancellationToken) { @@ -27,20 +29,20 @@ public async Task> GetRoleByUserId( } [HttpPost(nameof(CreateRoleForChat))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task CreateRoleForChat( CreateRoleForChatCommand createRoleForChatCommand, CancellationToken cancellationToken) { await _mediator.Send(createRoleForChatCommand, cancellationToken); - return Ok(); + return NoContent(); } [HttpPost(nameof(ChangeRoleForUserById))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task ChangeRoleForUserById( ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, CancellationToken cancellationToken) { await _mediator.Send(changeRoleForUserByIdCommand, cancellationToken); - return Ok(); + return NoContent(); } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index 711095e..d4086e2 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -10,9 +10,12 @@ namespace Do_Svyazi.User.Web.Controllers; -[Route("api/[controller]")] -[ApiController] [Authorize] +[ApiController] +[Route("api/[controller]")] +[ProducesResponseType(StatusCodes.Status200OK)] +[ProducesResponseType(StatusCodes.Status401Unauthorized)] +[ProducesResponseType(StatusCodes.Status500InternalServerError)] public class UserController : ControllerBase { private readonly IMediator _mediator; @@ -20,7 +23,6 @@ public class UserController : ControllerBase public UserController(IMediator mediator) => _mediator = mediator; [HttpGet("GetAll")] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetUsers(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetUsersQuery(), cancellationToken); @@ -28,7 +30,6 @@ public async Task>> GetUsers( } [HttpGet(nameof(GetUser))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetUser( [FromQuery] GetUserQuery getUserQuery, CancellationToken cancellationToken) { @@ -37,7 +38,6 @@ public async Task> GetUser( } [HttpGet(nameof(GetAllChatsByUserId))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetAllChatsByUserId( [FromQuery] GetAllChatsByUserIdQuery getAllChatsByUserIdQuery, CancellationToken cancellationToken) { @@ -46,7 +46,6 @@ public async Task>> GetAllChatsByUs } [HttpGet(nameof(GetAllChatsIdsByUserId))] - [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetAllChatsIdsByUserId( [FromQuery] GetAllChatsIdsByUserIdQuery getAllChatsIdsByUserIdQuery, CancellationToken cancellationToken) { @@ -55,45 +54,45 @@ public async Task>> GetAllChatsIdsByUserId( } [HttpPost(nameof(SetNickNameById))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task SetNickNameById( SetUserNickNameByIdCommand setUserNickNameByIdCommand, CancellationToken cancellationToken) { await _mediator.Send(setUserNickNameByIdCommand, cancellationToken); - return Ok(); + return NoContent(); } [HttpPost(nameof(DeleteUser))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task DeleteUser(DeleteUserCommand deleteUserCommand, CancellationToken cancellationToken) { await _mediator.Send(deleteUserCommand, cancellationToken); - return Ok(); + return NoContent(); } [AllowAnonymous] [HttpPost(nameof(AddUser))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status201Created)] public async Task> AddUser(AddUserCommand addUserCommand, CancellationToken cancellationToken) { var response = await _mediator.Send(addUserCommand, cancellationToken); - return Ok(response); + return Created(nameof(AddUser), response); } [HttpPost(nameof(ChangeDescription))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task ChangeDescription( ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, CancellationToken cancellationToken) { await _mediator.Send(changeUserDescriptionByIdCommand, cancellationToken); - return Ok(); + return NoContent(); } [HttpPost(nameof(ChangeName))] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task ChangeName(ChangeUserNameByIdCommand changeUserNameByIdCommand, CancellationToken cancellationToken) { await _mediator.Send(changeUserNameByIdCommand, cancellationToken); - return Ok(); + return NoContent(); } } \ No newline at end of file From 9a3b5781ad7857db6cd22ee25b8e7407f7db859f Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:37:23 +0300 Subject: [PATCH 15/45] feat: middlewares registered --- Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs index 26537b9..bbce022 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs @@ -1,6 +1,7 @@ using Do_Svyazi.User.Application.CQRS.Users.Queries; using Do_Svyazi.User.Dtos.Mapping; using Do_Svyazi.User.Web.Api.Extensions; +using Do_Svyazi.User.Web.Controllers.Middlewares; using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Builder; @@ -31,7 +32,7 @@ public void ConfigureServices(IServiceCollection services) .AddSwaggerServices() .AddEndpointsApiExplorer(); - services.AddMediatR(typeof(GetUsers).Assembly); + services.AddMediatR(typeof(GetUsersQuery).Assembly); services.AddAutoMapper(typeof(MappingProfile).Assembly); } @@ -49,6 +50,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); + + app.UseMiddleware(); + app.UseMiddleware(); + app.UseEndpoints(endpoints => endpoints.MapControllers()); } } \ No newline at end of file From 47e3ceb8126972da49d675ab27cd8f99db9af812 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:53:25 +0300 Subject: [PATCH 16/45] feat: error-handling middleware replaced with error-handling filter --- .../Chats/MessengerChatDto.cs | 1 - .../Do-Svyazi.User.Web.Api/Startup.cs | 1 - .../AuthenticateController.cs | 2 ++ .../ChatController.cs | 2 ++ .../Middlewares/ErrorHandlingMiddleware.cs | 34 ------------------- .../RolesController.cs | 2 ++ .../Tools/ExceptionFilterAttribute.cs | 32 +++++++++++++++++ .../UserController.cs | 2 ++ 8 files changed, 40 insertions(+), 36 deletions(-) delete mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs create mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs diff --git a/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs b/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs index cf0d5ce..22e54d8 100644 --- a/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs +++ b/Source/Application/Do-Svyazi.User.Dtos/Chats/MessengerChatDto.cs @@ -1,5 +1,4 @@ using Do_Svyazi.User.Dtos.Roles; -using Do_Svyazi.User.Dtos.Users; namespace Do_Svyazi.User.Dtos.Chats; diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs index bbce022..9e019d0 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs @@ -52,7 +52,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseAuthorization(); app.UseMiddleware(); - app.UseMiddleware(); app.UseEndpoints(endpoints => endpoints.MapControllers()); } diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index 4da9b87..4247d79 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -2,6 +2,7 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using Do_Svyazi.User.Domain.Authenticate; +using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -11,6 +12,7 @@ namespace Do_Svyazi.User.Web.Controllers; [ApiController] [Route("api/[controller]")] +[ExceptionFilter] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index 67f160b..82c44d1 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -3,6 +3,7 @@ using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Web.Controllers.Helpers; +using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,6 +12,7 @@ namespace Do_Svyazi.User.Web.Controllers; [Authorize] [ApiController] +[ExceptionFilter] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs deleted file mode 100644 index 1d41c52..0000000 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Do_Svyazi.User.Domain.Exceptions; -using Microsoft.AspNetCore.Http; - -namespace Do_Svyazi.User.Web.Controllers.Middlewares; - -public class ErrorHandlingMiddleware -{ - private readonly RequestDelegate _next; - - public ErrorHandlingMiddleware(RequestDelegate next) => _next = next; - - public async Task Invoke(HttpContext context) - { - try - { - await _next(context); - } - catch (Do_Svyazi_User_BusinessLogicException e) - { - context.Response.StatusCode = 400; - await context.Response.WriteAsync(e.Message); - } - catch (Do_Svyazi_User_NotFoundException e) - { - context.Response.StatusCode = 404; - await context.Response.WriteAsync(e.Message); - } - catch (Exception e) - { - context.Response.StatusCode = 500; - await context.Response.WriteAsJsonAsync(e.Message); - } - } -} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs index 7dac829..1a5f18b 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs @@ -1,6 +1,7 @@ using Do_Svyazi.User.Application.CQRS.Roles.Commands; using Do_Svyazi.User.Application.CQRS.Roles.Queries; using Do_Svyazi.User.Dtos.Roles; +using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -10,6 +11,7 @@ namespace Do_Svyazi.User.Web.Controllers; [Authorize] [ApiController] +[ExceptionFilter] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs new file mode 100644 index 0000000..2e76ed5 --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs @@ -0,0 +1,32 @@ +using Do_Svyazi.User.Domain.Exceptions; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Do_Svyazi.User.Web.Controllers.Tools; + +public class ExceptionFilterAttribute : Attribute, IExceptionFilter +{ + public async void OnException(ExceptionContext context) + { + Exception exception = context.Exception; + + if (exception.GetType() == typeof(Do_Svyazi_User_BusinessLogicException)) + { + context.HttpContext.Response.StatusCode = 400; + } + else if (exception.GetType() == typeof(Do_Svyazi_User_NotFoundException)) + { + context.HttpContext.Response.StatusCode = 404; + } + else + { + context.HttpContext.Response.StatusCode = 500; + } + + await context.HttpContext.Response.WriteAsJsonAsync( + $"An exception occurred in the {context.ActionDescriptor.DisplayName} method:" + + $"\n {exception.StackTrace} \n {exception.Message}"); + + context.ExceptionHandled = true; + } +} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index d4086e2..613c783 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -3,6 +3,7 @@ using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Users; +using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -12,6 +13,7 @@ namespace Do_Svyazi.User.Web.Controllers; [Authorize] [ApiController] +[ExceptionFilter] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] From 921067778b604622d8c824497085067c043fa9c3 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 02:58:39 +0300 Subject: [PATCH 17/45] feat: 401 error-code handling supported --- .../Helpers/AuthorizeAttribute.cs | 4 +--- .../Middlewares/AuthorizationMiddleware.cs | 4 +--- .../Tools/ExceptionFilterAttribute.cs | 4 ++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs index ca1348a..f1a880a 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs @@ -1,6 +1,4 @@ using Do_Svyazi.User.Domain.Authenticate; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; namespace Do_Svyazi.User.Web.Controllers.Helpers; @@ -14,7 +12,7 @@ public void OnAuthorization(AuthorizationFilterContext context) if (user == null) { - context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized }; + throw new UnauthorizedAccessException(); } } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs index d9b0a9d..60af8c5 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs @@ -52,14 +52,12 @@ private async Task AttachUserToContext(HttpContext context, string token) var jwtToken = validatedToken as JwtSecurityToken; string? userId = jwtToken?.Claims.First(x => x.Type == "jti").Value; - // attach user to context on successful jwt validation var user = await _userManager.FindByIdAsync(userId); context.Items["User"] = user; } catch { - context.Response.StatusCode = 401; - await context.Response.WriteAsync("Wrong auth credentials"); + throw new UnauthorizedAccessException(); } } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs index 2e76ed5..3200db6 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs @@ -14,6 +14,10 @@ public async void OnException(ExceptionContext context) { context.HttpContext.Response.StatusCode = 400; } + else if (exception.GetType() == typeof(UnauthorizedAccessException)) + { + context.HttpContext.Response.StatusCode = 401; + } else if (exception.GetType() == typeof(Do_Svyazi_User_NotFoundException)) { context.HttpContext.Response.StatusCode = 404; From 19e6abed712ed4f64099407c1ba6ce25cada149a Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 03:27:33 +0300 Subject: [PATCH 18/45] fix: error-handling middleware replaced error-handling filter --- .../Do-Svyazi.User.Web.Api/Startup.cs | 1 + .../AuthenticateController.cs | 9 ++-- .../ChatController.cs | 2 - .../Helpers/AuthorizeAttribute.cs | 7 +++ .../Middlewares/AuthorizationMiddleware.cs | 3 +- .../Middlewares/ErrorHandlingMiddleware.cs | 54 +++++++++++++++++++ .../RolesController.cs | 4 +- .../Tools/ExceptionFilterAttribute.cs | 36 ------------- .../UserController.cs | 6 +-- 9 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs delete mode 100644 Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs index 9e019d0..7c06ef1 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Startup.cs @@ -51,6 +51,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseAuthentication(); app.UseAuthorization(); + app.UseMiddleware(); app.UseMiddleware(); app.UseEndpoints(endpoints => endpoints.MapControllers()); diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index 4247d79..4df165f 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -2,17 +2,16 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using Do_Svyazi.User.Domain.Authenticate; -using Do_Svyazi.User.Web.Controllers.Tools; +using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Do_Svyazi.User.Web.Controllers; +[Authorize] [ApiController] [Route("api/[controller]")] -[ExceptionFilter] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] @@ -22,7 +21,6 @@ public class AuthenticateController : ControllerBase public AuthenticateController(IMediator mediator) => _mediator = mediator; - [Authorize] [HttpGet(nameof(GetAll))] public async Task>> GetAll(CancellationToken cancellationToken) { @@ -30,6 +28,7 @@ public async Task>> GetAll return Ok(response); } + [Authorize(false)] [HttpPost(nameof(Login))] public async Task Login([FromBody] LoginRequest model, CancellationToken cancellationToken) { @@ -57,7 +56,7 @@ public async Task> AuthenticateByJwt( return Ok(result); } - [Authorize] + [Authorize(false)] [HttpPost(nameof(RegisterAdmin))] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task RegisterAdmin([FromBody] RegisterAdminCommand model, CancellationToken cancellationToken) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index 82c44d1..67f160b 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -3,7 +3,6 @@ using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Web.Controllers.Helpers; -using Do_Svyazi.User.Web.Controllers.Tools; using MediatR; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -12,7 +11,6 @@ namespace Do_Svyazi.User.Web.Controllers; [Authorize] [ApiController] -[ExceptionFilter] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs index f1a880a..d17f871 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs @@ -6,8 +6,15 @@ namespace Do_Svyazi.User.Web.Controllers.Helpers; [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class AuthorizeAttribute : Attribute, IAuthorizationFilter { + public AuthorizeAttribute() { } + public AuthorizeAttribute(bool isEnabled) => IsEnabled = isEnabled; + + private bool IsEnabled { get; init; } + public void OnAuthorization(AuthorizationFilterContext context) { + if (!IsEnabled) return; + var user = context.HttpContext.Items["User"] as MessageIdentityUser; if (user == null) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs index 60af8c5..6677f8e 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs @@ -57,7 +57,8 @@ private async Task AttachUserToContext(HttpContext context, string token) } catch { - throw new UnauthorizedAccessException(); + context.Response.StatusCode = 401; + await context.Response.WriteAsync("Wrong auth credentials"); } } } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs new file mode 100644 index 0000000..072b4f5 --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/ErrorHandlingMiddleware.cs @@ -0,0 +1,54 @@ +using Do_Svyazi.User.Domain.Exceptions; +using Microsoft.AspNetCore.Http; + +namespace Do_Svyazi.User.Web.Controllers.Middlewares; + +public class ErrorHandlingMiddleware +{ + private readonly RequestDelegate _next; + + public ErrorHandlingMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task Invoke(HttpContext context) + { + try + { + await _next(context); + } + catch (Do_Svyazi_User_BusinessLogicException e) + { + context.Response.StatusCode = 400; + await AttachErrorMessage(context, e); + } + catch (UnauthorizedAccessException e) + { + context.Response.StatusCode = 401; + await AttachErrorMessage(context, e); + } + catch (Do_Svyazi_User_NotFoundException e) + { + context.Response.StatusCode = 404; + await AttachErrorMessage(context, e); + } + catch (Exception e) + { + context.Response.StatusCode = 500; + await AttachErrorMessage(context, e); + } + } + + private async Task AttachErrorMessage(HttpContext context, Exception exception) + { + var message = new + { + message = exception.Message, + endpoint = $"{context.GetEndpoint()}", + stackTrace = exception.StackTrace, + }; + + await context.Response.WriteAsJsonAsync(message); + } +} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs index 1a5f18b..018dbb7 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs @@ -1,9 +1,8 @@ using Do_Svyazi.User.Application.CQRS.Roles.Commands; using Do_Svyazi.User.Application.CQRS.Roles.Queries; using Do_Svyazi.User.Dtos.Roles; -using Do_Svyazi.User.Web.Controllers.Tools; +using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,7 +10,6 @@ namespace Do_Svyazi.User.Web.Controllers; [Authorize] [ApiController] -[ExceptionFilter] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs deleted file mode 100644 index 3200db6..0000000 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Tools/ExceptionFilterAttribute.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Do_Svyazi.User.Domain.Exceptions; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Do_Svyazi.User.Web.Controllers.Tools; - -public class ExceptionFilterAttribute : Attribute, IExceptionFilter -{ - public async void OnException(ExceptionContext context) - { - Exception exception = context.Exception; - - if (exception.GetType() == typeof(Do_Svyazi_User_BusinessLogicException)) - { - context.HttpContext.Response.StatusCode = 400; - } - else if (exception.GetType() == typeof(UnauthorizedAccessException)) - { - context.HttpContext.Response.StatusCode = 401; - } - else if (exception.GetType() == typeof(Do_Svyazi_User_NotFoundException)) - { - context.HttpContext.Response.StatusCode = 404; - } - else - { - context.HttpContext.Response.StatusCode = 500; - } - - await context.HttpContext.Response.WriteAsJsonAsync( - $"An exception occurred in the {context.ActionDescriptor.DisplayName} method:" + - $"\n {exception.StackTrace} \n {exception.Message}"); - - context.ExceptionHandled = true; - } -} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index 613c783..8702430 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -3,9 +3,8 @@ using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Users; -using Do_Svyazi.User.Web.Controllers.Tools; +using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -13,7 +12,6 @@ namespace Do_Svyazi.User.Web.Controllers; [Authorize] [ApiController] -[ExceptionFilter] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] @@ -72,7 +70,7 @@ public async Task DeleteUser(DeleteUserCommand deleteUserCommand, return NoContent(); } - [AllowAnonymous] + [Authorize(false)] [HttpPost(nameof(AddUser))] [ProducesResponseType(StatusCodes.Status201Created)] public async Task> AddUser(AddUserCommand addUserCommand, CancellationToken cancellationToken) From 652191e5df4a64c986c2b9db7e362e45a2ac9844 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 23:50:40 +0300 Subject: [PATCH 19/45] refactor!: MessageIdentityUser merged with MessengerUser --- .../Authenticate/Commands/RegisterCommand.cs | 2 +- .../Handlers/AuthenticateCommandHandler.cs | 56 +++++++------------ .../Handlers/AuthenticateQueryHandler.cs | 14 +++-- .../Authenticate/Queries/GetUsersRequest.cs | 4 +- .../Chats/Handlers/ChatsCommandHandler.cs | 28 ++++++---- .../ChangeUserDescriptionByIdCommand.cs | 2 +- .../Commands/ChangeUserNameByIdCommand.cs | 2 +- .../Users/Commands/ChangeUserNickNameById.cs | 2 +- .../CQRS/Users/Commands/DeleteUserCommand.cs | 2 +- .../Users/Handlers/UsersCommandHandler.cs | 46 +++++---------- .../CQRS/Users/Handlers/UsersQueryHandler.cs | 9 ++- .../DbContexts/IDbContext.cs | 1 - .../Do-Svyazi.User.Application.csproj | 1 + .../Authenticate/MessageIdentityRole.cs | 14 ++++- .../Authenticate/MessageIdentityUser.cs | 10 ++-- .../Authenticate/RegisterModel.cs | 6 +- .../Do-Svyazi.User.Domain/Chats/Channel.cs | 4 +- .../Do-Svyazi.User.Domain/Chats/Chat.cs | 4 +- .../Do-Svyazi.User.Domain/Chats/GroupChat.cs | 2 +- .../Do-Svyazi.User.Domain/Users/ChatUser.cs | 6 +- .../Users/MessengerUser.cs | 14 +++-- .../ApplicationDbContext.cs | 19 +++---- .../DoSvaziDbContext.cs | 1 - .../Do-Svyazi.User.Web.Api.csproj | 4 ++ .../Extensions/ClaimsPrincipalExtensions.cs | 34 ----------- .../Extensions/ServiceCollectionExtensions.cs | 3 +- .../AuthenticateController.cs | 13 ++--- .../ChatController.cs | 5 +- .../Helpers/AuthorizeAttribute.cs | 46 +++++++-------- .../Middlewares/AuthorizationMiddleware.cs | 5 +- .../RolesController.cs | 2 +- .../UserController.cs | 6 +- 32 files changed, 162 insertions(+), 205 deletions(-) delete mode 100644 Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs index 2efb426..3e14125 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Commands/RegisterCommand.cs @@ -4,4 +4,4 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Commands; public record RegisterCommand(RegisterModel model) - : IRequest; \ No newline at end of file + : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs index 8aa0ce9..664b648 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs @@ -3,6 +3,7 @@ using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Exceptions; +using Do_Svyazi.User.Domain.Users; using MediatR; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; @@ -10,77 +11,62 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; public class AuthenticateCommandHandler : - ICommandHandler, + ICommandHandler, ICommandHandler { - private readonly UserManager _userManager; + private readonly UserManager _userManager; private readonly RoleManager _roleManager; - private readonly IDbContext _context; public AuthenticateCommandHandler( - UserManager userManager, - RoleManager roleManager, - IDbContext context) + UserManager userManager, + RoleManager roleManager) { _userManager = userManager; _roleManager = roleManager; - _context = context; } - public async Task Handle(RegisterCommand request, CancellationToken cancellationToken) + public async Task Handle(RegisterCommand request, CancellationToken cancellationToken) { RegisterModel registerModel = request.model; - if (await _userManager.FindByNameAsync(registerModel.NickName) is not null) + if (await _userManager.FindByNameAsync(registerModel.UserName) is not null) throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - Guid userId = await GetMessengerUserIdByNickName(registerModel.NickName, cancellationToken); - - MessageIdentityUser user = CreateIdentityUser(registerModel, userId); + MessengerUser user = CreateIdentityUser(registerModel); if (!(await _userManager.CreateAsync(user, registerModel.Password)).Succeeded) throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); - return Unit.Value; + return user.Id; } public async Task Handle(RegisterAdminCommand request, CancellationToken cancellationToken) { RegisterModel registerModel = request.model; - if (await _userManager.FindByNameAsync(registerModel.NickName) is not null) - throw new Do_Svyazi_User_BusinessLogicException("User already exists"); - - Guid userId = await GetMessengerUserIdByNickName(registerModel.NickName, cancellationToken); + if (await _userManager.FindByNameAsync(registerModel.UserName) is not null) + throw new Do_Svyazi_User_BusinessLogicException($"User with nickName {registerModel.UserName} exists"); - MessageIdentityUser user = CreateIdentityUser(registerModel, userId); + MessengerUser user = CreateIdentityUser(registerModel); if (!(await _userManager.CreateAsync(user, registerModel.Password)).Succeeded) throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); + if (!await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) + await _roleManager.CreateAsync(new MessageIdentityRole(MessageIdentityRole.Admin)); + + if (!await _roleManager.RoleExistsAsync(MessageIdentityRole.User)) + await _roleManager.CreateAsync(new MessageIdentityRole(MessageIdentityRole.User)); + if (await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) - { await _userManager.AddToRoleAsync(user, MessageIdentityRole.Admin); - await _roleManager.CreateAsync(new MessageIdentityRole(MessageIdentityRole.User)); - } - if (await _roleManager.RoleExistsAsync(MessageIdentityRole.User)) - { + if (await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) await _userManager.AddToRoleAsync(user, MessageIdentityRole.User); - await _roleManager.CreateAsync(new MessageIdentityRole(MessageIdentityRole.Admin)); - } return Unit.Value; } - private async Task GetMessengerUserIdByNickName(string nickName, CancellationToken cancellationToken) => - (await _context.Users.SingleAsync(user => user.NickName == nickName, cancellationToken: cancellationToken)).Id; - - private MessageIdentityUser CreateIdentityUser(RegisterModel userModel, Guid userId) => new () - { - Id = userId, - UserName = userModel.NickName, - Email = userModel.Email, - PhoneNumber = userModel.PhoneNumber, - }; + private MessengerUser CreateIdentityUser(RegisterModel userModel) => + new (userModel.Name, userModel.UserName, userModel.Email, userModel.PhoneNumber); } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs index f5d2cc7..5bf06f8 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs @@ -5,6 +5,7 @@ using Do_Svyazi.User.Application.CQRS.Handlers; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Exceptions; +using Do_Svyazi.User.Domain.Users; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -15,14 +16,14 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; public class AuthenticateQueryHandler : IQueryHandler, IQueryHandler, - IQueryHandler> + IQueryHandler> { private const string NameType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; - private readonly UserManager _userManager; + private readonly UserManager _userManager; private readonly IConfiguration _configuration; - public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration) + public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration) { _userManager = userManager; _configuration = configuration; @@ -32,7 +33,7 @@ public async Task Handle(LoginRequest request, CancellationTok { var token = new JwtSecurityToken(); LoginModel loginModel = request.model; - MessageIdentityUser user = await GetUserByUsernameOrEmail(loginModel); + MessengerUser user = await GetUserByUsernameOrEmail(loginModel); if (!await _userManager.CheckPasswordAsync(user, loginModel.Password)) return token; @@ -42,6 +43,7 @@ public async Task Handle(LoginRequest request, CancellationTok { new Claim(ClaimTypes.Name, user.UserName), new Claim(JwtRegisteredClaimNames.Jti, $"{user.Id}"), + new Claim(JwtRegisteredClaimNames.Email, $"{user.Email}"), }; authClaims @@ -60,7 +62,7 @@ public async Task Handle(AuthenticateByJwtRequest request, CancellationTok return identityUser.Id; } - public async Task> Handle(GetUsersRequest request, CancellationToken cancellationToken) + public async Task> Handle(GetUsersRequest request, CancellationToken cancellationToken) => await _userManager.Users.ToListAsync(cancellationToken: cancellationToken); private JwtSecurityToken GetToken(List authClaims) @@ -77,7 +79,7 @@ private JwtSecurityToken GetToken(List authClaims) return token; } - private async Task GetUserByUsernameOrEmail(LoginModel loginModel) + private async Task GetUserByUsernameOrEmail(LoginModel loginModel) { if (loginModel.NickName is not null) return await _userManager.FindByNameAsync(loginModel.NickName); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs index 4a33a75..aa6ec14 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs @@ -1,7 +1,7 @@ -using Do_Svyazi.User.Domain.Authenticate; +using Do_Svyazi.User.Domain.Users; using MediatR; namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; public record GetUsersRequest - : IRequest>; \ No newline at end of file + : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index 479a235..2d231e1 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -5,6 +5,7 @@ using Do_Svyazi.User.Domain.Exceptions; using Do_Svyazi.User.Domain.Users; using MediatR; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; namespace Do_Svyazi.User.Application.CQRS.Chats.Handlers; @@ -18,12 +19,17 @@ public class ChatsCommandHandler : ICommandHandler { private readonly IDbContext _context; + private readonly UserManager _userManager; - public ChatsCommandHandler(IDbContext context) => _context = context; + public ChatsCommandHandler(UserManager userManager, IDbContext context) + { + _userManager = userManager; + _context = context; + } public async Task Handle(AddChannelCommand request, CancellationToken cancellationToken) { - MessengerUser user = await _context.Users + MessengerUser user = await _userManager.Users .SingleOrDefaultAsync(user => user.Id == request.adminId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.adminId} to create a channel was not found"); @@ -40,9 +46,8 @@ public async Task Handle(AddChannelCommand request, CancellationToken canc public async Task Handle(AddGroupChatCommand request, CancellationToken cancellationToken) { - MessengerUser user = await _context.Users - .SingleOrDefaultAsync(user => user.Id == request.adminId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( + MessengerUser user = await _userManager.FindByIdAsync($"{request.adminId}") + ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.adminId} to create a group chat was not found"); GroupChat chat = new GroupChat(user, request.name, request.description); @@ -58,19 +63,18 @@ public async Task Handle(AddGroupChatCommand request, CancellationToken ca public async Task Handle(AddPersonalChatCommand request, CancellationToken cancellationToken) { MessengerUser firstUser = - await _context.Users.SingleOrDefaultAsync(user => user.Id == request.firstUserId, cancellationToken) ?? + await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.firstUserId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.firstUserId} to create a personal chat was not found"); MessengerUser secondUser = - await _context.Users.SingleOrDefaultAsync(user => user.Id == request.secondUserId, cancellationToken) ?? + await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.secondUserId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.secondUserId} to create a personal chat was not found"); Chat chat = new PersonalChat(firstUser, secondUser, request.name, request.description); - _context.Users.Update(firstUser); - _context.Users.Update(secondUser); + _context.ChatUsers.AddRange(chat.Users); await _context.Chats.AddAsync(chat, cancellationToken); await _context.SaveChangesAsync(cancellationToken); @@ -80,7 +84,7 @@ await _context.Users.SingleOrDefaultAsync(user => user.Id == request.secondUserI public async Task Handle(AddSavedMessagesCommand request, CancellationToken cancellationToken) { MessengerUser user = - await _context.Users.SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? + await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.userId} to create saved messages chat not found"); @@ -105,7 +109,7 @@ public async Task Handle(AddUserToChatCommand request, CancellationToken c throw new Do_Svyazi_User_NotFoundException( $"Chat with id = {request.chatId} to add user {request.userId} was not found"); - MessengerUser messengerUser = await _context.Users + MessengerUser messengerUser = await _userManager.Users .SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.userId} to be added into chat with id = {request.chatId} not found"); @@ -128,7 +132,7 @@ public async Task Handle(DeleteUserFromChatCommand request, CancellationTo .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException($"Chat with id {request.chatId} not found"); - MessengerUser messengerUser = await _context.Users + MessengerUser messengerUser = await _userManager.Users .SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id {request.userId} not found"); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs index daa01e2..2f6df9f 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record ChangeUserDescriptionByIdCommand(Guid userId, string description) +public record ChangeUserDescriptionByIdCommand(string userId, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs index e82f5e3..50a531f 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record ChangeUserNameByIdCommand(Guid userId, string name) +public record ChangeUserNameByIdCommand(string userId, string name) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs index 8e78b60..bd64b3a 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record SetUserNickNameByIdCommand(Guid userId, string nickName) +public record SetUserNickNameByIdCommand(string userId, string nickName) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs index a4121a8..b2f71e1 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record DeleteUserCommand(Guid userId) +public record DeleteUserCommand(string userId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs index 905a600..fa0ed8e 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs @@ -4,65 +4,49 @@ using Do_Svyazi.User.Domain.Exceptions; using Do_Svyazi.User.Domain.Users; using MediatR; +using Microsoft.AspNetCore.Identity; namespace Do_Svyazi.User.Application.CQRS.Users.Handlers; public class UsersCommandHandler : - IQueryHandler, IQueryHandler, IQueryHandler, IQueryHandler, IQueryHandler { - private readonly IDbContext _context; - public UsersCommandHandler(IDbContext context) => _context = context; - - public async Task Handle(AddUserCommand request, CancellationToken cancellationToken) - { - if (NickNameExists(request.nickName)) - { - throw new Do_Svyazi_User_BusinessLogicException( - $"User with nickname = {request.nickName} already exists in messenger"); - } - - MessengerUser messengerUser = new (request.name, request.nickName, request.description); - - await _context.Users.AddAsync(messengerUser, cancellationToken); - await _context.SaveChangesAsync(cancellationToken); - - return messengerUser.Id; - } + private readonly UserManager _userManager; + public UsersCommandHandler(UserManager userManager) => _userManager = userManager; public async Task Handle(ChangeUserDescriptionByIdCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? + MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id {request.userId} to change description was not found"); messengerUser.ChangeDescription(request.description); - _context.Users.Update(messengerUser); - await _context.SaveChangesAsync(cancellationToken); + await _userManager.UpdateAsync(messengerUser); return Unit.Value; } public async Task Handle(ChangeUserNameByIdCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? + var users = _userManager.Users.ToList(); + + MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException($"User with id {request.userId} to change name was not found"); messengerUser.ChangeName(request.name); - _context.Users.Update(messengerUser); - await _context.SaveChangesAsync(cancellationToken); + await _userManager.UpdateAsync(messengerUser); return Unit.Value; } public async Task Handle(SetUserNickNameByIdCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? + MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException( $"User with id {request.userId} to change nickName was not found"); @@ -71,22 +55,20 @@ public async Task Handle(SetUserNickNameByIdCommand request, CancellationT messengerUser.ChangeNickName(request.nickName); - _context.Users.Update(messengerUser); - await _context.SaveChangesAsync(cancellationToken); + await _userManager.UpdateAsync(messengerUser); return Unit.Value; } public async Task Handle(DeleteUserCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _context.Users.FindAsync(request.userId) ?? + MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? throw new Do_Svyazi_User_NotFoundException($"Can't find user with id = {request.userId} to delete"); - _context.Users.Remove(messengerUser); - await _context.SaveChangesAsync(cancellationToken); + await _userManager.DeleteAsync(messengerUser); return Unit.Value; } - private bool NickNameExists(string nickName) => _context.Users.Any(user => user.NickName == nickName); + private bool NickNameExists(string nickName) => _userManager.FindByNameAsync(nickName) is not null; } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs index a85ba12..1692e17 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs @@ -7,6 +7,7 @@ using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Users; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; namespace Do_Svyazi.User.Application.CQRS.Users.Handlers; @@ -17,11 +18,13 @@ public class UsersQueryHandler : IQueryHandler, IQueryHandler> { + private readonly UserManager _userManager; private readonly IDbContext _context; private readonly IMapper _mapper; - public UsersQueryHandler(IDbContext context, IMapper mapper) + public UsersQueryHandler(UserManager userManager, IDbContext context, IMapper mapper) { + _userManager = userManager; _context = context; _mapper = mapper; } @@ -41,12 +44,12 @@ public async Task> Handle(GetAllChatsIdsByUserIdQuery reques .ToListAsync(cancellationToken); public async Task Handle(GetUserQuery request, CancellationToken cancellationToken) - => await _context.Users + => await _userManager.Users .SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken: cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException($"User with id = {request.userId} doesn't exist"); public async Task> Handle(GetUsersQuery request, CancellationToken cancellationToken) - => await _context.Users + => await _userManager.Users .ProjectTo(_mapper.ConfigurationProvider) .ToListAsync(cancellationToken: cancellationToken); } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/DbContexts/IDbContext.cs b/Source/Application/Do-Svyazi.User.Application/DbContexts/IDbContext.cs index 7d4ca41..5d80fc9 100644 --- a/Source/Application/Do-Svyazi.User.Application/DbContexts/IDbContext.cs +++ b/Source/Application/Do-Svyazi.User.Application/DbContexts/IDbContext.cs @@ -8,7 +8,6 @@ namespace Do_Svyazi.User.Application.DbContexts; public interface IDbContext { public DbSet Chats { get; init; } - public DbSet Users { get; init; } public DbSet ChatUsers { get; init; } public DbSet Roles { get; init; } Task SaveChangesAsync(CancellationToken cancellationToken); diff --git a/Source/Application/Do-Svyazi.User.Application/Do-Svyazi.User.Application.csproj b/Source/Application/Do-Svyazi.User.Application/Do-Svyazi.User.Application.csproj index cf78f83..7cf4e60 100644 --- a/Source/Application/Do-Svyazi.User.Application/Do-Svyazi.User.Application.csproj +++ b/Source/Application/Do-Svyazi.User.Application/Do-Svyazi.User.Application.csproj @@ -6,6 +6,7 @@ enable True enable + true diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityRole.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityRole.cs index dec0468..4103c51 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityRole.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityRole.cs @@ -4,13 +4,23 @@ namespace Do_Svyazi.User.Domain.Authenticate; public class MessageIdentityRole : IdentityRole { - public const string Admin = "Admin"; - public const string User = "User"; + public const string Admin = nameof(Admin); + public const string ChatCreator = nameof(ChatCreator); + public const string ChatAdmin = nameof(ChatAdmin); + public const string User = nameof(User); public MessageIdentityRole(string roleName) : base(roleName) { } + public MessageIdentityRole(string roleName, Guid chatId) + : base(roleName) + { + ChatId = chatId; + } + protected MessageIdentityRole() { } + + public Guid ChatId { get; set; } } \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityUser.cs index dcdd7d9..0239f07 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/MessageIdentityUser.cs @@ -1,5 +1,5 @@ -using Microsoft.AspNetCore.Identity; - -namespace Do_Svyazi.User.Domain.Authenticate; - -public class MessageIdentityUser : IdentityUser { } \ No newline at end of file +// using Microsoft.AspNetCore.Identity; +// +// namespace Do_Svyazi.User.Domain.Authenticate; +// +// public class MessageIdentityUser : IdentityUser { } \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs index e276170..001a963 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/RegisterModel.cs @@ -4,8 +4,10 @@ namespace Do_Svyazi.User.Domain.Authenticate; public record RegisterModel { - [Required(ErrorMessage = "NickName is required")] - public string NickName { get; init; } + [Required(ErrorMessage = "UserName is required")] + public string UserName { get; init; } + + public string Name { get; init; } [Required(ErrorMessage = "Email is required")] public string Email { get; init; } diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs index 30db63f..c9465aa 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs @@ -143,9 +143,9 @@ public override void ChangeUserRole(MessengerUser user, Role role) throw new ArgumentNullException(nameof(user), $"User to change role in chat {Name} is null"); if (role is null) - throw new ArgumentNullException(nameof(role), $"Role to change in user {user.NickName} in chat {Name} is null"); + throw new ArgumentNullException(nameof(role), $"Role to change in user {user.UserName} in chat {Name} is null"); - ChatUser chatUser = GetUser(user.NickName); + ChatUser chatUser = GetUser(user.UserName); chatUser.ChangeRole(role); } diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs index 09a5786..8ec3d55 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs @@ -49,8 +49,8 @@ public virtual void ChangeDescription(string description) public IReadOnlyCollection GetUsersByRole(Role role) => Users.Where(user => user.Role.Equals(role)).ToList(); - public ChatUser GetUser(string nickName) => - Users.SingleOrDefault(user => user.User.NickName == nickName) + public ChatUser GetUser(string userName) => + Users.SingleOrDefault(user => user.User.UserName == userName) ?? throw new Do_Svyazi_User_NotFoundException($"User is not found in chat {Name}"); public ChatUser GetUser(Guid id) => diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs index 73245c1..ac8b726 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs @@ -150,7 +150,7 @@ public override void ChangeUserRole(MessengerUser user, Role role) if (role is null) throw new ArgumentNullException(nameof(role), $"Role to set to user {user.Name} in chat {Name} is null"); - ChatUser chatUser = GetUser(user.NickName); + ChatUser chatUser = GetUser(user.UserName); chatUser.ChangeRole(role); } diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs index 2385945..777cdcf 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs @@ -8,8 +8,8 @@ public class ChatUser public ChatUser(MessengerUser user, Chat chat, Role role) { User = user ?? throw new ArgumentNullException(nameof(user), $"User to create chatUser in chat {chat.Name} is null"); - Chat = chat ?? throw new ArgumentNullException(nameof(chat), $"Chat to create chatUser to {user.NickName} is null"); - Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to create chatUser to {user.NickName} is null"); + Chat = chat ?? throw new ArgumentNullException(nameof(chat), $"Chat to create chatUser with name {user.UserName} is null"); + Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to create chatUser with userName {user.UserName} and {role} is null"); ChatId = chat.Id; MessengerUserId = user.Id; } @@ -24,7 +24,7 @@ public ChatUser() { } public Role Role { get; private set; } public void ChangeRole(Role role) => - Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to set to {User.NickName} in chat {Chat.Name} is null"); + Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to set to {User.UserName} in chat {Chat.Name} is null"); public override bool Equals(object? obj) => Equals(obj as ChatUser); diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs index 428b79e..1071865 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs @@ -1,28 +1,30 @@ using Do_Svyazi.User.Domain.Chats; +using Microsoft.AspNetCore.Identity; namespace Do_Svyazi.User.Domain.Users; -public class MessengerUser +public class MessengerUser : IdentityUser { private const string DefaultDescription = "No description"; - public MessengerUser(string name, string nickName, string? description = null) + public MessengerUser(string name, string nickName, string? email, string? phoneNumber, string? description = null) + : base(nickName) { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name), "User name can't be null"); if (string.IsNullOrWhiteSpace(nickName)) throw new ArgumentNullException(nameof(nickName), "User nickName can't be null"); + Email = email; + PhoneNumber = phoneNumber; Name = name; - NickName = nickName; Description = string.IsNullOrEmpty(description) ? DefaultDescription : description; + Id = Guid.NewGuid(); } public MessengerUser() { } - public Guid Id { get; protected init; } = Guid.NewGuid(); public string Name { get; private set; } - public string NickName { get; private set; } public string Description { get; private set; } public virtual void ChangeNickName(string nickName) @@ -30,7 +32,7 @@ public virtual void ChangeNickName(string nickName) if (string.IsNullOrWhiteSpace(nickName)) throw new ArgumentNullException(nameof(nickName), "User nickName to change is null"); - NickName = nickName; + UserName = nickName; } public virtual void ChangeName(string name) diff --git a/Source/Infrastructure/Do-Svyazi.User.DataAccess/ApplicationDbContext.cs b/Source/Infrastructure/Do-Svyazi.User.DataAccess/ApplicationDbContext.cs index c50328d..8442997 100644 --- a/Source/Infrastructure/Do-Svyazi.User.DataAccess/ApplicationDbContext.cs +++ b/Source/Infrastructure/Do-Svyazi.User.DataAccess/ApplicationDbContext.cs @@ -1,20 +1,15 @@ using Do_Svyazi.User.Domain.Authenticate; +using Do_Svyazi.User.Domain.Users; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; -namespace Do_Svyazi.User.DataAccess +namespace Do_Svyazi.User.DataAccess; + +public class ApplicationDbContext : IdentityDbContext { - public class ApplicationDbContext : IdentityDbContext + public ApplicationDbContext(DbContextOptions options) + : base(options) { - public ApplicationDbContext(DbContextOptions options) - : base(options) - { - Database.EnsureCreated(); - } - - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); - } + Database.EnsureCreated(); } } \ No newline at end of file diff --git a/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs b/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs index aa6ebd6..04a4bd6 100644 --- a/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs +++ b/Source/Infrastructure/Do-Svyazi.User.DataAccess/DoSvaziDbContext.cs @@ -17,7 +17,6 @@ public DoSvaziDbContext(DbContextOptions options) protected DoSvaziDbContext() { } public virtual DbSet Chats { get; init; } - public virtual DbSet Users { get; init; } public virtual DbSet ChatUsers { get; init; } public virtual DbSet Roles { get; init; } diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Do-Svyazi.User.Web.Api.csproj b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Do-Svyazi.User.Web.Api.csproj index 4d2f79f..aa25df4 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Do-Svyazi.User.Web.Api.csproj +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Do-Svyazi.User.Web.Api.csproj @@ -49,4 +49,8 @@ + + + + diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs deleted file mode 100644 index 98011d1..0000000 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ClaimsPrincipalExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Security.Claims; - -namespace Do_Svyazi.User.Web.Api.Extensions; - -public static class ClaimsPrincipalExtensions -{ - public static T GetLoggedInUserId(this ClaimsPrincipal principal) - { - if (principal == null) - throw new ArgumentNullException(nameof(principal)); - - var loggedInUserId = principal.FindFirstValue(ClaimTypes.NameIdentifier); - - if (typeof(T) == typeof(string)) - { - return (T)Convert.ChangeType(loggedInUserId, typeof(T)); - } - - if (typeof(T) == typeof(int) || typeof(T) == typeof(long)) - { - return loggedInUserId != null - ? (T)Convert.ChangeType(loggedInUserId, typeof(T)) - : (T)Convert.ChangeType(0, typeof(T)); - } - - throw new Exception("Invalid type provided"); - } - - public static string GetLoggedInUserName(this ClaimsPrincipal principal) => - principal.FindFirstValue(ClaimTypes.Name) ?? throw new ArgumentNullException(nameof(principal)); - - public static string GetLoggedInUserEmail(this ClaimsPrincipal principal) => - principal.FindFirstValue(ClaimTypes.Email) ?? throw new ArgumentNullException(nameof(principal)); -} \ No newline at end of file diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs index 99b955c..9ac1d0b 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.DataAccess; using Do_Svyazi.User.Domain.Authenticate; +using Do_Svyazi.User.Domain.Users; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; @@ -16,7 +17,7 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddAuthServices(this IServiceCollection services, IConfiguration configuration) { - services.AddIdentity(options => + services.AddIdentity(options => { options.Password = new PasswordOptions { diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index 4df165f..118c39a 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -2,14 +2,14 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using Do_Svyazi.User.Domain.Authenticate; -using Do_Svyazi.User.Web.Controllers.Helpers; +using Do_Svyazi.User.Domain.Users; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Do_Svyazi.User.Web.Controllers; -[Authorize] [ApiController] [Route("api/[controller]")] [ProducesResponseType(StatusCodes.Status200OK)] @@ -22,13 +22,13 @@ public class AuthenticateController : ControllerBase public AuthenticateController(IMediator mediator) => _mediator = mediator; [HttpGet(nameof(GetAll))] - public async Task>> GetAll(CancellationToken cancellationToken) + [Authorize(Roles = MessageIdentityRole.Admin)] + public async Task>> GetAll(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetUsersRequest(), cancellationToken); return Ok(response); } - [Authorize(false)] [HttpPost(nameof(Login))] public async Task Login([FromBody] LoginRequest model, CancellationToken cancellationToken) { @@ -44,8 +44,8 @@ public async Task Login([FromBody] LoginRequest model, Cancellatio [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task Register([FromBody] RegisterCommand model, CancellationToken cancellationToken) { - await _mediator.Send(model, cancellationToken); - return NoContent(); + var result = await _mediator.Send(model, cancellationToken); + return Ok(result); } [HttpGet(nameof(AuthenticateByJwt))] @@ -56,7 +56,6 @@ public async Task> AuthenticateByJwt( return Ok(result); } - [Authorize(false)] [HttpPost(nameof(RegisterAdmin))] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task RegisterAdmin([FromBody] RegisterAdminCommand model, CancellationToken cancellationToken) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index 67f160b..fb47f02 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -1,9 +1,10 @@ using Do_Svyazi.User.Application.CQRS.Chats.Commands; using Do_Svyazi.User.Application.CQRS.Chats.Queries; +using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; -using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -22,6 +23,7 @@ public class ChatController : ControllerBase public ChatController(IMediator mediator) => _mediator = mediator; [HttpGet(nameof(GetChats))] + [Authorize(Roles = MessageIdentityRole.Admin)] public async Task>> GetChats(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetChatsQuery(), cancellationToken); @@ -98,6 +100,7 @@ public async Task AddUserToChat( } [HttpDelete(nameof(DeleteUserFromChat))] + [Authorize(Roles = $"{MessageIdentityRole.ChatAdmin}, {MessageIdentityRole.ChatCreator}")] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task DeleteUserFromChat( DeleteUserFromChatCommand deleteUserFromChatCommand, CancellationToken cancellationToken) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs index d17f871..3d52f92 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Helpers/AuthorizeAttribute.cs @@ -1,25 +1,21 @@ -using Do_Svyazi.User.Domain.Authenticate; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Do_Svyazi.User.Web.Controllers.Helpers; - -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] -public class AuthorizeAttribute : Attribute, IAuthorizationFilter -{ - public AuthorizeAttribute() { } - public AuthorizeAttribute(bool isEnabled) => IsEnabled = isEnabled; - - private bool IsEnabled { get; init; } - - public void OnAuthorization(AuthorizationFilterContext context) - { - if (!IsEnabled) return; - - var user = context.HttpContext.Items["User"] as MessageIdentityUser; - - if (user == null) - { - throw new UnauthorizedAccessException(); - } - } -} \ No newline at end of file +// using Do_Svyazi.User.Domain.Authenticate; +// using Microsoft.AspNetCore.Mvc.Filters; +// +// namespace Do_Svyazi.User.Web.Controllers.Helpers; +// +// [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] +// public class AuthorizeAttribute : Attribute, IAuthorizationFilter +// { +// public AuthorizeAttribute() { } +// public AuthorizeAttribute(bool isEnabled) => IsEnabled = isEnabled; +// +// private bool IsEnabled { get; init; } +// +// public void OnAuthorization(AuthorizationFilterContext context) +// { +// if (!IsEnabled) return; +// +// if (context.HttpContext.Items["User"] is not MessageIdentityUser) +// throw new UnauthorizedAccessException(); +// } +// } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs index 6677f8e..3a985a3 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs @@ -1,6 +1,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Text; using Do_Svyazi.User.Domain.Authenticate; +using Do_Svyazi.User.Domain.Users; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Configuration; @@ -12,10 +13,10 @@ public class AuthorizationMiddleware { private readonly RequestDelegate _next; private readonly IConfiguration _configuration; - private readonly UserManager _userManager; + private readonly UserManager _userManager; public AuthorizationMiddleware( - RequestDelegate next, IConfiguration configuration, UserManager userManager) + RequestDelegate next, IConfiguration configuration, UserManager userManager) { _next = next; _configuration = configuration; diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs index 018dbb7..7dac829 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/RolesController.cs @@ -1,8 +1,8 @@ using Do_Svyazi.User.Application.CQRS.Roles.Commands; using Do_Svyazi.User.Application.CQRS.Roles.Queries; using Do_Svyazi.User.Dtos.Roles; -using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index 8702430..a69c5b7 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -1,10 +1,11 @@ using Do_Svyazi.User.Application.CQRS.Users.Commands; using Do_Svyazi.User.Application.CQRS.Users.Queries; +using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Users; -using Do_Svyazi.User.Web.Controllers.Helpers; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -23,6 +24,7 @@ public class UserController : ControllerBase public UserController(IMediator mediator) => _mediator = mediator; [HttpGet("GetAll")] + [Authorize(Roles = MessageIdentityRole.Admin)] public async Task>> GetUsers(CancellationToken cancellationToken) { var response = await _mediator.Send(new GetUsersQuery(), cancellationToken); @@ -70,7 +72,7 @@ public async Task DeleteUser(DeleteUserCommand deleteUserCommand, return NoContent(); } - [Authorize(false)] + [AllowAnonymous] [HttpPost(nameof(AddUser))] [ProducesResponseType(StatusCodes.Status201Created)] public async Task> AddUser(AddUserCommand addUserCommand, CancellationToken cancellationToken) From cec00329688131f6532222bab19a5b101273a85b Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 23:50:56 +0300 Subject: [PATCH 20/45] fix: tests updated after refactor --- Source/Tests/CQRS.Tests/CQRS.Tests.csproj | 10 + Source/Tests/CQRS.Tests/ChatTests.cs | 27 ++- Source/Tests/CQRS.Tests/UserTests.cs | 57 ++++-- .../Integration.Tests/IntegrationTests.cs | 171 ++++++++++-------- 4 files changed, 167 insertions(+), 98 deletions(-) diff --git a/Source/Tests/CQRS.Tests/CQRS.Tests.csproj b/Source/Tests/CQRS.Tests/CQRS.Tests.csproj index ec4480b..7bb6dbc 100644 --- a/Source/Tests/CQRS.Tests/CQRS.Tests.csproj +++ b/Source/Tests/CQRS.Tests/CQRS.Tests.csproj @@ -5,6 +5,8 @@ enable false + + true @@ -17,6 +19,8 @@ + + @@ -34,4 +38,10 @@ + + + ..\..\..\..\..\..\.nuget\packages\mockqueryable.moq\6.0.1\lib\net6.0\MockQueryable.Moq.dll + + + diff --git a/Source/Tests/CQRS.Tests/ChatTests.cs b/Source/Tests/CQRS.Tests/ChatTests.cs index dbcc3a5..15c2ede 100644 --- a/Source/Tests/CQRS.Tests/ChatTests.cs +++ b/Source/Tests/CQRS.Tests/ChatTests.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -10,6 +11,9 @@ using Do_Svyazi.User.Domain.Users; using EntityFrameworkCoreMock; using FluentAssertions; +using Microsoft.AspNetCore.Identity; +using MockQueryable.Moq; +using Moq; using Xunit; namespace CQRS.Tests; @@ -22,13 +26,19 @@ public async Task AddUserToChat_UserAdded( [Greedy] MessengerUser user, [Greedy] GroupChat chat) { + // to prevent Guid.Empty collision + user.Id = Guid.NewGuid(); + + var userStore = new Mock>(); + var mgr = new Mock>(userStore.Object, null, null, null, null, null, null, null, null); var dbContextMock = new DbContextMock(); + var usersQueryMock = new[] {user}.AsQueryable().BuildMock(); + mgr.Setup(x => x.Users).Returns(usersQueryMock); dbContextMock.CreateDbSetMock(x => x.Chats, new[] {chat}); - dbContextMock.CreateDbSetMock(x => x.Users, new[] {user}); dbContextMock.CreateDbSetMock(x => x.ChatUsers); - var addUserToChatHandler = new ChatsCommandHandler(dbContextMock.Object); + var addUserToChatHandler = new ChatsCommandHandler(mgr.Object, dbContextMock.Object); var addUserToChatCommand = new AddUserToChatCommand(user.Id, chat.Id); // as soon as we have chat creator @@ -43,8 +53,7 @@ public async Task AddUserToChat_UserAdded( .With(chatUser => chatUser.MessengerUserId, user.Id) .Create(); - chat.Users.Should().HaveCount(2); - chat.Users.Should().Contain(expectedChatUser); + chat.Users.Should().Contain(expectedChatUser).And.HaveCount(2); } [Theory, AutoData] @@ -52,13 +61,19 @@ public async Task DeleteUserFromChat_UsersListEmpty( [Greedy] MessengerUser user, [Greedy] GroupChat chat) { + // to prevent Guid.Empty collision + user.Id = Guid.NewGuid(); + + var userStore = new Mock>(); var dbContextMock = new DbContextMock(); + var mgr = new Mock>(userStore.Object, null, null, null, null, null, null, null, null); + var usersQueryMock = new[] {user}.AsQueryable().BuildMock(); + mgr.Setup(x => x.Users).Returns(usersQueryMock); dbContextMock.CreateDbSetMock(x => x.Chats, new[] {chat}); - dbContextMock.CreateDbSetMock(x => x.Users, new[] {user}); dbContextMock.CreateDbSetMock(x => x.ChatUsers); - var chatsCommandHandler = new ChatsCommandHandler(dbContextMock.Object); + var chatsCommandHandler = new ChatsCommandHandler(mgr.Object, dbContextMock.Object); var addUserToChatCommand = new AddUserToChatCommand(user.Id, chat.Id); await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); diff --git a/Source/Tests/CQRS.Tests/UserTests.cs b/Source/Tests/CQRS.Tests/UserTests.cs index dfd608d..493c683 100644 --- a/Source/Tests/CQRS.Tests/UserTests.cs +++ b/Source/Tests/CQRS.Tests/UserTests.cs @@ -1,14 +1,22 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AutoFixture; using AutoFixture.Xunit2; +using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; +using Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; using Do_Svyazi.User.Application.CQRS.Users.Commands; using Do_Svyazi.User.Application.CQRS.Users.Handlers; using Do_Svyazi.User.DataAccess; +using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Users; using EntityFrameworkCoreMock; using FluentAssertions; +using Microsoft.AspNetCore.Identity; +using MockQueryable.Moq; +using Moq; using Xunit; namespace CQRS.Tests; @@ -16,21 +24,37 @@ namespace CQRS.Tests; public class UserTests { [Theory, AutoData] - public async Task AddUser_UserAdded([Greedy] MessengerUser user) + public async Task AddUser_UserAdded([Frozen] IFixture fixture, MessengerUser messengerUser) { - var dbContextMock = new DbContextMock(); - dbContextMock.CreateDbSetMock(x => x.Users, Array.Empty()); + var userStore = new Mock>(); + var mgr = new Mock>(userStore.Object, null, null, null, null, null, null, null, null); + mgr.Object.PasswordValidators.Add(new PasswordValidator()); + var users = new List(); - var usersCommandHandler = new UsersCommandHandler(dbContextMock.Object); + var roleStore = new Mock>(); + var userManager = new RoleManager(roleStore.Object, null, null, null, null); - var addUserCommand = new AddUserCommand(user.Name, user.NickName, user.Description); - await usersCommandHandler.Handle(addUserCommand, CancellationToken.None); + mgr.Setup(x => x.CreateAsync(It.IsAny(), It.IsAny())).ReturnsAsync(IdentityResult.Success).Callback((x, y) => users.Add(x)); + mgr.Setup(x => x.Users).Returns(users.AsQueryable()); + + var usersCommandHandler = new AuthenticateCommandHandler(mgr.Object, userManager); - MessengerUser gainMessengerUser = dbContextMock.Object.Users.Single(); + RegisterModel registerModel = fixture.Build() + .With(model => model.Email, messengerUser.Email) + .With(model => model.Name, messengerUser.UserName) + .With(model => model.UserName, messengerUser.UserName) + .With(model => model.PhoneNumber, messengerUser.PhoneNumber) + .Create(); - gainMessengerUser.Name.Should().Be(user.Name); - gainMessengerUser.NickName.Should().Be(user.NickName); - gainMessengerUser.Description.Should().Be(user.Description); + var addUserCommand = new RegisterCommand(registerModel); + await usersCommandHandler.Handle(addUserCommand, CancellationToken.None); + + MessengerUser gainMessengerUser = mgr.Object.Users.Single(); + + gainMessengerUser.UserName.Should().Be(registerModel.UserName); + gainMessengerUser.Name.Should().Be(registerModel.Name); + gainMessengerUser.Email.Should().Be(registerModel.Email); + gainMessengerUser.PhoneNumber.Should().Be(registerModel.PhoneNumber); } [Theory, AutoData] @@ -38,15 +62,18 @@ public async Task ChangeUserNameById_UserNameChanged( [Greedy] MessengerUser user, string newName) { - var dbContextMock = new DbContextMock(); - dbContextMock.CreateDbSetMock(x => x.Users, new[] {user}); + var store = new Mock>(); + var mgr = new Mock>(store.Object, null, null, null, null, null, null, null, null); + var usersQueryMock = new[] {user}.AsQueryable().BuildMock(); - var usersCommandHandler = new UsersCommandHandler(dbContextMock.Object); + mgr.Setup(x => x.Users).Returns(usersQueryMock); + mgr.Setup( userManager => userManager.FindByIdAsync(It.IsAny())).ReturnsAsync(user); - var changeUserNameCommand = new ChangeUserNameByIdCommand(user.Id, newName); + var usersCommandHandler = new UsersCommandHandler(mgr.Object); + var changeUserNameCommand = new ChangeUserNameByIdCommand($"{user.Id}", newName); await usersCommandHandler.Handle(changeUserNameCommand, CancellationToken.None); - MessengerUser gainMessengerUser = dbContextMock.Object.Users.Single(); + MessengerUser gainMessengerUser = mgr.Object.Users.Single(); gainMessengerUser.Name.Should().Be(newName); } diff --git a/Source/Tests/Integration.Tests/IntegrationTests.cs b/Source/Tests/Integration.Tests/IntegrationTests.cs index e8c2ed1..084d572 100644 --- a/Source/Tests/Integration.Tests/IntegrationTests.cs +++ b/Source/Tests/Integration.Tests/IntegrationTests.cs @@ -2,17 +2,21 @@ using System.Threading; using System.Threading.Tasks; using AutoMapper; +using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; +using Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; using Do_Svyazi.User.Application.CQRS.Chats.Commands; using Do_Svyazi.User.Application.CQRS.Chats.Handlers; using Do_Svyazi.User.Application.CQRS.Chats.Queries; -using Do_Svyazi.User.Application.CQRS.Users.Commands; using Do_Svyazi.User.Application.CQRS.Users.Handlers; using Do_Svyazi.User.Application.CQRS.Users.Queries; using Do_Svyazi.User.DataAccess; +using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Mapping; using FluentAssertions; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using NUnit.Framework; @@ -21,125 +25,138 @@ namespace Integration.Tests; [TestFixture] public class IntegrationTests : IDisposable { + private IMapper _mapper; private DoSvaziDbContext _context; + private ApplicationDbContext _identityContext; + private UserManager _userManager; + private RoleManager _roleManager; - [SetUp] + [OneTimeSetUp] public void Setup() { - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase("test_db") - .Options; - - _context = new DoSvaziDbContext(options); + _mapper = new MapperConfiguration(c => + { + c.AddProfile(); + }).CreateMapper(); + + _context = new DoSvaziDbContext( + new DbContextOptionsBuilder() + .UseInMemoryDatabase("test_db") + .Options); + + _identityContext = new ApplicationDbContext( + new DbContextOptionsBuilder() + .UseInMemoryDatabase("user_identity_test_db") + .Options); + + _userManager = new UserManager( + new UserStore(_identityContext), null, + new PasswordHasher(), null, null, null, null, null, null); + + _roleManager = new RoleManager( + new RoleStore(_identityContext), null, null, null, null); } - + [TearDown] - public void TearDown() => _context.Database.EnsureDeleted(); + public void TearDown() + { + _context.Database.EnsureDeleted(); + _identityContext.Database.EnsureDeleted(); + } [Test] public async Task AddUsersToChat_CheckUserHaveChat_CheckChatHaveUsers() { - var messengerUser1 = new MessengerUser("name1", "nickname1", "description1"); - var messengerUser2 = new MessengerUser("name2", "nickname2", "description2"); - - var mapper = GenerateMapper(); - var chatsCommandHandler = new ChatsCommandHandler(_context); - var usersCommandHandler = new UsersCommandHandler(_context); - var usersQueryHandler = new UsersQueryHandler(_context, mapper); - var chatsQueryHandler = new ChatsQueryHandler(_context, mapper); - - var addUser = new AddUser(messengerUser1.Name, messengerUser1.NickName, messengerUser1.Description); - Guid userId1 = await usersCommandHandler.Handle(addUser, CancellationToken.None); - - addUser = new AddUser(messengerUser2.Name, messengerUser2.NickName, messengerUser2.Description); - Guid userId2 = await usersCommandHandler.Handle(addUser, CancellationToken.None); - - var addGroupChat = new AddGroupChat(userId1, "chat1", "description1"); + RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); + RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); + + var chatsCommandHandler = new ChatsCommandHandler(_userManager, _context); + var authCommandHandler = new AuthenticateCommandHandler(_userManager, _roleManager); + var usersQueryHandler = new UsersQueryHandler(_userManager, _context, _mapper); + var chatsQueryHandler = new ChatsQueryHandler(_context, _mapper); + + var userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); + var userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); + + var addGroupChat = new AddGroupChatCommand(userId1, "chat1", "description1"); Guid chatGroupId = await chatsCommandHandler.Handle(addGroupChat, CancellationToken.None); - - var addUserToChatCommand = new AddUserToChat(userId2, chatGroupId); + + var addUserToChatCommand = new AddUserToChatCommand(userId2, chatGroupId); await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); - var getAllChatsIdsByUserId = new GetAllChatsIdsByUserId(userId1); + var getAllChatsIdsByUserId = new GetAllChatsIdsByUserIdQuery(userId1); var userChats1 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); - getAllChatsIdsByUserId = new GetAllChatsIdsByUserId(userId2); + getAllChatsIdsByUserId = new GetAllChatsIdsByUserIdQuery(userId2); var userChats2 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); - var getChatById = new GetChatById(chatGroupId); + var getChatById = new GetChatByIdQuery(chatGroupId); MessengerChatDto chat = await chatsQueryHandler.Handle(getChatById, CancellationToken.None); chat.Users.Should().Contain(userId1) .And.Contain(userId2) .And.HaveCount(2); + userChats1.Should().Contain(chatGroupId).And.HaveCount(1); userChats2.Should().Contain(chatGroupId).And.HaveCount(1); } - + [Test] public async Task DeleteUserFromChat_CheckUserNotHaveChat() { - var messengerUser1 = new MessengerUser("name1", "nickname1", "description1"); - var messengerUser2 = new MessengerUser("name2", "nickname2", "description2"); - var messengerUser3 = new MessengerUser("name3", "nickname3", "description3"); - - var mapper = GenerateMapper(); - var chatsCommandHandler = new ChatsCommandHandler(_context); - var usersCommandHandler = new UsersCommandHandler(_context); - var usersQueryHandler = new UsersQueryHandler(_context, mapper); - var chatsQueryHandler = new ChatsQueryHandler(_context, mapper); - - var addUser = new AddUser(messengerUser1.Name, messengerUser1.NickName, messengerUser1.Description); - Guid userId1 = await usersCommandHandler.Handle(addUser, CancellationToken.None); - addUser = new AddUser(messengerUser2.Name, messengerUser2.NickName, messengerUser2.Description); - Guid userId2 = await usersCommandHandler.Handle(addUser, CancellationToken.None); - addUser = new AddUser(messengerUser3.Name, messengerUser3.NickName, messengerUser3.Description); - Guid userId3 = await usersCommandHandler.Handle(addUser, CancellationToken.None); - - var addGroupChat = new AddGroupChat(userId1, "chat1", "description1"); + RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); + RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); + RegisterModel userModel3 = CreateRegisterModel("name3", "nickname3", "email3", "phoneNumber3"); + + var chatsCommandHandler = new ChatsCommandHandler(_userManager, _context); + var authCommandHandler = new AuthenticateCommandHandler(_userManager, _roleManager); + var usersQueryHandler = new UsersQueryHandler(_userManager, _context, _mapper); + var chatsQueryHandler = new ChatsQueryHandler(_context, _mapper); + + Guid userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); + Guid userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); + Guid userId3 = await authCommandHandler.Handle(new RegisterCommand(userModel3), CancellationToken.None); + + var addGroupChat = new AddGroupChatCommand(userId1, "chat1", "description1"); Guid chatGroupId = await chatsCommandHandler.Handle(addGroupChat, CancellationToken.None); - - var addUserToChatCommand = new AddUserToChat(userId2, chatGroupId); + + var addUserToChatCommand = new AddUserToChatCommand(userId2, chatGroupId); await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); - addUserToChatCommand = new AddUserToChat(userId3, chatGroupId); + addUserToChatCommand = new AddUserToChatCommand(userId3, chatGroupId); await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); - var getAllChatsIdsByUserId = new GetAllChatsIdsByUserId(userId1); - var userChats1 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); - - getAllChatsIdsByUserId = new GetAllChatsIdsByUserId(userId2); - var userChats2 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); - - getAllChatsIdsByUserId = new GetAllChatsIdsByUserId(userId3); - var userChats3 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); + var userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + var userChats2 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId2), CancellationToken.None); + var userChats3 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId3), CancellationToken.None); userChats1.Should().Contain(chatGroupId).And.HaveCount(1); userChats2.Should().Contain(chatGroupId).And.HaveCount(1); userChats3.Should().Contain(chatGroupId).And.HaveCount(1); - var deleteUserFromChat = new DeleteUserFromChat(userId3, chatGroupId); - await chatsCommandHandler.Handle(deleteUserFromChat, CancellationToken.None); - getAllChatsIdsByUserId = new GetAllChatsIdsByUserId(userId3); - userChats3 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); - - var getChatById = new GetChatById(chatGroupId); - MessengerChatDto chat = await chatsQueryHandler.Handle(getChatById, CancellationToken.None); + await chatsCommandHandler.Handle(new DeleteUserFromChatCommand(userId3, chatGroupId), CancellationToken.None); + userChats3 = await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId3), CancellationToken.None); + + MessengerChatDto chat = + await chatsQueryHandler.Handle(new GetChatByIdQuery(chatGroupId), CancellationToken.None); chat.Users.Should().NotContain(userId3).And.HaveCount(2); userChats3.Should().NotContain(chatGroupId).And.HaveCount(0); } - - public static IMapper GenerateMapper() - { - var mapperConfig = new MapperConfiguration(c => - { - c.AddProfile(); - }); - - return mapperConfig.CreateMapper(); - } public void Dispose() { _context.Dispose(); + _identityContext.Dispose(); } + + private RegisterModel CreateRegisterModel(string userName, string name, string email, string phoneNumber) => new() + { + UserName = userName, + Name = name, + Email = email, + Password = $"Test??111{Guid.NewGuid()}", + PhoneNumber = phoneNumber, + }; } \ No newline at end of file From 3f138ed8022b7ad1010cecd5bd682604690f2a2d Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 25 Jun 2022 23:53:30 +0300 Subject: [PATCH 21/45] style: tests codestyle --- .../Integration.Tests/IntegrationTests.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Source/Tests/Integration.Tests/IntegrationTests.cs b/Source/Tests/Integration.Tests/IntegrationTests.cs index 084d572..764c26f 100644 --- a/Source/Tests/Integration.Tests/IntegrationTests.cs +++ b/Source/Tests/Integration.Tests/IntegrationTests.cs @@ -78,21 +78,18 @@ public async Task AddUsersToChat_CheckUserHaveChat_CheckChatHaveUsers() var userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); var userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); - var addGroupChat = new AddGroupChatCommand(userId1, "chat1", "description1"); - Guid chatGroupId = await chatsCommandHandler.Handle(addGroupChat, CancellationToken.None); - - var addUserToChatCommand = new AddUserToChatCommand(userId2, chatGroupId); - await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); - - var getAllChatsIdsByUserId = new GetAllChatsIdsByUserIdQuery(userId1); - var userChats1 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); + Guid chatGroupId = await chatsCommandHandler.Handle(new AddGroupChatCommand(userId1, "chat1", "description1"), CancellationToken.None); + await chatsCommandHandler.Handle(new AddUserToChatCommand(userId2, chatGroupId), CancellationToken.None); - getAllChatsIdsByUserId = new GetAllChatsIdsByUserIdQuery(userId2); - var userChats2 = await usersQueryHandler.Handle(getAllChatsIdsByUserId, CancellationToken.None); - var getChatById = new GetChatByIdQuery(chatGroupId); - MessengerChatDto chat = await chatsQueryHandler.Handle(getChatById, CancellationToken.None); + var userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + var userChats2 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId2), CancellationToken.None); + MessengerChatDto chat = + await chatsQueryHandler.Handle(new GetChatByIdQuery(chatGroupId), CancellationToken.None); - chat.Users.Should().Contain(userId1) + chat.Users.Should() + .Contain(userId1) .And.Contain(userId2) .And.HaveCount(2); From 6e2acc59e3834caa83ac014b607ccf8b023dd0ec Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 02:26:35 +0300 Subject: [PATCH 22/45] test: tests fixed with new mockExtension methods --- Source/Tests/CQRS.Tests/ChatTests.cs | 31 +++++----------- .../CQRS.Tests/Extensions/MockExtensions.cs | 34 ++++++++++++++++- Source/Tests/CQRS.Tests/UserTests.cs | 37 ++++++------------- 3 files changed, 55 insertions(+), 47 deletions(-) diff --git a/Source/Tests/CQRS.Tests/ChatTests.cs b/Source/Tests/CQRS.Tests/ChatTests.cs index 15c2ede..6bb142d 100644 --- a/Source/Tests/CQRS.Tests/ChatTests.cs +++ b/Source/Tests/CQRS.Tests/ChatTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AutoFixture; @@ -12,9 +11,8 @@ using EntityFrameworkCoreMock; using FluentAssertions; using Microsoft.AspNetCore.Identity; -using MockQueryable.Moq; -using Moq; using Xunit; +using static CQRS.Tests.Extensions.MockExtensions; namespace CQRS.Tests; @@ -23,22 +21,18 @@ public class ChatTests [Theory, AutoData] public async Task AddUserToChat_UserAdded( IFixture fixture, - [Greedy] MessengerUser user, + MessengerUser user, [Greedy] GroupChat chat) { - // to prevent Guid.Empty collision - user.Id = Guid.NewGuid(); + var users = new List {user}; - var userStore = new Mock>(); - var mgr = new Mock>(userStore.Object, null, null, null, null, null, null, null, null); + var mockUserManager = MockUserManager, MessengerUser>(users); var dbContextMock = new DbContextMock(); - var usersQueryMock = new[] {user}.AsQueryable().BuildMock(); - mgr.Setup(x => x.Users).Returns(usersQueryMock); dbContextMock.CreateDbSetMock(x => x.Chats, new[] {chat}); dbContextMock.CreateDbSetMock(x => x.ChatUsers); - var addUserToChatHandler = new ChatsCommandHandler(mgr.Object, dbContextMock.Object); + var addUserToChatHandler = new ChatsCommandHandler(mockUserManager.Object, dbContextMock.Object); var addUserToChatCommand = new AddUserToChatCommand(user.Id, chat.Id); // as soon as we have chat creator @@ -58,22 +52,17 @@ public async Task AddUserToChat_UserAdded( [Theory, AutoData] public async Task DeleteUserFromChat_UsersListEmpty( - [Greedy] MessengerUser user, + MessengerUser user, [Greedy] GroupChat chat) { - // to prevent Guid.Empty collision - user.Id = Guid.NewGuid(); + var users = new List {user}; - var userStore = new Mock>(); + var mockUserManager = MockUserManager, MessengerUser>(users); var dbContextMock = new DbContextMock(); - var mgr = new Mock>(userStore.Object, null, null, null, null, null, null, null, null); - var usersQueryMock = new[] {user}.AsQueryable().BuildMock(); - - mgr.Setup(x => x.Users).Returns(usersQueryMock); dbContextMock.CreateDbSetMock(x => x.Chats, new[] {chat}); dbContextMock.CreateDbSetMock(x => x.ChatUsers); - var chatsCommandHandler = new ChatsCommandHandler(mgr.Object, dbContextMock.Object); + var chatsCommandHandler = new ChatsCommandHandler(mockUserManager.Object, dbContextMock.Object); var addUserToChatCommand = new AddUserToChatCommand(user.Id, chat.Id); await chatsCommandHandler.Handle(addUserToChatCommand, CancellationToken.None); diff --git a/Source/Tests/CQRS.Tests/Extensions/MockExtensions.cs b/Source/Tests/CQRS.Tests/Extensions/MockExtensions.cs index 24b6d07..1611c56 100644 --- a/Source/Tests/CQRS.Tests/Extensions/MockExtensions.cs +++ b/Source/Tests/CQRS.Tests/Extensions/MockExtensions.cs @@ -1,11 +1,14 @@ +using System.Collections.Generic; using System.Linq; +using Microsoft.AspNetCore.Identity; +using MockQueryable.Moq; using Moq; namespace CQRS.Tests.Extensions; public static class MockExtensions { - private static void MockDbSet(Mock mock, T[] items) + public static void MockDbSet(Mock mock, T[] items) { IQueryable itemsQueryable = items.AsQueryable(); @@ -25,4 +28,33 @@ private static void MockDbSet(Mock mock, T[] items) .Setup(x => x.GetEnumerator()) .Returns(itemsQueryable.GetEnumerator()); } + + public static Mock MockUserManager(List? users = null) + where TOut : class + where T : UserManager + { + var mock = new Mock(new Mock>().Object, null, null, null, null, null, null, null, null); + mock.Object.PasswordValidators.Add(new PasswordValidator()); + + if (users != null) + { + mock.Setup(x => x.CreateAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(IdentityResult.Success) + .Callback((x, y) => users.Add(x)); + + mock.Setup(x => x.Users).Returns(users.AsQueryable().BuildMock()); + } + + + return mock; + } + + public static Mock MockRoleManager() + where TOut : class + where T : RoleManager + { + var mock = new Mock(new Mock>().Object, new RoleValidator[] { }, null, null, null); + + return mock; + } } \ No newline at end of file diff --git a/Source/Tests/CQRS.Tests/UserTests.cs b/Source/Tests/CQRS.Tests/UserTests.cs index 493c683..d6656ce 100644 --- a/Source/Tests/CQRS.Tests/UserTests.cs +++ b/Source/Tests/CQRS.Tests/UserTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -9,15 +8,13 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; using Do_Svyazi.User.Application.CQRS.Users.Commands; using Do_Svyazi.User.Application.CQRS.Users.Handlers; -using Do_Svyazi.User.DataAccess; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Users; -using EntityFrameworkCoreMock; using FluentAssertions; using Microsoft.AspNetCore.Identity; -using MockQueryable.Moq; using Moq; using Xunit; +using static CQRS.Tests.Extensions.MockExtensions; namespace CQRS.Tests; @@ -26,18 +23,12 @@ public class UserTests [Theory, AutoData] public async Task AddUser_UserAdded([Frozen] IFixture fixture, MessengerUser messengerUser) { - var userStore = new Mock>(); - var mgr = new Mock>(userStore.Object, null, null, null, null, null, null, null, null); - mgr.Object.PasswordValidators.Add(new PasswordValidator()); var users = new List(); - var roleStore = new Mock>(); - var userManager = new RoleManager(roleStore.Object, null, null, null, null); + var mockUserManager = MockUserManager, MessengerUser>(users); + var mockRoleManager = MockRoleManager, MessageIdentityRole>(); - mgr.Setup(x => x.CreateAsync(It.IsAny(), It.IsAny())).ReturnsAsync(IdentityResult.Success).Callback((x, y) => users.Add(x)); - mgr.Setup(x => x.Users).Returns(users.AsQueryable()); - - var usersCommandHandler = new AuthenticateCommandHandler(mgr.Object, userManager); + var usersCommandHandler = new AuthenticateCommandHandler(mockUserManager.Object, mockRoleManager.Object); RegisterModel registerModel = fixture.Build() .With(model => model.Email, messengerUser.Email) @@ -49,7 +40,7 @@ public async Task AddUser_UserAdded([Frozen] IFixture fixture, MessengerUser mes var addUserCommand = new RegisterCommand(registerModel); await usersCommandHandler.Handle(addUserCommand, CancellationToken.None); - MessengerUser gainMessengerUser = mgr.Object.Users.Single(); + MessengerUser gainMessengerUser = mockUserManager.Object.Users.Single(); gainMessengerUser.UserName.Should().Be(registerModel.UserName); gainMessengerUser.Name.Should().Be(registerModel.Name); @@ -58,22 +49,18 @@ public async Task AddUser_UserAdded([Frozen] IFixture fixture, MessengerUser mes } [Theory, AutoData] - public async Task ChangeUserNameById_UserNameChanged( - [Greedy] MessengerUser user, - string newName) + public async Task ChangeUserNameById_UserNameChanged(MessengerUser user, string newName) { - var store = new Mock>(); - var mgr = new Mock>(store.Object, null, null, null, null, null, null, null, null); - var usersQueryMock = new[] {user}.AsQueryable().BuildMock(); + var users = new List {user}; - mgr.Setup(x => x.Users).Returns(usersQueryMock); - mgr.Setup( userManager => userManager.FindByIdAsync(It.IsAny())).ReturnsAsync(user); + var mockUserManager = MockUserManager, MessengerUser>(users); + mockUserManager.Setup( userManager => userManager.FindByIdAsync($"{user.Id}")).ReturnsAsync(user); - var usersCommandHandler = new UsersCommandHandler(mgr.Object); - var changeUserNameCommand = new ChangeUserNameByIdCommand($"{user.Id}", newName); + var usersCommandHandler = new UsersCommandHandler(mockUserManager.Object); + var changeUserNameCommand = new ChangeUserNameByIdCommand(user.Id, newName); await usersCommandHandler.Handle(changeUserNameCommand, CancellationToken.None); - MessengerUser gainMessengerUser = mgr.Object.Users.Single(); + MessengerUser gainMessengerUser = mockUserManager.Object.Users.Single(); gainMessengerUser.Name.Should().Be(newName); } From c24d833ace51cc591273f3d4d32f5ec8f94cb4ba Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 02:28:00 +0300 Subject: [PATCH 23/45] fix: small bug/logic fixes --- .../Handlers/AuthenticateCommandHandler.cs | 2 +- .../Handlers/AuthenticateQueryHandler.cs | 34 +++++++++++++------ .../Authenticate/Queries/GetUsersRequest.cs | 4 +-- .../ChangeUserDescriptionByIdCommand.cs | 2 +- .../Commands/ChangeUserNameByIdCommand.cs | 2 +- .../Users/Commands/ChangeUserNickNameById.cs | 2 +- .../CQRS/Users/Commands/DeleteUserCommand.cs | 2 +- .../Users/Handlers/UsersCommandHandler.cs | 22 +++++------- .../CQRS/Users/Handlers/UsersQueryHandler.cs | 13 ++++--- .../CQRS/Users/Queries/GetUserQuery.cs | 4 +-- .../Users/MessengerUserDto.cs | 2 +- .../Authenticate/LoginModel.cs | 4 +-- .../Users/MessengerUser.cs | 12 ++----- .../UserController.cs | 2 +- 14 files changed, 55 insertions(+), 52 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs index 664b648..907b2ff 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs @@ -45,7 +45,7 @@ public async Task Handle(RegisterAdminCommand request, CancellationToken c RegisterModel registerModel = request.model; if (await _userManager.FindByNameAsync(registerModel.UserName) is not null) - throw new Do_Svyazi_User_BusinessLogicException($"User with nickName {registerModel.UserName} exists"); + throw new Do_Svyazi_User_BusinessLogicException($"User with userName {registerModel.UserName} exists"); MessengerUser user = CreateIdentityUser(registerModel); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs index 5bf06f8..2e32883 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs @@ -1,11 +1,14 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; +using AutoMapper; +using AutoMapper.QueryableExtensions; using Do_Svyazi.User.Application.CQRS.Authenticate.Queries; using Do_Svyazi.User.Application.CQRS.Handlers; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Exceptions; using Do_Svyazi.User.Domain.Users; +using Do_Svyazi.User.Dtos.Users; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -16,26 +19,28 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; public class AuthenticateQueryHandler : IQueryHandler, IQueryHandler, - IQueryHandler> + IQueryHandler> { private const string NameType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; private readonly UserManager _userManager; private readonly IConfiguration _configuration; + private readonly IMapper _mapper; - public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration) + public AuthenticateQueryHandler(UserManager userManager, IConfiguration configuration, IMapper mapper) { _userManager = userManager; _configuration = configuration; + _mapper = mapper; } public async Task Handle(LoginRequest request, CancellationToken cancellationToken) { - var token = new JwtSecurityToken(); LoginModel loginModel = request.model; MessengerUser user = await GetUserByUsernameOrEmail(loginModel); - if (!await _userManager.CheckPasswordAsync(user, loginModel.Password)) return token; + if (!await _userManager.CheckPasswordAsync(user, loginModel.Password)) + throw new UnauthorizedAccessException("Can't login with this credentials"); IList? userRoles = await _userManager.GetRolesAsync(user); @@ -62,8 +67,10 @@ public async Task Handle(AuthenticateByJwtRequest request, CancellationTok return identityUser.Id; } - public async Task> Handle(GetUsersRequest request, CancellationToken cancellationToken) - => await _userManager.Users.ToListAsync(cancellationToken: cancellationToken); + public async Task> Handle(GetUsersRequest request, CancellationToken cancellationToken) + => await _userManager.Users + .ProjectTo(_mapper.ConfigurationProvider) + .ToListAsync(cancellationToken: cancellationToken); private JwtSecurityToken GetToken(List authClaims) { @@ -81,12 +88,17 @@ private JwtSecurityToken GetToken(List authClaims) private async Task GetUserByUsernameOrEmail(LoginModel loginModel) { - if (loginModel.NickName is not null) - return await _userManager.FindByNameAsync(loginModel.NickName); + MessengerUser? user = default; - if (loginModel.Email is not null) - return await _userManager.FindByEmailAsync(loginModel.Email); + if (loginModel.UserName is not null) + user = await _userManager.FindByNameAsync(loginModel.UserName); - throw new Do_Svyazi_User_NotFoundException("User to login was not found"); + if (user is null && loginModel.Email is not null) + user = await _userManager.FindByEmailAsync(loginModel.Email); + + if (user is null) + throw new Do_Svyazi_User_NotFoundException($"User {loginModel.UserName} to login was not found"); + + return user; } } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs index aa6ec14..008e942 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/GetUsersRequest.cs @@ -1,7 +1,7 @@ -using Do_Svyazi.User.Domain.Users; +using Do_Svyazi.User.Dtos.Users; using MediatR; namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; public record GetUsersRequest - : IRequest>; \ No newline at end of file + : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs index 2f6df9f..daa01e2 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserDescriptionByIdCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record ChangeUserDescriptionByIdCommand(string userId, string description) +public record ChangeUserDescriptionByIdCommand(Guid userId, string description) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs index 50a531f..e82f5e3 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNameByIdCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record ChangeUserNameByIdCommand(string userId, string name) +public record ChangeUserNameByIdCommand(Guid userId, string name) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs index bd64b3a..aab8419 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/ChangeUserNickNameById.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record SetUserNickNameByIdCommand(string userId, string nickName) +public record SetUserNickNameByIdCommand(Guid userId, string userName) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs index b2f71e1..a4121a8 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Commands/DeleteUserCommand.cs @@ -2,5 +2,5 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Commands; -public record DeleteUserCommand(string userId) +public record DeleteUserCommand(Guid userId) : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs index fa0ed8e..5e320a6 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs @@ -19,7 +19,7 @@ public class UsersCommandHandler : public async Task Handle(ChangeUserDescriptionByIdCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? + MessengerUser messengerUser = await _userManager.FindByIdAsync($"{request.userId}") ?? throw new Do_Svyazi_User_NotFoundException( $"User with id {request.userId} to change description was not found"); @@ -32,9 +32,7 @@ public async Task Handle(ChangeUserDescriptionByIdCommand request, Cancell public async Task Handle(ChangeUserNameByIdCommand request, CancellationToken cancellationToken) { - var users = _userManager.Users.ToList(); - - MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? + var messengerUser = await _userManager.FindByIdAsync($"{request.userId}") ?? throw new Do_Svyazi_User_NotFoundException($"User with id {request.userId} to change name was not found"); messengerUser.ChangeName(request.name); @@ -46,23 +44,21 @@ public async Task Handle(ChangeUserNameByIdCommand request, CancellationTo public async Task Handle(SetUserNickNameByIdCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? + var messengerUser = await _userManager.FindByIdAsync($"{request.userId}") ?? throw new Do_Svyazi_User_NotFoundException( - $"User with id {request.userId} to change nickName was not found"); - - if (NickNameExists(request.nickName)) - throw new Do_Svyazi_User_BusinessLogicException($"Nickname = {request.nickName} already exists in messenger"); + $"User with id {request.userId} to change userName was not found"); - messengerUser.ChangeNickName(request.nickName); + if (IsNickNameExist(request.userName)) + throw new Do_Svyazi_User_BusinessLogicException($"Nickname = {request.userName} already exists in messenger"); - await _userManager.UpdateAsync(messengerUser); + await _userManager.SetUserNameAsync(messengerUser, request.userName); return Unit.Value; } public async Task Handle(DeleteUserCommand request, CancellationToken cancellationToken) { - MessengerUser messengerUser = await _userManager.FindByIdAsync(request.userId) ?? + var messengerUser = await _userManager.FindByIdAsync($"{request.userId}") ?? throw new Do_Svyazi_User_NotFoundException($"Can't find user with id = {request.userId} to delete"); await _userManager.DeleteAsync(messengerUser); @@ -70,5 +66,5 @@ public async Task Handle(DeleteUserCommand request, CancellationToken canc return Unit.Value; } - private bool NickNameExists(string nickName) => _userManager.FindByNameAsync(nickName) is not null; + private bool IsNickNameExist(string nickName) => _userManager.FindByNameAsync(nickName) is null; } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs index 1692e17..8520f46 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersQueryHandler.cs @@ -15,7 +15,7 @@ namespace Do_Svyazi.User.Application.CQRS.Users.Handlers; public class UsersQueryHandler : IQueryHandler>, IQueryHandler>, - IQueryHandler, + IQueryHandler, IQueryHandler> { private readonly UserManager _userManager; @@ -43,10 +43,13 @@ public async Task> Handle(GetAllChatsIdsByUserIdQuery reques .Select(chatUser => chatUser.ChatId) .ToListAsync(cancellationToken); - public async Task Handle(GetUserQuery request, CancellationToken cancellationToken) - => await _userManager.Users - .SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken: cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException($"User with id = {request.userId} doesn't exist"); + public async Task Handle(GetUserQuery request, CancellationToken cancellationToken) + { + var user = await _userManager.FindByIdAsync($"{request.userId}") + ?? throw new Do_Svyazi_User_NotFoundException($"User with id = {request.userId} doesn't exist"); + + return _mapper.Map(user); + } public async Task> Handle(GetUsersQuery request, CancellationToken cancellationToken) => await _userManager.Users diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs index 104f50f..cb1af4a 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Queries/GetUserQuery.cs @@ -1,7 +1,7 @@ -using Do_Svyazi.User.Domain.Users; +using Do_Svyazi.User.Dtos.Users; using MediatR; namespace Do_Svyazi.User.Application.CQRS.Users.Queries; public record GetUserQuery(Guid userId) - : IRequest; \ No newline at end of file + : IRequest; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Dtos/Users/MessengerUserDto.cs b/Source/Application/Do-Svyazi.User.Dtos/Users/MessengerUserDto.cs index f020df6..fc27df2 100644 --- a/Source/Application/Do-Svyazi.User.Dtos/Users/MessengerUserDto.cs +++ b/Source/Application/Do-Svyazi.User.Dtos/Users/MessengerUserDto.cs @@ -4,6 +4,6 @@ public record MessengerUserDto { public Guid Id { get; init; } public string? Name { get; init; } - public string? NickName { get; init; } + public string? UserName { get; init; } public string? Description { get; init; } } \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs index 4776b33..59ea5f5 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Authenticate/LoginModel.cs @@ -4,11 +4,11 @@ namespace Do_Svyazi.User.Domain.Authenticate; public record LoginModel { - public string? NickName { get; init; } + public string? UserName { get; init; } public string? Email { get; init; } [Required(ErrorMessage = "Password is required")] public string? Password { get; init; } - public override int GetHashCode() => HashCode.Combine(NickName, Email); + public override int GetHashCode() => HashCode.Combine(UserName, Email); } \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs index 1071865..a386b94 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs @@ -13,13 +13,13 @@ public MessengerUser(string name, string nickName, string? email, string? phoneN if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name), "User name can't be null"); if (string.IsNullOrWhiteSpace(nickName)) - throw new ArgumentNullException(nameof(nickName), "User nickName can't be null"); + throw new ArgumentNullException(nameof(nickName), "User userName can't be null"); + Id = Guid.NewGuid(); Email = email; PhoneNumber = phoneNumber; Name = name; Description = string.IsNullOrEmpty(description) ? DefaultDescription : description; - Id = Guid.NewGuid(); } public MessengerUser() { } @@ -27,14 +27,6 @@ public MessengerUser() { } public string Name { get; private set; } public string Description { get; private set; } - public virtual void ChangeNickName(string nickName) - { - if (string.IsNullOrWhiteSpace(nickName)) - throw new ArgumentNullException(nameof(nickName), "User nickName to change is null"); - - UserName = nickName; - } - public virtual void ChangeName(string name) { if (string.IsNullOrWhiteSpace(name)) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index a69c5b7..e83b60f 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -32,7 +32,7 @@ public async Task>> GetUsers( } [HttpGet(nameof(GetUser))] - public async Task> GetUser( + public async Task> GetUser( [FromQuery] GetUserQuery getUserQuery, CancellationToken cancellationToken) { var response = await _mediator.Send(getUserQuery, cancellationToken); From 4f642597dc0be52744374d23d524e8c5586def0a Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 02:49:16 +0300 Subject: [PATCH 24/45] chore: CQRS.Tests renamed to Unit.Tests --- Do-Svyazi.User.sln | 2 +- Source/Tests/{CQRS.Tests => Unit.Tests/CQRS}/ChatTests.cs | 2 +- Source/Tests/{CQRS.Tests => Unit.Tests/CQRS}/UserTests.cs | 2 +- .../{CQRS.Tests => Unit.Tests}/Extensions/MockExtensions.cs | 0 .../CQRS.Tests.csproj => Unit.Tests/Unit.Tests.csproj} | 3 +-- 5 files changed, 4 insertions(+), 5 deletions(-) rename Source/Tests/{CQRS.Tests => Unit.Tests/CQRS}/ChatTests.cs (99%) rename Source/Tests/{CQRS.Tests => Unit.Tests/CQRS}/UserTests.cs (99%) rename Source/Tests/{CQRS.Tests => Unit.Tests}/Extensions/MockExtensions.cs (100%) rename Source/Tests/{CQRS.Tests/CQRS.Tests.csproj => Unit.Tests/Unit.Tests.csproj} (97%) diff --git a/Do-Svyazi.User.sln b/Do-Svyazi.User.sln index 0b9ecd9..55d843e 100644 --- a/Do-Svyazi.User.sln +++ b/Do-Svyazi.User.sln @@ -24,7 +24,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do-Svyazi.User.Web.Controll EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do-Svyazi.User.Web.ApiClient", "Source\Presentation\Do-Svyazi.User.Web.ApiClient\Do-Svyazi.User.Web.ApiClient.csproj", "{A5520DDE-4790-46C6-BD8B-FD65BD5E32B9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRS.Tests", "Source\Tests\CQRS.Tests\CQRS.Tests.csproj", "{86C8E30B-B631-46E7-A0DD-815D0F447079}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit.Tests", "Source\Tests\Unit.Tests\Unit.Tests.csproj", "{86C8E30B-B631-46E7-A0DD-815D0F447079}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Integration.Tests", "Source\Tests\Integration.Tests\Integration.Tests.csproj", "{83F47902-3FCC-4D11-A780-5590930C224C}" EndProject diff --git a/Source/Tests/CQRS.Tests/ChatTests.cs b/Source/Tests/Unit.Tests/CQRS/ChatTests.cs similarity index 99% rename from Source/Tests/CQRS.Tests/ChatTests.cs rename to Source/Tests/Unit.Tests/CQRS/ChatTests.cs index 6bb142d..aa50247 100644 --- a/Source/Tests/CQRS.Tests/ChatTests.cs +++ b/Source/Tests/Unit.Tests/CQRS/ChatTests.cs @@ -14,7 +14,7 @@ using Xunit; using static CQRS.Tests.Extensions.MockExtensions; -namespace CQRS.Tests; +namespace CQRS.Tests.CQRS; public class ChatTests { diff --git a/Source/Tests/CQRS.Tests/UserTests.cs b/Source/Tests/Unit.Tests/CQRS/UserTests.cs similarity index 99% rename from Source/Tests/CQRS.Tests/UserTests.cs rename to Source/Tests/Unit.Tests/CQRS/UserTests.cs index d6656ce..77c1450 100644 --- a/Source/Tests/CQRS.Tests/UserTests.cs +++ b/Source/Tests/Unit.Tests/CQRS/UserTests.cs @@ -16,7 +16,7 @@ using Xunit; using static CQRS.Tests.Extensions.MockExtensions; -namespace CQRS.Tests; +namespace CQRS.Tests.CQRS; public class UserTests { diff --git a/Source/Tests/CQRS.Tests/Extensions/MockExtensions.cs b/Source/Tests/Unit.Tests/Extensions/MockExtensions.cs similarity index 100% rename from Source/Tests/CQRS.Tests/Extensions/MockExtensions.cs rename to Source/Tests/Unit.Tests/Extensions/MockExtensions.cs diff --git a/Source/Tests/CQRS.Tests/CQRS.Tests.csproj b/Source/Tests/Unit.Tests/Unit.Tests.csproj similarity index 97% rename from Source/Tests/CQRS.Tests/CQRS.Tests.csproj rename to Source/Tests/Unit.Tests/Unit.Tests.csproj index 7bb6dbc..d36c314 100644 --- a/Source/Tests/CQRS.Tests/CQRS.Tests.csproj +++ b/Source/Tests/Unit.Tests/Unit.Tests.csproj @@ -3,10 +3,9 @@ net6.0 enable - false - true + CQRS.Tests From 705c2ea60e3c17d9bbfab922fe94e1ae20fd1c0b Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 02:54:52 +0300 Subject: [PATCH 25/45] style: small codestyle && naming fixes in integration tests --- ...egrationTests.cs => ChatAndUserInteraction.cs} | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) rename Source/Tests/Integration.Tests/{IntegrationTests.cs => ChatAndUserInteraction.cs} (99%) diff --git a/Source/Tests/Integration.Tests/IntegrationTests.cs b/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs similarity index 99% rename from Source/Tests/Integration.Tests/IntegrationTests.cs rename to Source/Tests/Integration.Tests/ChatAndUserInteraction.cs index 764c26f..81312bd 100644 --- a/Source/Tests/Integration.Tests/IntegrationTests.cs +++ b/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs @@ -67,14 +67,14 @@ public void TearDown() [Test] public async Task AddUsersToChat_CheckUserHaveChat_CheckChatHaveUsers() { - RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); - RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); - var chatsCommandHandler = new ChatsCommandHandler(_userManager, _context); var authCommandHandler = new AuthenticateCommandHandler(_userManager, _roleManager); var usersQueryHandler = new UsersQueryHandler(_userManager, _context, _mapper); var chatsQueryHandler = new ChatsQueryHandler(_context, _mapper); + RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); + RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); + var userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); var userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); @@ -100,15 +100,16 @@ public async Task AddUsersToChat_CheckUserHaveChat_CheckChatHaveUsers() [Test] public async Task DeleteUserFromChat_CheckUserNotHaveChat() { - RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); - RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); - RegisterModel userModel3 = CreateRegisterModel("name3", "nickname3", "email3", "phoneNumber3"); - var chatsCommandHandler = new ChatsCommandHandler(_userManager, _context); var authCommandHandler = new AuthenticateCommandHandler(_userManager, _roleManager); var usersQueryHandler = new UsersQueryHandler(_userManager, _context, _mapper); var chatsQueryHandler = new ChatsQueryHandler(_context, _mapper); + RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); + RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); + RegisterModel userModel3 = CreateRegisterModel("name3", "nickname3", "email3", "phoneNumber3"); + + Guid userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); Guid userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); Guid userId3 = await authCommandHandler.Handle(new RegisterCommand(userModel3), CancellationToken.None); From f02edd6560e19f8608d653cf23bc4cccbd93d039 Mon Sep 17 00:00:00 2001 From: KotDimos Date: Sun, 26 Jun 2022 11:34:00 +0300 Subject: [PATCH 26/45] fix: add personal chat --- .../CQRS/Chats/Handlers/ChatsCommandHandler.cs | 2 +- Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index 2d231e1..1104931 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -74,7 +74,7 @@ await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.secondU Chat chat = new PersonalChat(firstUser, secondUser, request.name, request.description); - _context.ChatUsers.AddRange(chat.Users); + await _context.ChatUsers.AddRangeAsync(chat.Users, cancellationToken); await _context.Chats.AddAsync(chat, cancellationToken); await _context.SaveChangesAsync(cancellationToken); diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs index 1772df7..3e97a9f 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/PersonalChat.cs @@ -52,7 +52,7 @@ public PersonalChat(MessengerUser firstMessengerUser, MessengerUser secondMessen BaseAdminRole = _baseAdminRole; BaseUserRole = _baseUserRole; - ChatUser firstUser = CreateChatUser(secondMessengerUser, _baseAdminRole); + ChatUser firstUser = CreateChatUser(firstMessengerUser, _baseAdminRole); ChatUser secondUser = CreateChatUser(secondMessengerUser, _baseAdminRole); Users.AddRange(new[] { firstUser, secondUser }); From 87e5bdbe992e51011c741e1021c9c8babfa096ec Mon Sep 17 00:00:00 2001 From: KotDimos Date: Sun, 26 Jun 2022 11:34:53 +0300 Subject: [PATCH 27/45] feat: add test for add chats --- .../ChatAndUserInteraction.cs | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs b/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs index 81312bd..eed9c81 100644 --- a/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs +++ b/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs @@ -143,6 +143,87 @@ public async Task DeleteUserFromChat_CheckUserNotHaveChat() userChats3.Should().NotContain(chatGroupId).And.HaveCount(0); } + [Test] + public async Task UserCreateFourChats() + { + var chatsCommandHandler = new ChatsCommandHandler(_userManager, _context); + var authCommandHandler = new AuthenticateCommandHandler(_userManager, _roleManager); + var usersQueryHandler = new UsersQueryHandler(_userManager, _context, _mapper); + var chatsQueryHandler = new ChatsQueryHandler(_context, _mapper); + + RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); + RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); + Guid userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); + Guid userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); + + var addGroupChat = new AddGroupChatCommand(userId1, "chat1", "description1"); + Guid chatGroupId1 = await chatsCommandHandler.Handle(addGroupChat, CancellationToken.None); + var userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + + userChats1.Should().HaveCount(1); + + var addSavedMessages = new AddSavedMessagesCommand(userId1, "chat2", "description2"); + Guid chatGroupId2 = await chatsCommandHandler.Handle(addSavedMessages, CancellationToken.None); + + userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + + userChats1.Should().HaveCount(2); + + var addChannel = new AddChannelCommand(userId1, "chat3", "description3"); + Guid chatGroupId3 = await chatsCommandHandler.Handle(addChannel, CancellationToken.None); + + userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + + userChats1.Should().HaveCount(3); + + var addPersonalChat = new AddPersonalChatCommand(userId1, userId2, "chat4", "description4"); + Guid chatGroupId4 = await chatsCommandHandler.Handle(addPersonalChat, CancellationToken.None); + + userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + var userChats2 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId2), CancellationToken.None); + + userChats1.Should().HaveCount(4); + userChats2.Should().HaveCount(1); + } + + + [Test] + public async Task CreatePersonalChat() + { + var chatsCommandHandler = new ChatsCommandHandler(_userManager, _context); + var authCommandHandler = new AuthenticateCommandHandler(_userManager, _roleManager); + var usersQueryHandler = new UsersQueryHandler(_userManager, _context, _mapper); + var chatsQueryHandler = new ChatsQueryHandler(_context, _mapper); + + RegisterModel userModel1 = CreateRegisterModel("name1", "nickname1", "email1", "phoneNumber1"); + RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); + Guid userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); + Guid userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); + + var addPersonalChat = new AddPersonalChatCommand(userId1, userId2, "chat1", "description1"); + Guid chatGroupId1 = await chatsCommandHandler.Handle(addPersonalChat, CancellationToken.None); + + var userChats1 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId1), CancellationToken.None); + var userChats2 = + await usersQueryHandler.Handle(new GetAllChatsIdsByUserIdQuery(userId2), CancellationToken.None); + + var getChatById = new GetChatByIdQuery(chatGroupId1); + var chat = await chatsQueryHandler.Handle(getChatById, CancellationToken.None); + + chat.Users.Should() + .Contain(userId1).And + .Contain(userId2).And + .HaveCount(2); + userChats1.Should().HaveCount(1); + userChats2.Should().HaveCount(1); + } + public void Dispose() { _context.Dispose(); From 701a0dbabab0fc175b97270e44244305f481f046 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 16:05:02 +0300 Subject: [PATCH 28/45] fix: MessengerUser removed from ChatUser && ChatUserDto added --- .../Handlers/AuthenticateCommandHandler.cs | 19 ++++++++++--------- .../Chats/Handlers/ChatsCommandHandler.cs | 4 ---- .../CQRS/Chats/Handlers/ChatsQueryHandler.cs | 10 ++++------ .../Chats/Queries/GetUsersByChatIdQuery.cs | 4 ++-- .../Mapping/MappingProfile.cs | 1 + .../Do-Svyazi.User.Dtos/Users/ChatUserDto.cs | 10 ++++++++++ .../Do-Svyazi.User.Domain/Chats/Channel.cs | 2 +- .../Do-Svyazi.User.Domain/Chats/Chat.cs | 4 ---- .../Do-Svyazi.User.Domain/Chats/GroupChat.cs | 2 +- .../Do-Svyazi.User.Domain/Users/ChatUser.cs | 9 ++++----- .../ChatController.cs | 4 ++-- 11 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 Source/Application/Do-Svyazi.User.Dtos/Users/ChatUserDto.cs diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs index 907b2ff..620cc4a 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateCommandHandler.cs @@ -1,12 +1,10 @@ using Do_Svyazi.User.Application.CQRS.Authenticate.Commands; using Do_Svyazi.User.Application.CQRS.Handlers; -using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Exceptions; using Do_Svyazi.User.Domain.Users; using MediatR; using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; @@ -44,13 +42,7 @@ public async Task Handle(RegisterAdminCommand request, CancellationToken c { RegisterModel registerModel = request.model; - if (await _userManager.FindByNameAsync(registerModel.UserName) is not null) - throw new Do_Svyazi_User_BusinessLogicException($"User with userName {registerModel.UserName} exists"); - - MessengerUser user = CreateIdentityUser(registerModel); - - if (!(await _userManager.CreateAsync(user, registerModel.Password)).Succeeded) - throw new Do_Svyazi_User_BusinessLogicException("User creation failed! Please check user details and try again."); + MessengerUser user = await GetUserByUsernameOrEmail(registerModel); if (!await _roleManager.RoleExistsAsync(MessageIdentityRole.Admin)) await _roleManager.CreateAsync(new MessageIdentityRole(MessageIdentityRole.Admin)); @@ -69,4 +61,13 @@ public async Task Handle(RegisterAdminCommand request, CancellationToken c private MessengerUser CreateIdentityUser(RegisterModel userModel) => new (userModel.Name, userModel.UserName, userModel.Email, userModel.PhoneNumber); + + private async Task GetUserByUsernameOrEmail(RegisterModel registerModel) + { + MessengerUser user = await _userManager.FindByNameAsync(registerModel.UserName) + ?? await _userManager.FindByEmailAsync(registerModel.Email) + ?? throw new Do_Svyazi_User_NotFoundException($"User with userName {registerModel.UserName} or email {registerModel.Email} was not found"); + + return user; + } } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index 2d231e1..08cd49c 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -101,8 +101,6 @@ await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.userId, public async Task Handle(AddUserToChatCommand request, CancellationToken cancellationToken) { Chat chat = await _context.Chats - .Include(chat => chat.Users) - .ThenInclude(user => user.User) .Include(chat => chat.Users) .ThenInclude(user => user.Role) .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? @@ -125,8 +123,6 @@ public async Task Handle(AddUserToChatCommand request, CancellationToken c public async Task Handle(DeleteUserFromChatCommand request, CancellationToken cancellationToken) { Chat chat = await _context.Chats - .Include(chat => chat.Users) - .ThenInclude(user => user.User) .Include(chat => chat.Users) .ThenInclude(user => user.Role) .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs index c415a76..f512635 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsQueryHandler.cs @@ -4,8 +4,8 @@ using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Chats; using Do_Svyazi.User.Domain.Exceptions; -using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; +using Do_Svyazi.User.Dtos.Users; using Microsoft.EntityFrameworkCore; namespace Do_Svyazi.User.Application.CQRS.Chats.Handlers; @@ -14,7 +14,7 @@ public class ChatsQueryHandler : IQueryHandler, IQueryHandler>, IQueryHandler>, - IQueryHandler> + IQueryHandler> { private readonly IDbContext _context; private readonly IMapper _mapper; @@ -58,16 +58,14 @@ public async Task> Handle(GetUserIdsByChatIdQuery requ return _mapper.Map>(userIds); } - public async Task> Handle(GetUsersByChatIdQuery request, CancellationToken cancellationToken) + public async Task> Handle(GetUsersByChatIdQuery request, CancellationToken cancellationToken) { Chat chat = await _context.Chats - .Include(chat => chat.Users) - .ThenInclude(user => user.User) .Include(chat => chat.Users) .ThenInclude(user => user.Role) .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException($"Chat with id = {request.chatId} to get users was not found"); - return _mapper.Map>(chat.Users); + return _mapper.Map>(chat.Users); } } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs index d312dc3..63c535a 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Queries/GetUsersByChatIdQuery.cs @@ -1,8 +1,8 @@ -using Do_Svyazi.User.Domain.Users; +using Do_Svyazi.User.Dtos.Users; namespace Do_Svyazi.User.Application.CQRS.Chats.Queries; using MediatR; public record GetUsersByChatIdQuery(Guid chatId) - : IRequest>; \ No newline at end of file + : IRequest>; \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Dtos/Mapping/MappingProfile.cs b/Source/Application/Do-Svyazi.User.Dtos/Mapping/MappingProfile.cs index 73e995c..5f53b2d 100644 --- a/Source/Application/Do-Svyazi.User.Dtos/Mapping/MappingProfile.cs +++ b/Source/Application/Do-Svyazi.User.Dtos/Mapping/MappingProfile.cs @@ -20,6 +20,7 @@ public MappingProfile() .Select(user => user.MessengerUserId))); CreateMap(); + CreateMap(); CreateMap(); } } \ No newline at end of file diff --git a/Source/Application/Do-Svyazi.User.Dtos/Users/ChatUserDto.cs b/Source/Application/Do-Svyazi.User.Dtos/Users/ChatUserDto.cs new file mode 100644 index 0000000..4e0aab8 --- /dev/null +++ b/Source/Application/Do-Svyazi.User.Dtos/Users/ChatUserDto.cs @@ -0,0 +1,10 @@ +using Do_Svyazi.User.Dtos.Roles; + +namespace Do_Svyazi.User.Dtos.Users; + +public record ChatUserDto +{ + public string ChatUserName { get; init; } + public Guid MessengerUserId { get; init; } + public RoleDto Role { get; init; } +} \ No newline at end of file diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs index c9465aa..171d209 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Channel.cs @@ -145,7 +145,7 @@ public override void ChangeUserRole(MessengerUser user, Role role) if (role is null) throw new ArgumentNullException(nameof(role), $"Role to change in user {user.UserName} in chat {Name} is null"); - ChatUser chatUser = GetUser(user.UserName); + ChatUser chatUser = GetUser(user.Id); chatUser.ChangeRole(role); } diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs index 8ec3d55..2176504 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/Chat.cs @@ -49,10 +49,6 @@ public virtual void ChangeDescription(string description) public IReadOnlyCollection GetUsersByRole(Role role) => Users.Where(user => user.Role.Equals(role)).ToList(); - public ChatUser GetUser(string userName) => - Users.SingleOrDefault(user => user.User.UserName == userName) - ?? throw new Do_Svyazi_User_NotFoundException($"User is not found in chat {Name}"); - public ChatUser GetUser(Guid id) => Users.SingleOrDefault(user => user.MessengerUserId == id) ?? throw new Do_Svyazi_User_NotFoundException($"User is not found in chat {Name}"); diff --git a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs index ac8b726..580a1ab 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Chats/GroupChat.cs @@ -150,7 +150,7 @@ public override void ChangeUserRole(MessengerUser user, Role role) if (role is null) throw new ArgumentNullException(nameof(role), $"Role to set to user {user.Name} in chat {Name} is null"); - ChatUser chatUser = GetUser(user.UserName); + ChatUser chatUser = GetUser(user.Id); chatUser.ChangeRole(role); } diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs index 777cdcf..1a48f48 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/ChatUser.cs @@ -7,32 +7,31 @@ public class ChatUser { public ChatUser(MessengerUser user, Chat chat, Role role) { - User = user ?? throw new ArgumentNullException(nameof(user), $"User to create chatUser in chat {chat.Name} is null"); Chat = chat ?? throw new ArgumentNullException(nameof(chat), $"Chat to create chatUser with name {user.UserName} is null"); Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to create chatUser with userName {user.UserName} and {role} is null"); ChatId = chat.Id; MessengerUserId = user.Id; + ChatUserName = user.UserName; } public ChatUser() { } - public MessengerUser User { get; init; } public Guid Id { get; init; } = Guid.NewGuid(); + public string ChatUserName { get; init; } public Guid MessengerUserId { get; init; } public Chat Chat { get; init; } public Guid ChatId { get; init; } public Role Role { get; private set; } public void ChangeRole(Role role) => - Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to set to {User.UserName} in chat {Chat.Name} is null"); + Role = role ?? throw new ArgumentNullException(nameof(role), $"Role to set in chat {Chat.Name} is null"); public override bool Equals(object? obj) => Equals(obj as ChatUser); - public override int GetHashCode() => HashCode.Combine(Chat, User); + public override int GetHashCode() => HashCode.Combine(ChatId, MessengerUserId); private bool Equals(ChatUser? chatUser) => chatUser is not null && - User.Id.Equals(chatUser.User.Id) && Chat.Id.Equals(chatUser.Chat.Id) && MessengerUserId.Equals(chatUser.MessengerUserId); } \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index fb47f02..49728dc 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -1,8 +1,8 @@ using Do_Svyazi.User.Application.CQRS.Chats.Commands; using Do_Svyazi.User.Application.CQRS.Chats.Queries; using Do_Svyazi.User.Domain.Authenticate; -using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; +using Do_Svyazi.User.Dtos.Users; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -47,7 +47,7 @@ public async Task>> GetUserIdsByChatId( } [HttpGet(nameof(GetUsersByChatId))] - public async Task>> GetUsersByChatId( + public async Task>> GetUsersByChatId( [FromQuery] GetUsersByChatIdQuery getUsersByChatIdQuery, CancellationToken cancellationToken) { var response = await _mediator.Send(getUsersByChatIdQuery, cancellationToken); From 817961a82f0ae53f685c03768a4f932f8aa41d48 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 16:05:14 +0300 Subject: [PATCH 29/45] style: namespaces fixed --- .../CQRS/Users/Handlers/UsersCommandHandler.cs | 1 - Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs | 1 - .../Middlewares/AuthorizationMiddleware.cs | 1 - .../Do-Svyazi.User.Web.Controllers/UserController.cs | 1 - 4 files changed, 4 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs index 5e320a6..6298ada 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Users/Handlers/UsersCommandHandler.cs @@ -1,6 +1,5 @@ using Do_Svyazi.User.Application.CQRS.Handlers; using Do_Svyazi.User.Application.CQRS.Users.Commands; -using Do_Svyazi.User.Application.DbContexts; using Do_Svyazi.User.Domain.Exceptions; using Do_Svyazi.User.Domain.Users; using MediatR; diff --git a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs index a386b94..ecebb8b 100644 --- a/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs +++ b/Source/Domain/Do-Svyazi.User.Domain/Users/MessengerUser.cs @@ -1,4 +1,3 @@ -using Do_Svyazi.User.Domain.Chats; using Microsoft.AspNetCore.Identity; namespace Do_Svyazi.User.Domain.Users; diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs index 3a985a3..e7ce4d3 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/Middlewares/AuthorizationMiddleware.cs @@ -1,6 +1,5 @@ using System.IdentityModel.Tokens.Jwt; using System.Text; -using Do_Svyazi.User.Domain.Authenticate; using Do_Svyazi.User.Domain.Users; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs index e83b60f..ca09146 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/UserController.cs @@ -1,7 +1,6 @@ using Do_Svyazi.User.Application.CQRS.Users.Commands; using Do_Svyazi.User.Application.CQRS.Users.Queries; using Do_Svyazi.User.Domain.Authenticate; -using Do_Svyazi.User.Domain.Users; using Do_Svyazi.User.Dtos.Chats; using Do_Svyazi.User.Dtos.Users; using MediatR; From bfbbfc20fb51779dd67b4388f638114e6571735e Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 16:05:52 +0300 Subject: [PATCH 30/45] test: fixed after removing MessengerUser from ChatUser --- Source/Tests/Integration.Tests/ChatAndUserInteraction.cs | 1 - Source/Tests/Unit.Tests/CQRS/ChatTests.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs b/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs index 81312bd..b88854e 100644 --- a/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs +++ b/Source/Tests/Integration.Tests/ChatAndUserInteraction.cs @@ -109,7 +109,6 @@ public async Task DeleteUserFromChat_CheckUserNotHaveChat() RegisterModel userModel2 = CreateRegisterModel("name2", "nickname2", "email2", "phoneNumber2"); RegisterModel userModel3 = CreateRegisterModel("name3", "nickname3", "email3", "phoneNumber3"); - Guid userId1 = await authCommandHandler.Handle(new RegisterCommand(userModel1), CancellationToken.None); Guid userId2 = await authCommandHandler.Handle(new RegisterCommand(userModel2), CancellationToken.None); Guid userId3 = await authCommandHandler.Handle(new RegisterCommand(userModel3), CancellationToken.None); diff --git a/Source/Tests/Unit.Tests/CQRS/ChatTests.cs b/Source/Tests/Unit.Tests/CQRS/ChatTests.cs index aa50247..f232a30 100644 --- a/Source/Tests/Unit.Tests/CQRS/ChatTests.cs +++ b/Source/Tests/Unit.Tests/CQRS/ChatTests.cs @@ -42,7 +42,7 @@ public async Task AddUserToChat_UserAdded( ChatUser expectedChatUser = fixture.Build() .With(chatUser => chatUser.Chat, chat) - .With(chatUser => chatUser.User, user) + // .With(chatUser => chatUser.User, user) .With(chatUser => chatUser.ChatId, chat.Id) .With(chatUser => chatUser.MessengerUserId, user.Id) .Create(); From 5bf81ba2c367ddb88a7dcccb9c721713e8d6b125 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 16:23:41 +0300 Subject: [PATCH 31/45] fix: small fixes in user finding --- .../Chats/Handlers/ChatsCommandHandler.cs | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs index 87f631f..b58b00a 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Chats/Handlers/ChatsCommandHandler.cs @@ -29,12 +29,11 @@ public ChatsCommandHandler(UserManager userManager, IDbContext co public async Task Handle(AddChannelCommand request, CancellationToken cancellationToken) { - MessengerUser user = await _userManager.Users - .SingleOrDefaultAsync(user => user.Id == request.adminId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( + MessengerUser user = await _userManager.FindByIdAsync($"{request.adminId}") + ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.adminId} to create a channel was not found"); - Chat chat = new Channel(user, request.name, request.description); + var chat = new Channel(user, request.name, request.description); var chatAdmin = chat.Users.Single(); await _context.ChatUsers.AddAsync(chatAdmin, cancellationToken); @@ -50,7 +49,7 @@ public async Task Handle(AddGroupChatCommand request, CancellationToken ca ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.adminId} to create a group chat was not found"); - GroupChat chat = new GroupChat(user, request.name, request.description); + var chat = new GroupChat(user, request.name, request.description); var chatAdmin = chat.Users.Single(); await _context.ChatUsers.AddAsync(chatAdmin, cancellationToken); @@ -62,15 +61,13 @@ public async Task Handle(AddGroupChatCommand request, CancellationToken ca public async Task Handle(AddPersonalChatCommand request, CancellationToken cancellationToken) { - MessengerUser firstUser = - await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.firstUserId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( - $"User with id = {request.firstUserId} to create a personal chat was not found"); + MessengerUser firstUser = await _userManager.FindByIdAsync($"{request.firstUserId}") + ?? throw new Do_Svyazi_User_NotFoundException( + $"User with id = {request.firstUserId} to create a personal chat was not found"); - MessengerUser secondUser = - await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.secondUserId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( - $"User with id = {request.secondUserId} to create a personal chat was not found"); + MessengerUser secondUser = await _userManager.FindByIdAsync($"{request.secondUserId}") + ?? throw new Do_Svyazi_User_NotFoundException( + $"User with id = {request.secondUserId} to create a personal chat was not found"); Chat chat = new PersonalChat(firstUser, secondUser, request.name, request.description); @@ -83,10 +80,9 @@ await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.secondU public async Task Handle(AddSavedMessagesCommand request, CancellationToken cancellationToken) { - MessengerUser user = - await _userManager.Users.SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( - $"User with id = {request.userId} to create saved messages chat not found"); + MessengerUser user = await _userManager.FindByIdAsync($"{request.userId}") + ?? throw new Do_Svyazi_User_NotFoundException( + $"User with id = {request.userId} to create saved messages chat not found"); Chat chat = new SavedMessages(user, request.name, request.description); var chatAdmin = chat.Users.Single(); @@ -102,14 +98,13 @@ public async Task Handle(AddUserToChatCommand request, CancellationToken c { Chat chat = await _context.Chats .Include(chat => chat.Users) - .ThenInclude(user => user.Role) + .ThenInclude(user => user.Role) .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException( $"Chat with id = {request.chatId} to add user {request.userId} was not found"); - MessengerUser messengerUser = await _userManager.Users - .SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( + MessengerUser messengerUser = await _userManager.FindByIdAsync($"{request.userId}") + ?? throw new Do_Svyazi_User_NotFoundException( $"User with id = {request.userId} to be added into chat with id = {request.chatId} not found"); ChatUser newChatUser = chat.AddUser(messengerUser); @@ -124,14 +119,12 @@ public async Task Handle(DeleteUserFromChatCommand request, CancellationTo { Chat chat = await _context.Chats .Include(chat => chat.Users) - .ThenInclude(user => user.Role) + .ThenInclude(user => user.Role) .SingleOrDefaultAsync(chat => chat.Id == request.chatId, cancellationToken) ?? throw new Do_Svyazi_User_NotFoundException($"Chat with id {request.chatId} not found"); - MessengerUser messengerUser = await _userManager.Users - .SingleOrDefaultAsync(user => user.Id == request.userId, cancellationToken) ?? - throw new Do_Svyazi_User_NotFoundException( - $"User with id {request.userId} not found"); + MessengerUser messengerUser = await _userManager.FindByIdAsync($"{request.userId}") + ?? throw new Do_Svyazi_User_NotFoundException($"User with id {request.userId} not found"); var removedUser = chat.RemoveUser(messengerUser); From f266890e0eab2908cd7e0846f88e3e50c91c0300 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 16:32:39 +0300 Subject: [PATCH 32/45] fix: tests fixed --- Source/Tests/Unit.Tests/CQRS/ChatTests.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Tests/Unit.Tests/CQRS/ChatTests.cs b/Source/Tests/Unit.Tests/CQRS/ChatTests.cs index f232a30..b611f47 100644 --- a/Source/Tests/Unit.Tests/CQRS/ChatTests.cs +++ b/Source/Tests/Unit.Tests/CQRS/ChatTests.cs @@ -11,6 +11,7 @@ using EntityFrameworkCoreMock; using FluentAssertions; using Microsoft.AspNetCore.Identity; +using Moq; using Xunit; using static CQRS.Tests.Extensions.MockExtensions; @@ -27,8 +28,9 @@ public async Task AddUserToChat_UserAdded( var users = new List {user}; var mockUserManager = MockUserManager, MessengerUser>(users); - var dbContextMock = new DbContextMock(); + mockUserManager.Setup( userManager => userManager.FindByIdAsync($"{user.Id}")).ReturnsAsync(user); + var dbContextMock = new DbContextMock(); dbContextMock.CreateDbSetMock(x => x.Chats, new[] {chat}); dbContextMock.CreateDbSetMock(x => x.ChatUsers); @@ -42,7 +44,6 @@ public async Task AddUserToChat_UserAdded( ChatUser expectedChatUser = fixture.Build() .With(chatUser => chatUser.Chat, chat) - // .With(chatUser => chatUser.User, user) .With(chatUser => chatUser.ChatId, chat.Id) .With(chatUser => chatUser.MessengerUserId, user.Id) .Create(); @@ -58,6 +59,8 @@ public async Task DeleteUserFromChat_UsersListEmpty( var users = new List {user}; var mockUserManager = MockUserManager, MessengerUser>(users); + mockUserManager.Setup( userManager => userManager.FindByIdAsync($"{user.Id}")).ReturnsAsync(user); + var dbContextMock = new DbContextMock(); dbContextMock.CreateDbSetMock(x => x.Chats, new[] {chat}); dbContextMock.CreateDbSetMock(x => x.ChatUsers); From 15b9474beef526e70091696750bd5535a8a8057a Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 17:28:01 +0300 Subject: [PATCH 33/45] feat: validTo prop added into AuthenticateByJwt endpoint response --- .../Authenticate/Handlers/AuthenticateQueryHandler.cs | 11 +++++++---- .../Authenticate/Queries/AuthenticateByJwtRequest.cs | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs index 2e32883..3a8c586 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Handlers/AuthenticateQueryHandler.cs @@ -18,7 +18,7 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Handlers; public class AuthenticateQueryHandler : IQueryHandler, - IQueryHandler, + IQueryHandler, IQueryHandler> { private const string NameType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"; @@ -58,13 +58,13 @@ public async Task Handle(LoginRequest request, CancellationTok return GetToken(authClaims); } - public async Task Handle(AuthenticateByJwtRequest request, CancellationToken cancellationToken) + public async Task Handle(AuthenticateByJwtRequest request, CancellationToken cancellationToken) { var token = new JwtSecurityToken(request.jwtToken); string userNickName = token.Claims.First(x => x.Type == NameType).Value; var identityUser = await _userManager.FindByNameAsync(userNickName); - return identityUser.Id; + return new AuthenticateResponse(identityUser.Id, token.ValidTo); } public async Task> Handle(GetUsersRequest request, CancellationToken cancellationToken) @@ -76,10 +76,13 @@ private JwtSecurityToken GetToken(List authClaims) { var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"])); + var time = DateTime.UtcNow.AddHours(int.Parse(_configuration["JWT:Expires"])); + var token = new JwtSecurityToken( issuer: _configuration["JWT:ValidIssuer"], audience: _configuration["JWT:ValidAudience"], - expires: DateTime.Now.AddHours(int.Parse(_configuration["JWT:Expires"])), + notBefore: DateTime.UtcNow, + expires: DateTime.UtcNow.AddHours(int.Parse(_configuration["JWT:Expires"])), claims: authClaims, signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)); diff --git a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs index 05647a0..6b24e23 100644 --- a/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs +++ b/Source/Application/Do-Svyazi.User.Application/CQRS/Authenticate/Queries/AuthenticateByJwtRequest.cs @@ -3,4 +3,6 @@ namespace Do_Svyazi.User.Application.CQRS.Authenticate.Queries; public record AuthenticateByJwtRequest(string jwtToken) - : IRequest; \ No newline at end of file + : IRequest; + +public record AuthenticateResponse(Guid userId, DateTime validTo); \ No newline at end of file From 4494245cd11c3bd3b0d5e3f4b284cbeaec3c087e Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 17:39:16 +0300 Subject: [PATCH 34/45] chore: ApiClients updated --- .../Backend/Do-Svyazi.User.Client.cs | 822 +++++++++- .../Backend/Do-Svyazi.User.Contracts.cs | 577 ++++--- .../Frontend/do-svyazi.user.clients.ts | 1399 +++++++++++------ .../openApiContracts.json | 868 +++++++--- 4 files changed, 2564 insertions(+), 1102 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs index 92af68b..a12f3d9 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs @@ -55,20 +55,108 @@ public string BaseUrl partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); /// A server side error occurred. - public virtual System.Threading.Tasks.Task LoginAsync(Login model) + public virtual System.Threading.Tasks.Task> GetAllAsync() + { + return GetAllAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken) + { + var urlBuilder_ = new System.Text.StringBuilder(); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/GetAll"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// A server side error occurred. + public virtual System.Threading.Tasks.Task LoginAsync(LoginRequest model) { return LoginAsync(model, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task LoginAsync(Login model, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest model, System.Threading.CancellationToken cancellationToken) { if (model == null) throw new System.ArgumentNullException("model"); var urlBuilder_ = new System.Text.StringBuilder(); - urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/login"); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/Login"); var client_ = _httpClient; var disposeClient_ = false; @@ -80,7 +168,6 @@ public virtual async System.Threading.Tasks.Task LoginAsync(Login content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); PrepareRequest(client_, request_, urlBuilder_); @@ -103,12 +190,25 @@ public virtual async System.Threading.Tasks.Task LoginAsync(Login ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; - if (status_ == 200 || status_ == 206) + if (status_ == 200) { - var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false); - var fileResponse_ = new FileResponse(status_, headers_, responseStream_, null, response_); - disposeClient_ = false; disposeResponse_ = false; // response and client are disposed by FileResponse - return fileResponse_; + return; + } + else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -131,20 +231,20 @@ public virtual async System.Threading.Tasks.Task LoginAsync(Login } /// A server side error occurred. - public virtual System.Threading.Tasks.Task RegisterAsync(Register model) + public virtual System.Threading.Tasks.Task RegisterAsync(RegisterCommand model) { return RegisterAsync(model, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task RegisterAsync(Register model, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand model, System.Threading.CancellationToken cancellationToken) { if (model == null) throw new System.ArgumentNullException("model"); var urlBuilder_ = new System.Text.StringBuilder(); - urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/register"); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/Register"); var client_ = _httpClient; var disposeClient_ = false; @@ -156,7 +256,6 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(Reg content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); PrepareRequest(client_, request_, urlBuilder_); @@ -179,12 +278,30 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(Reg ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; - if (status_ == 200 || status_ == 206) + if (status_ == 200) { - var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false); - var fileResponse_ = new FileResponse(status_, headers_, responseStream_, null, response_); - disposeClient_ = false; disposeResponse_ = false; // response and client are disposed by FileResponse - return fileResponse_; + return; + } + else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; } else { @@ -207,20 +324,112 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(Reg } /// A server side error occurred. - public virtual System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmin model) + public virtual System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken) + { + return AuthenticateByJwtAsync(jwtToken, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken, System.Threading.CancellationToken cancellationToken) + { + var urlBuilder_ = new System.Text.StringBuilder(); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/AuthenticateByJwt"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + + if (jwtToken == null) + throw new System.ArgumentNullException("jwtToken"); + request_.Headers.TryAddWithoutValidation("jwtToken", ConvertToString(jwtToken, System.Globalization.CultureInfo.InvariantCulture)); + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// A server side error occurred. + public virtual System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model) { return RegisterAdminAsync(model, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmin model, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model, System.Threading.CancellationToken cancellationToken) { if (model == null) throw new System.ArgumentNullException("model"); var urlBuilder_ = new System.Text.StringBuilder(); - urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/register-admin"); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/RegisterAdmin"); var client_ = _httpClient; var disposeClient_ = false; @@ -232,7 +441,6 @@ public virtual async System.Threading.Tasks.Task RegisterAdminAsyn content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); PrepareRequest(client_, request_, urlBuilder_); @@ -255,12 +463,30 @@ public virtual async System.Threading.Tasks.Task RegisterAdminAsyn ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; - if (status_ == 200 || status_ == 206) + if (status_ == 200) + { + return; + } + else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) { - var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false); - var fileResponse_ = new FileResponse(status_, headers_, responseStream_, null, response_); - disposeClient_ = false; disposeResponse_ = false; // response and client are disposed by FileResponse - return fileResponse_; + return; } else { @@ -473,6 +699,22 @@ public string BaseUrl return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -550,6 +792,22 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -627,6 +885,22 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -647,14 +921,14 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId) + public virtual System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId) { return GetUsersByChatIdAsync(chatId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken) { if (chatId == null) throw new System.ArgumentNullException("chatId"); @@ -696,7 +970,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -704,6 +978,22 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -724,14 +1014,14 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddChannelAsync(AddChannel addChannelCommand) + public virtual System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand) { return AddChannelAsync(addChannelCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannel addChannelCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand, System.Threading.CancellationToken cancellationToken) { if (addChannelCommand == null) throw new System.ArgumentNullException("addChannelCommand"); @@ -776,6 +1066,27 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannel addC return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 201) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -796,14 +1107,14 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannel addC } /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChat addGroupChatCommand) + public virtual System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand) { return AddGroupChatAsync(addGroupChatCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChat addGroupChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand, System.Threading.CancellationToken cancellationToken) { if (addGroupChatCommand == null) throw new System.ArgumentNullException("addGroupChatCommand"); @@ -848,6 +1159,27 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChat return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 201) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -868,14 +1200,14 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChat } /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChat addPersonalChatCommand) + public virtual System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand) { return AddPersonalChatAsync(addPersonalChatCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChat addPersonalChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand, System.Threading.CancellationToken cancellationToken) { if (addPersonalChatCommand == null) throw new System.ArgumentNullException("addPersonalChatCommand"); @@ -920,6 +1252,27 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 201) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -940,14 +1293,14 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona } /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessages addSavedMessagesCommand) + public virtual System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand) { return AddSavedMessagesAsync(addSavedMessagesCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessages addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken) { if (addSavedMessagesCommand == null) throw new System.ArgumentNullException("addSavedMessagesCommand"); @@ -992,6 +1345,27 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 201) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1012,14 +1386,14 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM } /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChat addUserToChatCommand) + public virtual System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand) { return AddUserToChatAsync(addUserToChatCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChat addUserToChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand, System.Threading.CancellationToken cancellationToken) { if (addUserToChatCommand == null) throw new System.ArgumentNullException("addUserToChatCommand"); @@ -1064,6 +1438,27 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1084,14 +1479,14 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha } /// A server side error occurred. - public virtual System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChat deleteUserFromChatCommand) + public virtual System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand) { return DeleteUserFromChatAsync(deleteUserFromChatCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChat deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken) { if (deleteUserFromChatCommand == null) throw new System.ArgumentNullException("deleteUserFromChatCommand"); @@ -1136,6 +1531,27 @@ public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteU return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1355,6 +1771,22 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1375,17 +1807,17 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S } /// A server side error occurred. - public virtual System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChat createRoleForChat) + public virtual System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand) { - return CreateRoleForChatAsync(createRoleForChat, System.Threading.CancellationToken.None); + return CreateRoleForChatAsync(createRoleForChatCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChat createRoleForChat, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand, System.Threading.CancellationToken cancellationToken) { - if (createRoleForChat == null) - throw new System.ArgumentNullException("createRoleForChat"); + if (createRoleForChatCommand == null) + throw new System.ArgumentNullException("createRoleForChatCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/CreateRoleForChat"); @@ -1396,7 +1828,7 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(createRoleForChat, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(createRoleForChatCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1427,6 +1859,27 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1447,17 +1900,17 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo } /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserById changeRoleForUserById) + public virtual System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand) { - return ChangeRoleForUserByIdAsync(changeRoleForUserById, System.Threading.CancellationToken.None); + return ChangeRoleForUserByIdAsync(changeRoleForUserByIdCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserById changeRoleForUserById, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, System.Threading.CancellationToken cancellationToken) { - if (changeRoleForUserById == null) - throw new System.ArgumentNullException("changeRoleForUserById"); + if (changeRoleForUserByIdCommand == null) + throw new System.ArgumentNullException("changeRoleForUserByIdCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/ChangeRoleForUserById"); @@ -1468,7 +1921,7 @@ public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(Chan { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeRoleForUserById, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeRoleForUserByIdCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1499,6 +1952,27 @@ public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(Chan return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1709,6 +2183,22 @@ public string BaseUrl return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1729,14 +2219,14 @@ public string BaseUrl } /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetUserAsync(System.Guid userId) + public virtual System.Threading.Tasks.Task GetUserAsync(System.Guid userId) { return GetUserAsync(userId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken) { if (userId == null) throw new System.ArgumentNullException("userId"); @@ -1778,7 +2268,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync(Sys var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -1786,6 +2276,22 @@ public virtual async System.Threading.Tasks.Task GetUserAsync(Sys return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1863,6 +2369,22 @@ public virtual async System.Threading.Tasks.Task GetUserAsync(Sys return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1940,6 +2462,22 @@ public virtual async System.Threading.Tasks.Task GetUserAsync(Sys return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -1960,17 +2498,17 @@ public virtual async System.Threading.Tasks.Task GetUserAsync(Sys } /// A server side error occurred. - public virtual System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameById setUserNickNameById) + public virtual System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand) { - return SetNickNameByIdAsync(setUserNickNameById, System.Threading.CancellationToken.None); + return SetNickNameByIdAsync(setUserNickNameByIdCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameById setUserNickNameById, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand, System.Threading.CancellationToken cancellationToken) { - if (setUserNickNameById == null) - throw new System.ArgumentNullException("setUserNickNameById"); + if (setUserNickNameByIdCommand == null) + throw new System.ArgumentNullException("setUserNickNameByIdCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/SetNickNameById"); @@ -1981,7 +2519,7 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(setUserNickNameById, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(setUserNickNameByIdCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2012,6 +2550,27 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -2032,17 +2591,17 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic } /// A server side error occurred. - public virtual System.Threading.Tasks.Task DeleteUserAsync(DeleteUser deleteUser) + public virtual System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand) { - return DeleteUserAsync(deleteUser, System.Threading.CancellationToken.None); + return DeleteUserAsync(deleteUserCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser deleteUser, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand, System.Threading.CancellationToken cancellationToken) { - if (deleteUser == null) - throw new System.ArgumentNullException("deleteUser"); + if (deleteUserCommand == null) + throw new System.ArgumentNullException("deleteUserCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/DeleteUser"); @@ -2053,7 +2612,7 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser dele { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(deleteUser, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(deleteUserCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2084,6 +2643,27 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser dele return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -2104,17 +2684,17 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser dele } /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddUserAsync(AddUser addUser) + public virtual System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand) { - return AddUserAsync(addUser, System.Threading.CancellationToken.None); + return AddUserAsync(addUserCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddUserAsync(AddUser addUser, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand, System.Threading.CancellationToken cancellationToken) { - if (addUser == null) - throw new System.ArgumentNullException("addUser"); + if (addUserCommand == null) + throw new System.ArgumentNullException("addUserCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/AddUser"); @@ -2125,7 +2705,7 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser dele { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addUser, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addUserCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2162,6 +2742,32 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser dele return objectResponse_.Object; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 201) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -2182,17 +2788,17 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUser dele } /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionById changeUserDescriptionById) + public virtual System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand) { - return ChangeDescriptionAsync(changeUserDescriptionById, System.Threading.CancellationToken.None); + return ChangeDescriptionAsync(changeUserDescriptionByIdCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionById changeUserDescriptionById, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, System.Threading.CancellationToken cancellationToken) { - if (changeUserDescriptionById == null) - throw new System.ArgumentNullException("changeUserDescriptionById"); + if (changeUserDescriptionByIdCommand == null) + throw new System.ArgumentNullException("changeUserDescriptionByIdCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/ChangeDescription"); @@ -2203,7 +2809,7 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserDescriptionById, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserDescriptionByIdCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2234,6 +2840,27 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); @@ -2254,17 +2881,17 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs } /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameById changeUserNameById) + public virtual System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand) { - return ChangeNameAsync(changeUserNameById, System.Threading.CancellationToken.None); + return ChangeNameAsync(changeUserNameByIdCommand, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameById changeUserNameById, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand, System.Threading.CancellationToken cancellationToken) { - if (changeUserNameById == null) - throw new System.ArgumentNullException("changeUserNameById"); + if (changeUserNameByIdCommand == null) + throw new System.ArgumentNullException("changeUserNameByIdCommand"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/ChangeName"); @@ -2275,7 +2902,7 @@ public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameB { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserNameById, _settings.Value)); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserNameByIdCommand, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2306,6 +2933,27 @@ public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameB return; } else + if (status_ == 401) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 500) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + } + else + if (status_ == 204) + { + return; + } + else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new Do_Svyazi_User_ApiClient_Exception("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs index db8a73c..6133af7 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs @@ -21,25 +21,39 @@ namespace Do_Svyazi.User.Web.ApiClient.Contracts public partial interface IAuthenticateClient { /// A server side error occurred. - System.Threading.Tasks.Task LoginAsync(Login model); + System.Threading.Tasks.Task> GetAllAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task LoginAsync(Login model, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task RegisterAsync(Register model); + System.Threading.Tasks.Task LoginAsync(LoginRequest model); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task RegisterAsync(Register model, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task LoginAsync(LoginRequest model, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmin model); + System.Threading.Tasks.Task RegisterAsync(RegisterCommand model); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmin model, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task RegisterAsync(RegisterCommand model, System.Threading.CancellationToken cancellationToken); + + /// A server side error occurred. + System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// A server side error occurred. + System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken, System.Threading.CancellationToken cancellationToken); + + /// A server side error occurred. + System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// A server side error occurred. + System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model, System.Threading.CancellationToken cancellationToken); } @@ -68,53 +82,53 @@ public partial interface IChatClient System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId); + System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task AddChannelAsync(AddChannel addChannelCommand); + System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task AddChannelAsync(AddChannel addChannelCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChat addGroupChatCommand); + System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChat addGroupChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChat addPersonalChatCommand); + System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChat addPersonalChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessages addSavedMessagesCommand); + System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessages addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChat addUserToChatCommand); + System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChat addUserToChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChat deleteUserFromChatCommand); + System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChat deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken); } @@ -129,18 +143,18 @@ public partial interface IRolesClient System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChat createRoleForChat); + System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChat createRoleForChat, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserById changeRoleForUserById); + System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserById changeRoleForUserById, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, System.Threading.CancellationToken cancellationToken); } @@ -155,11 +169,11 @@ public partial interface IUserClient System.Threading.Tasks.Task> GetUsersAsync(System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task GetUserAsync(System.Guid userId); + System.Threading.Tasks.Task GetUserAsync(System.Guid userId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId); @@ -176,47 +190,50 @@ public partial interface IUserClient System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameById setUserNickNameById); + System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameById setUserNickNameById, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserAsync(DeleteUser deleteUser); + System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserAsync(DeleteUser deleteUser, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task AddUserAsync(AddUser addUser); + System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task AddUserAsync(AddUser addUser, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionById changeUserDescriptionById); + System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionById changeUserDescriptionById, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, System.Threading.CancellationToken cancellationToken); /// A server side error occurred. - System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameById changeUserNameById); + System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A server side error occurred. - System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameById changeUserNameById, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand, System.Threading.CancellationToken cancellationToken); } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class Login + public partial class MessengerUser : IdentityUserOfGuid { - [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public LoginModel Model { get; set; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } public string ToJson() { @@ -224,47 +241,62 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static Login FromJson(string data) + public static MessengerUser FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class LoginModel + public partial class IdentityUserOfGuid { [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid Id { get; set; } - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.Always)] - public string NickName { get; set; } + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string UserName { get; set; } - [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] - public string Password { get; set; } + [Newtonsoft.Json.JsonProperty("normalizedUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string NormalizedUserName { get; set; } - public string ToJson() - { + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Email { get; set; } - return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + [Newtonsoft.Json.JsonProperty("normalizedEmail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string NormalizedEmail { get; set; } - } - public static LoginModel FromJson(string data) - { + [Newtonsoft.Json.JsonProperty("emailConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool EmailConfirmed { get; set; } - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + [Newtonsoft.Json.JsonProperty("passwordHash", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PasswordHash { get; set; } - } + [Newtonsoft.Json.JsonProperty("securityStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string SecurityStamp { get; set; } - } + [Newtonsoft.Json.JsonProperty("concurrencyStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ConcurrencyStamp { get; set; } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class Register - { - [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RegisterModel Model { get; set; } + [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PhoneNumber { get; set; } + + [Newtonsoft.Json.JsonProperty("phoneNumberConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool PhoneNumberConfirmed { get; set; } + + [Newtonsoft.Json.JsonProperty("twoFactorEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool TwoFactorEnabled { get; set; } + + [Newtonsoft.Json.JsonProperty("lockoutEnd", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTime? LockoutEnd { get; set; } + + [Newtonsoft.Json.JsonProperty("lockoutEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool LockoutEnabled { get; set; } + + [Newtonsoft.Json.JsonProperty("accessFailedCount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int AccessFailedCount { get; set; } public string ToJson() { @@ -272,86 +304,65 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static Register FromJson(string data) + public static IdentityUserOfGuid FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterModel + public partial class ProblemDetails { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Always)] - public string Name { get; set; } - - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.Always)] - public string NickName { get; set; } + [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Type { get; set; } - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] - public string Email { get; set; } + [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Title { get; set; } - [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] - public string Password { get; set; } + [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int? Status { get; set; } - public string ToJson() - { + [Newtonsoft.Json.JsonProperty("detail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Detail { get; set; } - return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + [Newtonsoft.Json.JsonProperty("instance", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Instance { get; set; } - } - public static RegisterModel FromJson(string data) - { + [Newtonsoft.Json.JsonProperty("extensions", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.Generic.Dictionary Extensions { get; set; } - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + private System.Collections.Generic.IDictionary _additionalProperties = new System.Collections.Generic.Dictionary(); + [Newtonsoft.Json.JsonExtensionData] + public System.Collections.Generic.IDictionary AdditionalProperties + { + get { return _additionalProperties; } + set { _additionalProperties = value; } } - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterAdmin - { - [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RegisterModel Model { get; set; } - public string ToJson() { return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterAdmin FromJson(string data) + public static ProblemDetails FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerChatDto + public partial class LoginRequest { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } - - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } - - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } - - [Newtonsoft.Json.JsonProperty("creator", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public MessengerUserDto Creator { get; set; } - - [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Users { get; set; } - - [Newtonsoft.Json.JsonProperty("roles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Roles { get; set; } + [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public LoginModel Model { get; set; } public string ToJson() { @@ -359,29 +370,26 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerChatDto FromJson(string data) + public static LoginRequest FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerUserDto + public partial class LoginModel { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } - - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string UserName { get; set; } - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string NickName { get; set; } + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Email { get; set; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + public string Password { get; set; } public string ToJson() { @@ -389,53 +397,20 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerUserDto FromJson(string data) + public static LoginModel FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RoleDto + public partial class RegisterCommand { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } - - [Newtonsoft.Json.JsonProperty("canEditMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanEditMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canDeleteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canWriteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanWriteMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canReadMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanReadMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canAddUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanAddUsers { get; set; } - - [Newtonsoft.Json.JsonProperty("canDeleteUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteUsers { get; set; } - - [Newtonsoft.Json.JsonProperty("canPinMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanPinMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canSeeChannelMembers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanSeeChannelMembers { get; set; } - - [Newtonsoft.Json.JsonProperty("canInviteOtherUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanInviteOtherUsers { get; set; } - - [Newtonsoft.Json.JsonProperty("canEditChannelDescription", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanEditChannelDescription { get; set; } - - [Newtonsoft.Json.JsonProperty("canDeleteChat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteChat { get; set; } + [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RegisterModel Model { get; set; } public string ToJson() { @@ -443,47 +418,32 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RoleDto FromJson(string data) + public static RegisterCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public enum ActionOption - { - - Unavailable = 0, - - Enabled = 1, - - Disabled = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChatUser + public partial class RegisterModel { - [Newtonsoft.Json.JsonProperty("user", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public MessengerUser User { get; set; } + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Always)] + public string UserName { get; set; } - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } - - [Newtonsoft.Json.JsonProperty("messengerUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid MessengerUserId { get; set; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; set; } - [Newtonsoft.Json.JsonProperty("chat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public Chat Chat { get; set; } + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] + public string Email { get; set; } - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; set; } + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + public string Password { get; set; } - [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public Role Role { get; set; } + [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PhoneNumber { get; set; } public string ToJson() { @@ -491,32 +451,20 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChatUser FromJson(string data) + public static RegisterModel FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerUser + public partial class RegisterAdminCommand { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } - - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } - - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string NickName { get; set; } - - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } - - [Newtonsoft.Json.JsonProperty("chats", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Chats { get; set; } + [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RegisterModel Model { get; set; } public string ToJson() { @@ -524,41 +472,32 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerUser FromJson(string data) + public static RegisterAdminCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public abstract partial class Chat + public partial class MessengerChatDto { [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid Id { get; set; } - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Name { get; set; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Description { get; set; } - [Newtonsoft.Json.JsonProperty("creator", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public MessengerUser Creator { get; set; } - - [Newtonsoft.Json.JsonProperty("creatorId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid CreatorId { get; set; } - - [Newtonsoft.Json.JsonProperty("maxUsersAmount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int MaxUsersAmount { get; set; } - [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Users { get; set; } + public System.Collections.ObjectModel.ObservableCollection Users { get; set; } [Newtonsoft.Json.JsonProperty("roles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Roles { get; set; } + public System.Collections.ObjectModel.ObservableCollection Roles { get; set; } public string ToJson() { @@ -566,24 +505,18 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static Chat FromJson(string data) + public static MessengerChatDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class Role + public partial class RoleDto { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } - - [Newtonsoft.Json.JsonProperty("chat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public Chat Chat { get; set; } - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Name { get; set; } @@ -626,17 +559,56 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static Role FromJson(string data) + public static RoleDto FromJson(string data) + { + + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public enum ActionOption + { + + Unavailable = 0, + + Enabled = 1, + + Disabled = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChatUserDto + { + [Newtonsoft.Json.JsonProperty("chatUserName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ChatUserName { get; set; } + + [Newtonsoft.Json.JsonProperty("messengerUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid MessengerUserId { get; set; } + + [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDto Role { get; set; } + + public string ToJson() + { + + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + + } + public static ChatUserDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddChannel + public partial class AddChannelCommand { [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid AdminId { get; set; } @@ -653,17 +625,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddChannel FromJson(string data) + public static AddChannelCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddGroupChat + public partial class AddGroupChatCommand { [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid AdminId { get; set; } @@ -680,17 +652,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddGroupChat FromJson(string data) + public static AddGroupChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddPersonalChat + public partial class AddPersonalChatCommand { [Newtonsoft.Json.JsonProperty("firstUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid FirstUserId { get; set; } @@ -710,17 +682,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddPersonalChat FromJson(string data) + public static AddPersonalChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddSavedMessages + public partial class AddSavedMessagesCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -737,17 +709,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddSavedMessages FromJson(string data) + public static AddSavedMessagesCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddUserToChat + public partial class AddUserToChatCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -761,17 +733,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddUserToChat FromJson(string data) + public static AddUserToChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class DeleteUserFromChat + public partial class DeleteUserFromChatCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -785,17 +757,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static DeleteUserFromChat FromJson(string data) + public static DeleteUserFromChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class CreateRoleForChat + public partial class CreateRoleForChatCommand { [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public RoleDto Role { get; set; } @@ -809,17 +781,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static CreateRoleForChat FromJson(string data) + public static CreateRoleForChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeRoleForUserById + public partial class ChangeRoleForUserByIdCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -836,23 +808,53 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeRoleForUserById FromJson(string data) + public static ChangeRoleForUserByIdCommand FromJson(string data) + { + + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class MessengerUserDto + { + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; set; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; set; } + + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string UserName { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + public string ToJson() + { + + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + + } + public static MessengerUserDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class SetUserNickNameById + public partial class SetUserNickNameByIdCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string NickName { get; set; } + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string UserName { get; set; } public string ToJson() { @@ -860,17 +862,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static SetUserNickNameById FromJson(string data) + public static SetUserNickNameByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class DeleteUser + public partial class DeleteUserCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -881,17 +883,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static DeleteUser FromJson(string data) + public static DeleteUserCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddUser + public partial class AddUserCommand { [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Name { get; set; } @@ -908,17 +910,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddUser FromJson(string data) + public static AddUserCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeUserDescriptionById + public partial class ChangeUserDescriptionByIdCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -932,17 +934,17 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeUserDescriptionById FromJson(string data) + public static ChangeUserDescriptionByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeUserNameById + public partial class ChangeUserNameByIdCommand { [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; set; } @@ -956,50 +958,15 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeUserNameById FromJson(string data) + public static ChangeUserNameByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class FileResponse : System.IDisposable - { - private System.IDisposable _client; - private System.IDisposable _response; - - public int StatusCode { get; private set; } - - public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } - - public System.IO.Stream Stream { get; private set; } - - public bool IsPartial - { - get { return StatusCode == 206; } - } - - public FileResponse(int statusCode, System.Collections.Generic.IReadOnlyDictionary> headers, System.IO.Stream stream, System.IDisposable client, System.IDisposable response) - { - StatusCode = statusCode; - Headers = headers; - Stream = stream; - _client = client; - _response = response; - } - - public void Dispose() - { - Stream.Dispose(); - if (_response != null) - _response.Dispose(); - if (_client != null) - _client.Dispose(); - } - } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts index b6cde42..89de025 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts @@ -14,9 +14,11 @@ import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, CancelToken } fr import * as moment from 'moment'; export interface IAuthenticateClient { - login(model: Login): Promise; - register(model: Register): Promise; - registerAdmin(model: RegisterAdmin): Promise; + getAll(): Promise; + login(model: LoginRequest): Promise; + register(model: RegisterCommand): Promise; + authenticateByJwt(jwtToken: string | null): Promise; + registerAdmin(model: RegisterAdminCommand): Promise; } export class AuthenticateClient implements IAuthenticateClient { @@ -32,20 +34,85 @@ export class AuthenticateClient implements IAuthenticateClient { } - login(model: Login , cancelToken?: CancelToken | undefined): Promise { - let url_ = this.baseUrl + "/api/Authenticate/login"; + getAll( cancelToken?: CancelToken | undefined): Promise { + let url_ = this.baseUrl + "/api/Authenticate/GetAll"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: AxiosRequestConfig = { + method: "GET", + url: url_, + headers: { + "Accept": "application/json" + }, + cancelToken + }; + + return this.instance.request(options_).catch((_error: any) => { + if (isAxiosError(_error) && _error.response) { + return _error.response; + } else { + throw _error; + } + }).then((_response: AxiosResponse) => { + return this.processGetAll(_response); + }); + } + + protected processGetAll(response: AxiosResponse): Promise { + const status = response.status; + let _headers: any = {}; + if (response.headers && typeof response.headers === "object") { + for (let k in response.headers) { + if (response.headers.hasOwnProperty(k)) { + _headers[k] = response.headers[k]; + } + } + } + let _mappings: { source: any, target: any }[] = []; + if (status === 200) { + const _responseText = response.data; + let result200: any = null; + let resultData200 = _responseText; + if (Array.isArray(resultData200)) { + result200 = [] as any; + for (let item of resultData200) + result200!.push(MessengerUser.fromJS(item, _mappings)); + } + else { + result200 = null; + } + return Promise.resolve(result200); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status !== 200 && status !== 204) { + const _responseText = response.data; + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + } + return Promise.resolve(null as any); + } + + login(model: LoginRequest , cancelToken?: CancelToken | undefined): Promise { + let url_ = this.baseUrl + "/api/Authenticate/Login"; url_ = url_.replace(/[?&]$/, ""); const content_ = JSON.stringify(model); let options_: AxiosRequestConfig = { data: content_, - responseType: "blob", method: "POST", url: url_, headers: { "Content-Type": "application/json", - "Accept": "application/octet-stream" }, cancelToken }; @@ -61,7 +128,7 @@ export class AuthenticateClient implements IAuthenticateClient { }); } - protected processLogin(response: AxiosResponse): Promise { + protected processLogin(response: AxiosResponse): Promise { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { @@ -71,32 +138,41 @@ export class AuthenticateClient implements IAuthenticateClient { } } } - if (status === 200 || status === 206) { - const contentDisposition = response.headers ? response.headers["content-disposition"] : undefined; - const fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined; - const fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined; - return Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers }); + let _mappings: { source: any, target: any }[] = []; + if (status === 200) { + const _responseText = response.data; + return Promise.resolve(null as any); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } - return Promise.resolve(null as any); + return Promise.resolve(null as any); } - register(model: Register , cancelToken?: CancelToken | undefined): Promise { - let url_ = this.baseUrl + "/api/Authenticate/register"; + register(model: RegisterCommand , cancelToken?: CancelToken | undefined): Promise { + let url_ = this.baseUrl + "/api/Authenticate/Register"; url_ = url_.replace(/[?&]$/, ""); const content_ = JSON.stringify(model); let options_: AxiosRequestConfig = { data: content_, - responseType: "blob", method: "POST", url: url_, headers: { "Content-Type": "application/json", - "Accept": "application/octet-stream" }, cancelToken }; @@ -112,7 +188,7 @@ export class AuthenticateClient implements IAuthenticateClient { }); } - protected processRegister(response: AxiosResponse): Promise { + protected processRegister(response: AxiosResponse): Promise { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { @@ -122,32 +198,107 @@ export class AuthenticateClient implements IAuthenticateClient { } } } - if (status === 200 || status === 206) { - const contentDisposition = response.headers ? response.headers["content-disposition"] : undefined; - const fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined; - const fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined; - return Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers }); + let _mappings: { source: any, target: any }[] = []; + if (status === 200) { + const _responseText = response.data; + return Promise.resolve(null as any); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + + } else if (status !== 200 && status !== 204) { + const _responseText = response.data; + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + } + return Promise.resolve(null as any); + } + + authenticateByJwt(jwtToken: string | null , cancelToken?: CancelToken | undefined): Promise { + let url_ = this.baseUrl + "/api/Authenticate/AuthenticateByJwt"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: AxiosRequestConfig = { + method: "GET", + url: url_, + headers: { + "jwtToken": jwtToken !== undefined && jwtToken !== null ? "" + jwtToken : "", + "Accept": "application/json" + }, + cancelToken + }; + + return this.instance.request(options_).catch((_error: any) => { + if (isAxiosError(_error) && _error.response) { + return _error.response; + } else { + throw _error; + } + }).then((_response: AxiosResponse) => { + return this.processAuthenticateByJwt(_response); + }); + } + + protected processAuthenticateByJwt(response: AxiosResponse): Promise { + const status = response.status; + let _headers: any = {}; + if (response.headers && typeof response.headers === "object") { + for (let k in response.headers) { + if (response.headers.hasOwnProperty(k)) { + _headers[k] = response.headers[k]; + } + } + } + let _mappings: { source: any, target: any }[] = []; + if (status === 200) { + const _responseText = response.data; + let result200: any = null; + let resultData200 = _responseText; + result200 = resultData200 !== undefined ? resultData200 : null; + + return Promise.resolve(result200); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } - return Promise.resolve(null as any); + return Promise.resolve(null as any); } - registerAdmin(model: RegisterAdmin , cancelToken?: CancelToken | undefined): Promise { - let url_ = this.baseUrl + "/api/Authenticate/register-admin"; + registerAdmin(model: RegisterAdminCommand , cancelToken?: CancelToken | undefined): Promise { + let url_ = this.baseUrl + "/api/Authenticate/RegisterAdmin"; url_ = url_.replace(/[?&]$/, ""); const content_ = JSON.stringify(model); let options_: AxiosRequestConfig = { data: content_, - responseType: "blob", method: "POST", url: url_, headers: { "Content-Type": "application/json", - "Accept": "application/octet-stream" }, cancelToken }; @@ -163,7 +314,7 @@ export class AuthenticateClient implements IAuthenticateClient { }); } - protected processRegisterAdmin(response: AxiosResponse): Promise { + protected processRegisterAdmin(response: AxiosResponse): Promise { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { @@ -173,16 +324,31 @@ export class AuthenticateClient implements IAuthenticateClient { } } } - if (status === 200 || status === 206) { - const contentDisposition = response.headers ? response.headers["content-disposition"] : undefined; - const fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined; - const fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined; - return Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers }); + let _mappings: { source: any, target: any }[] = []; + if (status === 200) { + const _responseText = response.data; + return Promise.resolve(null as any); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } - return Promise.resolve(null as any); + return Promise.resolve(null as any); } } @@ -190,13 +356,13 @@ export interface IChatClient { getChats(): Promise; getChatById(chatId: string): Promise; getUserIdsByChatId(chatId: string): Promise; - getUsersByChatId(chatId: string): Promise; - addChannel(addChannelCommand: AddChannel): Promise; - addGroupChat(addGroupChatCommand: AddGroupChat): Promise; - addPersonalChat(addPersonalChatCommand: AddPersonalChat): Promise; - addSavedMessages(addSavedMessagesCommand: AddSavedMessages): Promise; - addUserToChat(addUserToChatCommand: AddUserToChat): Promise; - deleteUserFromChat(deleteUserFromChatCommand: DeleteUserFromChat): Promise; + getUsersByChatId(chatId: string): Promise; + addChannel(addChannelCommand: AddChannelCommand): Promise; + addGroupChat(addGroupChatCommand: AddGroupChatCommand): Promise; + addPersonalChat(addPersonalChatCommand: AddPersonalChatCommand): Promise; + addSavedMessages(addSavedMessagesCommand: AddSavedMessagesCommand): Promise; + addUserToChat(addUserToChatCommand: AddUserToChatCommand): Promise; + deleteUserFromChat(deleteUserFromChatCommand: DeleteUserFromChatCommand): Promise; } export class ChatClient implements IChatClient { @@ -261,6 +427,17 @@ export class ChatClient implements IChatClient { } return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -314,6 +491,17 @@ export class ChatClient implements IChatClient { result200 = MessengerChatDto.fromJS(resultData200, _mappings); return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -359,6 +547,7 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; let result200: any = null; @@ -373,6 +562,17 @@ export class ChatClient implements IChatClient { } return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -380,7 +580,7 @@ export class ChatClient implements IChatClient { return Promise.resolve(null as any); } - getUsersByChatId(chatId: string , cancelToken?: CancelToken | undefined): Promise { + getUsersByChatId(chatId: string , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/GetUsersByChatId?"; if (chatId === undefined || chatId === null) throw new Error("The parameter 'chatId' must be defined and cannot be null."); @@ -408,7 +608,7 @@ export class ChatClient implements IChatClient { }); } - protected processGetUsersByChatId(response: AxiosResponse): Promise { + protected processGetUsersByChatId(response: AxiosResponse): Promise { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { @@ -426,21 +626,32 @@ export class ChatClient implements IChatClient { if (Array.isArray(resultData200)) { result200 = [] as any; for (let item of resultData200) - result200!.push(ChatUser.fromJS(item, _mappings)); + result200!.push(ChatUserDto.fromJS(item, _mappings)); } else { result200 = null; } - return Promise.resolve(result200); + return Promise.resolve(result200); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } - return Promise.resolve(null as any); + return Promise.resolve(null as any); } - addChannel(addChannelCommand: AddChannel , cancelToken?: CancelToken | undefined): Promise { + addChannel(addChannelCommand: AddChannelCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/AddChannel"; url_ = url_.replace(/[?&]$/, ""); @@ -477,10 +688,26 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 201) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -488,7 +715,7 @@ export class ChatClient implements IChatClient { return Promise.resolve(null as any); } - addGroupChat(addGroupChatCommand: AddGroupChat , cancelToken?: CancelToken | undefined): Promise { + addGroupChat(addGroupChatCommand: AddGroupChatCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/AddGroupChat"; url_ = url_.replace(/[?&]$/, ""); @@ -525,10 +752,26 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 201) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -536,7 +779,7 @@ export class ChatClient implements IChatClient { return Promise.resolve(null as any); } - addPersonalChat(addPersonalChatCommand: AddPersonalChat , cancelToken?: CancelToken | undefined): Promise { + addPersonalChat(addPersonalChatCommand: AddPersonalChatCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/AddPersonalChat"; url_ = url_.replace(/[?&]$/, ""); @@ -573,10 +816,26 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 201) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -584,7 +843,7 @@ export class ChatClient implements IChatClient { return Promise.resolve(null as any); } - addSavedMessages(addSavedMessagesCommand: AddSavedMessages , cancelToken?: CancelToken | undefined): Promise { + addSavedMessages(addSavedMessagesCommand: AddSavedMessagesCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/AddSavedMessages"; url_ = url_.replace(/[?&]$/, ""); @@ -621,10 +880,26 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 201) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -632,7 +907,7 @@ export class ChatClient implements IChatClient { return Promise.resolve(null as any); } - addUserToChat(addUserToChatCommand: AddUserToChat , cancelToken?: CancelToken | undefined): Promise { + addUserToChat(addUserToChatCommand: AddUserToChatCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/AddUserToChat"; url_ = url_.replace(/[?&]$/, ""); @@ -669,10 +944,26 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -680,7 +971,7 @@ export class ChatClient implements IChatClient { return Promise.resolve(null as any); } - deleteUserFromChat(deleteUserFromChatCommand: DeleteUserFromChat , cancelToken?: CancelToken | undefined): Promise { + deleteUserFromChat(deleteUserFromChatCommand: DeleteUserFromChatCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Chat/DeleteUserFromChat"; url_ = url_.replace(/[?&]$/, ""); @@ -717,10 +1008,26 @@ export class ChatClient implements IChatClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -731,8 +1038,8 @@ export class ChatClient implements IChatClient { export interface IRolesClient { getRoleByUserId(userId: string, chatId: string): Promise; - createRoleForChat(createRoleForChat: CreateRoleForChat): Promise; - changeRoleForUserById(changeRoleForUserById: ChangeRoleForUserById): Promise; + createRoleForChat(createRoleForChatCommand: CreateRoleForChatCommand): Promise; + changeRoleForUserById(changeRoleForUserByIdCommand: ChangeRoleForUserByIdCommand): Promise; } export class RolesClient implements IRolesClient { @@ -798,6 +1105,17 @@ export class RolesClient implements IRolesClient { result200 = RoleDto.fromJS(resultData200, _mappings); return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -805,11 +1123,11 @@ export class RolesClient implements IRolesClient { return Promise.resolve(null as any); } - createRoleForChat(createRoleForChat: CreateRoleForChat , cancelToken?: CancelToken | undefined): Promise { + createRoleForChat(createRoleForChatCommand: CreateRoleForChatCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Roles/CreateRoleForChat"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(createRoleForChat); + const content_ = JSON.stringify(createRoleForChatCommand); let options_: AxiosRequestConfig = { data: content_, @@ -842,10 +1160,26 @@ export class RolesClient implements IRolesClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -853,11 +1187,11 @@ export class RolesClient implements IRolesClient { return Promise.resolve(null as any); } - changeRoleForUserById(changeRoleForUserById: ChangeRoleForUserById , cancelToken?: CancelToken | undefined): Promise { + changeRoleForUserById(changeRoleForUserByIdCommand: ChangeRoleForUserByIdCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Roles/ChangeRoleForUserById"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(changeRoleForUserById); + const content_ = JSON.stringify(changeRoleForUserByIdCommand); let options_: AxiosRequestConfig = { data: content_, @@ -890,10 +1224,26 @@ export class RolesClient implements IRolesClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -904,14 +1254,14 @@ export class RolesClient implements IRolesClient { export interface IUserClient { getAll(): Promise; - getUser(userId: string): Promise; + getUser(userId: string): Promise; getAllChatsByUserId(userId: string): Promise; getAllChatsIdsByUserId(userId: string): Promise; - setNickNameById(setUserNickNameById: SetUserNickNameById): Promise; - deleteUser(deleteUser: DeleteUser): Promise; - addUser(addUser: AddUser): Promise; - changeDescription(changeUserDescriptionById: ChangeUserDescriptionById): Promise; - changeName(changeUserNameById: ChangeUserNameById): Promise; + setNickNameById(setUserNickNameByIdCommand: SetUserNickNameByIdCommand): Promise; + deleteUser(deleteUserCommand: DeleteUserCommand): Promise; + addUser(addUserCommand: AddUserCommand): Promise; + changeDescription(changeUserDescriptionByIdCommand: ChangeUserDescriptionByIdCommand): Promise; + changeName(changeUserNameByIdCommand: ChangeUserNameByIdCommand): Promise; } export class UserClient implements IUserClient { @@ -976,6 +1326,17 @@ export class UserClient implements IUserClient { } return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -983,7 +1344,7 @@ export class UserClient implements IUserClient { return Promise.resolve(null as any); } - getUser(userId: string , cancelToken?: CancelToken | undefined): Promise { + getUser(userId: string , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/User/GetUser?"; if (userId === undefined || userId === null) throw new Error("The parameter 'userId' must be defined and cannot be null."); @@ -1011,7 +1372,7 @@ export class UserClient implements IUserClient { }); } - protected processGetUser(response: AxiosResponse): Promise { + protected processGetUser(response: AxiosResponse): Promise { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { @@ -1026,14 +1387,25 @@ export class UserClient implements IUserClient { const _responseText = response.data; let result200: any = null; let resultData200 = _responseText; - result200 = MessengerUser.fromJS(resultData200, _mappings); - return Promise.resolve(result200); + result200 = MessengerUserDto.fromJS(resultData200, _mappings); + return Promise.resolve(result200); + + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } - return Promise.resolve(null as any); + return Promise.resolve(null as any); } getAllChatsByUserId(userId: string , cancelToken?: CancelToken | undefined): Promise { @@ -1089,6 +1461,17 @@ export class UserClient implements IUserClient { } return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -1134,6 +1517,7 @@ export class UserClient implements IUserClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; let result200: any = null; @@ -1148,6 +1532,17 @@ export class UserClient implements IUserClient { } return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -1155,11 +1550,11 @@ export class UserClient implements IUserClient { return Promise.resolve(null as any); } - setNickNameById(setUserNickNameById: SetUserNickNameById , cancelToken?: CancelToken | undefined): Promise { + setNickNameById(setUserNickNameByIdCommand: SetUserNickNameByIdCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/User/SetNickNameById"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(setUserNickNameById); + const content_ = JSON.stringify(setUserNickNameByIdCommand); let options_: AxiosRequestConfig = { data: content_, @@ -1192,10 +1587,26 @@ export class UserClient implements IUserClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -1203,11 +1614,11 @@ export class UserClient implements IUserClient { return Promise.resolve(null as any); } - deleteUser(deleteUser: DeleteUser , cancelToken?: CancelToken | undefined): Promise { + deleteUser(deleteUserCommand: DeleteUserCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/User/DeleteUser"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(deleteUser); + const content_ = JSON.stringify(deleteUserCommand); let options_: AxiosRequestConfig = { data: content_, @@ -1240,22 +1651,38 @@ export class UserClient implements IUserClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); - } else if (status !== 200 && status !== 204) { + } else if (status === 401) { const _responseText = response.data; - return throwException("An unexpected server error occurred.", status, _responseText, _headers); - } - return Promise.resolve(null as any); - } + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); - addUser(addUser: AddUser , cancelToken?: CancelToken | undefined): Promise { + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + + } else if (status !== 200 && status !== 204) { + const _responseText = response.data; + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + } + return Promise.resolve(null as any); + } + + addUser(addUserCommand: AddUserCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/User/AddUser"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(addUser); + const content_ = JSON.stringify(addUserCommand); let options_: AxiosRequestConfig = { data: content_, @@ -1289,6 +1716,7 @@ export class UserClient implements IUserClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; let result200: any = null; @@ -1297,6 +1725,25 @@ export class UserClient implements IUserClient { return Promise.resolve(result200); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 201) { + const _responseText = response.data; + let result201: any = null; + let resultData201 = _responseText; + result201 = resultData201 !== undefined ? resultData201 : null; + + return Promise.resolve(result201); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -1304,11 +1751,11 @@ export class UserClient implements IUserClient { return Promise.resolve(null as any); } - changeDescription(changeUserDescriptionById: ChangeUserDescriptionById , cancelToken?: CancelToken | undefined): Promise { + changeDescription(changeUserDescriptionByIdCommand: ChangeUserDescriptionByIdCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/User/ChangeDescription"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(changeUserDescriptionById); + const content_ = JSON.stringify(changeUserDescriptionByIdCommand); let options_: AxiosRequestConfig = { data: content_, @@ -1341,10 +1788,26 @@ export class UserClient implements IUserClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -1352,11 +1815,11 @@ export class UserClient implements IUserClient { return Promise.resolve(null as any); } - changeName(changeUserNameById: ChangeUserNameById , cancelToken?: CancelToken | undefined): Promise { + changeName(changeUserNameByIdCommand: ChangeUserNameByIdCommand , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/User/ChangeName"; url_ = url_.replace(/[?&]$/, ""); - const content_ = JSON.stringify(changeUserNameById); + const content_ = JSON.stringify(changeUserNameByIdCommand); let options_: AxiosRequestConfig = { data: content_, @@ -1389,10 +1852,26 @@ export class UserClient implements IUserClient { } } } + let _mappings: { source: any, target: any }[] = []; if (status === 200) { const _responseText = response.data; return Promise.resolve(null as any); + } else if (status === 401) { + const _responseText = response.data; + let result401: any = null; + let resultData401 = _responseText; + result401 = ProblemDetails.fromJS(resultData401, _mappings); + return throwException("A server side error occurred.", status, _responseText, _headers, result401); + + } else if (status === 500) { + const _responseText = response.data; + return throwException("A server side error occurred.", status, _responseText, _headers); + + } else if (status === 204) { + const _responseText = response.data; + return Promise.resolve(null as any); + } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); @@ -1401,10 +1880,201 @@ export class UserClient implements IUserClient { } } -export class Login implements ILogin { +export class IdentityUserOfGuid implements IIdentityUserOfGuid { + id!: string; + userName!: string | undefined; + normalizedUserName!: string | undefined; + email!: string | undefined; + normalizedEmail!: string | undefined; + emailConfirmed!: boolean; + passwordHash!: string | undefined; + securityStamp!: string | undefined; + concurrencyStamp!: string | undefined; + phoneNumber!: string | undefined; + phoneNumberConfirmed!: boolean; + twoFactorEnabled!: boolean; + lockoutEnd!: moment.Moment | undefined; + lockoutEnabled!: boolean; + accessFailedCount!: number; + + constructor(data?: IIdentityUserOfGuid) { + if (data) { + for (var property in data) { + if (data.hasOwnProperty(property)) + (this)[property] = (data)[property]; + } + } + } + + init(_data?: any, _mappings?: any) { + if (_data) { + this.id = _data["id"]; + this.userName = _data["userName"]; + this.normalizedUserName = _data["normalizedUserName"]; + this.email = _data["email"]; + this.normalizedEmail = _data["normalizedEmail"]; + this.emailConfirmed = _data["emailConfirmed"]; + this.passwordHash = _data["passwordHash"]; + this.securityStamp = _data["securityStamp"]; + this.concurrencyStamp = _data["concurrencyStamp"]; + this.phoneNumber = _data["phoneNumber"]; + this.phoneNumberConfirmed = _data["phoneNumberConfirmed"]; + this.twoFactorEnabled = _data["twoFactorEnabled"]; + this.lockoutEnd = _data["lockoutEnd"] ? moment.parseZone(_data["lockoutEnd"].toString()) : undefined; + this.lockoutEnabled = _data["lockoutEnabled"]; + this.accessFailedCount = _data["accessFailedCount"]; + } + } + + static fromJS(data: any, _mappings?: any): IdentityUserOfGuid | null { + data = typeof data === 'object' ? data : {}; + return createInstance(data, _mappings, IdentityUserOfGuid); + } + + toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["id"] = this.id; + data["userName"] = this.userName; + data["normalizedUserName"] = this.normalizedUserName; + data["email"] = this.email; + data["normalizedEmail"] = this.normalizedEmail; + data["emailConfirmed"] = this.emailConfirmed; + data["passwordHash"] = this.passwordHash; + data["securityStamp"] = this.securityStamp; + data["concurrencyStamp"] = this.concurrencyStamp; + data["phoneNumber"] = this.phoneNumber; + data["phoneNumberConfirmed"] = this.phoneNumberConfirmed; + data["twoFactorEnabled"] = this.twoFactorEnabled; + data["lockoutEnd"] = this.lockoutEnd ? this.lockoutEnd.toISOString(true) : undefined; + data["lockoutEnabled"] = this.lockoutEnabled; + data["accessFailedCount"] = this.accessFailedCount; + return data; + } +} + +export interface IIdentityUserOfGuid { + id: string; + userName: string | undefined; + normalizedUserName: string | undefined; + email: string | undefined; + normalizedEmail: string | undefined; + emailConfirmed: boolean; + passwordHash: string | undefined; + securityStamp: string | undefined; + concurrencyStamp: string | undefined; + phoneNumber: string | undefined; + phoneNumberConfirmed: boolean; + twoFactorEnabled: boolean; + lockoutEnd: moment.Moment | undefined; + lockoutEnabled: boolean; + accessFailedCount: number; +} + +export class MessengerUser extends IdentityUserOfGuid implements IMessengerUser { + name!: string; + description!: string; + + constructor(data?: IMessengerUser) { + super(data); + } + + override init(_data?: any, _mappings?: any) { + super.init(_data); + if (_data) { + this.name = _data["name"]; + this.description = _data["description"]; + } + } + + static override fromJS(data: any, _mappings?: any): MessengerUser | null { + data = typeof data === 'object' ? data : {}; + return createInstance(data, _mappings, MessengerUser); + } + + override toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["name"] = this.name; + data["description"] = this.description; + super.toJSON(data); + return data; + } +} + +export interface IMessengerUser extends IIdentityUserOfGuid { + name: string; + description: string; +} + +export class ProblemDetails implements IProblemDetails { + type!: string | undefined; + title!: string | undefined; + status!: number | undefined; + detail!: string | undefined; + instance!: string | undefined; + extensions!: { [key: string]: any; }; + + constructor(data?: IProblemDetails) { + if (data) { + for (var property in data) { + if (data.hasOwnProperty(property)) + (this)[property] = (data)[property]; + } + } + } + + init(_data?: any, _mappings?: any) { + if (_data) { + this.type = _data["type"]; + this.title = _data["title"]; + this.status = _data["status"]; + this.detail = _data["detail"]; + this.instance = _data["instance"]; + if (_data["extensions"]) { + this.extensions = {} as any; + for (let key in _data["extensions"]) { + if (_data["extensions"].hasOwnProperty(key)) + (this.extensions)![key] = _data["extensions"][key]; + } + } + } + } + + static fromJS(data: any, _mappings?: any): ProblemDetails | null { + data = typeof data === 'object' ? data : {}; + return createInstance(data, _mappings, ProblemDetails); + } + + toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["type"] = this.type; + data["title"] = this.title; + data["status"] = this.status; + data["detail"] = this.detail; + data["instance"] = this.instance; + if (this.extensions) { + data["extensions"] = {}; + for (let key in this.extensions) { + if (this.extensions.hasOwnProperty(key)) + (data["extensions"])[key] = this.extensions[key]; + } + } + return data; + } +} + +export interface IProblemDetails { + type: string | undefined; + title: string | undefined; + status: number | undefined; + detail: string | undefined; + instance: string | undefined; + extensions: { [key: string]: any; }; +} + +export class LoginRequest implements ILoginRequest { model!: LoginModel; - constructor(data?: ILogin) { + constructor(data?: ILoginRequest) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -1419,9 +2089,9 @@ export class Login implements ILogin { } } - static fromJS(data: any, _mappings?: any): Login | null { + static fromJS(data: any, _mappings?: any): LoginRequest | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, Login); + return createInstance(data, _mappings, LoginRequest); } toJSON(data?: any) { @@ -1431,13 +2101,13 @@ export class Login implements ILogin { } } -export interface ILogin { +export interface ILoginRequest { model: LoginModel; } export class LoginModel implements ILoginModel { - id!: string; - nickName!: string; + userName!: string | undefined; + email!: string | undefined; password!: string; constructor(data?: ILoginModel) { @@ -1451,8 +2121,8 @@ export class LoginModel implements ILoginModel { init(_data?: any, _mappings?: any) { if (_data) { - this.id = _data["id"]; - this.nickName = _data["nickName"]; + this.userName = _data["userName"]; + this.email = _data["email"]; this.password = _data["password"]; } } @@ -1464,23 +2134,23 @@ export class LoginModel implements ILoginModel { toJSON(data?: any) { data = typeof data === 'object' ? data : {}; - data["id"] = this.id; - data["nickName"] = this.nickName; + data["userName"] = this.userName; + data["email"] = this.email; data["password"] = this.password; return data; } } export interface ILoginModel { - id: string; - nickName: string; + userName: string | undefined; + email: string | undefined; password: string; } -export class Register implements IRegister { +export class RegisterCommand implements IRegisterCommand { model!: RegisterModel; - constructor(data?: IRegister) { + constructor(data?: IRegisterCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -1495,9 +2165,9 @@ export class Register implements IRegister { } } - static fromJS(data: any, _mappings?: any): Register | null { + static fromJS(data: any, _mappings?: any): RegisterCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, Register); + return createInstance(data, _mappings, RegisterCommand); } toJSON(data?: any) { @@ -1507,15 +2177,16 @@ export class Register implements IRegister { } } -export interface IRegister { +export interface IRegisterCommand { model: RegisterModel; } export class RegisterModel implements IRegisterModel { + userName!: string; name!: string; - nickName!: string; email!: string; password!: string; + phoneNumber!: string; constructor(data?: IRegisterModel) { if (data) { @@ -1528,10 +2199,11 @@ export class RegisterModel implements IRegisterModel { init(_data?: any, _mappings?: any) { if (_data) { + this.userName = _data["userName"]; this.name = _data["name"]; - this.nickName = _data["nickName"]; this.email = _data["email"]; this.password = _data["password"]; + this.phoneNumber = _data["phoneNumber"]; } } @@ -1542,25 +2214,27 @@ export class RegisterModel implements IRegisterModel { toJSON(data?: any) { data = typeof data === 'object' ? data : {}; + data["userName"] = this.userName; data["name"] = this.name; - data["nickName"] = this.nickName; data["email"] = this.email; data["password"] = this.password; + data["phoneNumber"] = this.phoneNumber; return data; } } export interface IRegisterModel { + userName: string; name: string; - nickName: string; email: string; password: string; + phoneNumber: string; } -export class RegisterAdmin implements IRegisterAdmin { +export class RegisterAdminCommand implements IRegisterAdminCommand { model!: RegisterModel; - constructor(data?: IRegisterAdmin) { + constructor(data?: IRegisterAdminCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -1575,9 +2249,9 @@ export class RegisterAdmin implements IRegisterAdmin { } } - static fromJS(data: any, _mappings?: any): RegisterAdmin | null { + static fromJS(data: any, _mappings?: any): RegisterAdminCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, RegisterAdmin); + return createInstance(data, _mappings, RegisterAdminCommand); } toJSON(data?: any) { @@ -1587,7 +2261,7 @@ export class RegisterAdmin implements IRegisterAdmin { } } -export interface IRegisterAdmin { +export interface IRegisterAdminCommand { model: RegisterModel; } @@ -1595,7 +2269,6 @@ export class MessengerChatDto implements IMessengerChatDto { id!: string; name!: string | undefined; description!: string | undefined; - creator!: MessengerUserDto | undefined; users!: string[]; roles!: RoleDto[]; @@ -1613,7 +2286,6 @@ export class MessengerChatDto implements IMessengerChatDto { this.id = _data["id"]; this.name = _data["name"]; this.description = _data["description"]; - this.creator = _data["creator"] ? MessengerUserDto.fromJS(_data["creator"], _mappings) : undefined; if (Array.isArray(_data["users"])) { this.users = [] as any; for (let item of _data["users"]) @@ -1637,7 +2309,6 @@ export class MessengerChatDto implements IMessengerChatDto { data["id"] = this.id; data["name"] = this.name; data["description"] = this.description; - data["creator"] = this.creator ? this.creator.toJSON() : undefined; if (Array.isArray(this.users)) { data["users"] = []; for (let item of this.users) @@ -1656,57 +2327,10 @@ export interface IMessengerChatDto { id: string; name: string | undefined; description: string | undefined; - creator: MessengerUserDto | undefined; users: string[]; roles: RoleDto[]; } -export class MessengerUserDto implements IMessengerUserDto { - id!: string; - name!: string | undefined; - nickName!: string | undefined; - description!: string | undefined; - - constructor(data?: IMessengerUserDto) { - if (data) { - for (var property in data) { - if (data.hasOwnProperty(property)) - (this)[property] = (data)[property]; - } - } - } - - init(_data?: any, _mappings?: any) { - if (_data) { - this.id = _data["id"]; - this.name = _data["name"]; - this.nickName = _data["nickName"]; - this.description = _data["description"]; - } - } - - static fromJS(data: any, _mappings?: any): MessengerUserDto | null { - data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, MessengerUserDto); - } - - toJSON(data?: any) { - data = typeof data === 'object' ? data : {}; - data["id"] = this.id; - data["name"] = this.name; - data["nickName"] = this.nickName; - data["description"] = this.description; - return data; - } -} - -export interface IMessengerUserDto { - id: string; - name: string | undefined; - nickName: string | undefined; - description: string | undefined; -} - export class RoleDto implements IRoleDto { name!: string; canEditMessages!: ActionOption; @@ -1791,15 +2415,12 @@ export enum ActionOption { Disabled = 2, } -export class ChatUser implements IChatUser { - user!: MessengerUser; - id!: string; +export class ChatUserDto implements IChatUserDto { + chatUserName!: string; messengerUserId!: string; - chat!: Chat; - chatId!: string; - role!: Role; + role!: RoleDto; - constructor(data?: IChatUser) { + constructor(data?: IChatUserDto) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -1810,269 +2431,38 @@ export class ChatUser implements IChatUser { init(_data?: any, _mappings?: any) { if (_data) { - this.user = _data["user"] ? MessengerUser.fromJS(_data["user"], _mappings) : undefined; - this.id = _data["id"]; + this.chatUserName = _data["chatUserName"]; this.messengerUserId = _data["messengerUserId"]; - this.chat = _data["chat"] ? Chat.fromJS(_data["chat"], _mappings) : undefined; - this.chatId = _data["chatId"]; - this.role = _data["role"] ? Role.fromJS(_data["role"], _mappings) : undefined; + this.role = _data["role"] ? RoleDto.fromJS(_data["role"], _mappings) : undefined; } } - static fromJS(data: any, _mappings?: any): ChatUser | null { + static fromJS(data: any, _mappings?: any): ChatUserDto | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, ChatUser); + return createInstance(data, _mappings, ChatUserDto); } toJSON(data?: any) { data = typeof data === 'object' ? data : {}; - data["user"] = this.user ? this.user.toJSON() : undefined; - data["id"] = this.id; + data["chatUserName"] = this.chatUserName; data["messengerUserId"] = this.messengerUserId; - data["chat"] = this.chat ? this.chat.toJSON() : undefined; - data["chatId"] = this.chatId; data["role"] = this.role ? this.role.toJSON() : undefined; return data; } } -export interface IChatUser { - user: MessengerUser; - id: string; +export interface IChatUserDto { + chatUserName: string; messengerUserId: string; - chat: Chat; - chatId: string; - role: Role; -} - -export class MessengerUser implements IMessengerUser { - id!: string; - name!: string; - nickName!: string; - description!: string; - chats!: Chat[]; - - constructor(data?: IMessengerUser) { - if (data) { - for (var property in data) { - if (data.hasOwnProperty(property)) - (this)[property] = (data)[property]; - } - } - } - - init(_data?: any, _mappings?: any) { - if (_data) { - this.id = _data["id"]; - this.name = _data["name"]; - this.nickName = _data["nickName"]; - this.description = _data["description"]; - if (Array.isArray(_data["chats"])) { - this.chats = [] as any; - for (let item of _data["chats"]) - this.chats!.push(Chat.fromJS(item, _mappings)); - } - } - } - - static fromJS(data: any, _mappings?: any): MessengerUser | null { - data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, MessengerUser); - } - - toJSON(data?: any) { - data = typeof data === 'object' ? data : {}; - data["id"] = this.id; - data["name"] = this.name; - data["nickName"] = this.nickName; - data["description"] = this.description; - if (Array.isArray(this.chats)) { - data["chats"] = []; - for (let item of this.chats) - data["chats"].push(item.toJSON()); - } - return data; - } -} - -export interface IMessengerUser { - id: string; - name: string; - nickName: string; - description: string; - chats: Chat[]; -} - -export abstract class Chat implements IChat { - id!: string; - name!: string; - description!: string; - creator!: MessengerUser; - creatorId!: string; - maxUsersAmount!: number; - users!: ChatUser[]; - roles!: Role[]; - - constructor(data?: IChat) { - if (data) { - for (var property in data) { - if (data.hasOwnProperty(property)) - (this)[property] = (data)[property]; - } - } - } - - init(_data?: any, _mappings?: any) { - if (_data) { - this.id = _data["id"]; - this.name = _data["name"]; - this.description = _data["description"]; - this.creator = _data["creator"] ? MessengerUser.fromJS(_data["creator"], _mappings) : undefined; - this.creatorId = _data["creatorId"]; - this.maxUsersAmount = _data["maxUsersAmount"]; - if (Array.isArray(_data["users"])) { - this.users = [] as any; - for (let item of _data["users"]) - this.users!.push(ChatUser.fromJS(item, _mappings)); - } - if (Array.isArray(_data["roles"])) { - this.roles = [] as any; - for (let item of _data["roles"]) - this.roles!.push(Role.fromJS(item, _mappings)); - } - } - } - - static fromJS(data: any, _mappings?: any): Chat | null { - data = typeof data === 'object' ? data : {}; - throw new Error("The abstract class 'Chat' cannot be instantiated."); - } - - toJSON(data?: any) { - data = typeof data === 'object' ? data : {}; - data["id"] = this.id; - data["name"] = this.name; - data["description"] = this.description; - data["creator"] = this.creator ? this.creator.toJSON() : undefined; - data["creatorId"] = this.creatorId; - data["maxUsersAmount"] = this.maxUsersAmount; - if (Array.isArray(this.users)) { - data["users"] = []; - for (let item of this.users) - data["users"].push(item.toJSON()); - } - if (Array.isArray(this.roles)) { - data["roles"] = []; - for (let item of this.roles) - data["roles"].push(item.toJSON()); - } - return data; - } -} - -export interface IChat { - id: string; - name: string; - description: string; - creator: MessengerUser; - creatorId: string; - maxUsersAmount: number; - users: ChatUser[]; - roles: Role[]; -} - -export class Role implements IRole { - id!: string; - chat!: Chat; - name!: string; - canEditMessages!: ActionOption; - canDeleteMessages!: ActionOption; - canWriteMessages!: ActionOption; - canReadMessages!: ActionOption; - canAddUsers!: ActionOption; - canDeleteUsers!: ActionOption; - canPinMessages!: ActionOption; - canSeeChannelMembers!: ActionOption; - canInviteOtherUsers!: ActionOption; - canEditChannelDescription!: ActionOption; - canDeleteChat!: ActionOption; - - constructor(data?: IRole) { - if (data) { - for (var property in data) { - if (data.hasOwnProperty(property)) - (this)[property] = (data)[property]; - } - } - } - - init(_data?: any, _mappings?: any) { - if (_data) { - this.id = _data["id"]; - this.chat = _data["chat"] ? Chat.fromJS(_data["chat"], _mappings) : undefined; - this.name = _data["name"]; - this.canEditMessages = _data["canEditMessages"]; - this.canDeleteMessages = _data["canDeleteMessages"]; - this.canWriteMessages = _data["canWriteMessages"]; - this.canReadMessages = _data["canReadMessages"]; - this.canAddUsers = _data["canAddUsers"]; - this.canDeleteUsers = _data["canDeleteUsers"]; - this.canPinMessages = _data["canPinMessages"]; - this.canSeeChannelMembers = _data["canSeeChannelMembers"]; - this.canInviteOtherUsers = _data["canInviteOtherUsers"]; - this.canEditChannelDescription = _data["canEditChannelDescription"]; - this.canDeleteChat = _data["canDeleteChat"]; - } - } - - static fromJS(data: any, _mappings?: any): Role | null { - data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, Role); - } - - toJSON(data?: any) { - data = typeof data === 'object' ? data : {}; - data["id"] = this.id; - data["chat"] = this.chat ? this.chat.toJSON() : undefined; - data["name"] = this.name; - data["canEditMessages"] = this.canEditMessages; - data["canDeleteMessages"] = this.canDeleteMessages; - data["canWriteMessages"] = this.canWriteMessages; - data["canReadMessages"] = this.canReadMessages; - data["canAddUsers"] = this.canAddUsers; - data["canDeleteUsers"] = this.canDeleteUsers; - data["canPinMessages"] = this.canPinMessages; - data["canSeeChannelMembers"] = this.canSeeChannelMembers; - data["canInviteOtherUsers"] = this.canInviteOtherUsers; - data["canEditChannelDescription"] = this.canEditChannelDescription; - data["canDeleteChat"] = this.canDeleteChat; - return data; - } -} - -export interface IRole { - id: string; - chat: Chat; - name: string; - canEditMessages: ActionOption; - canDeleteMessages: ActionOption; - canWriteMessages: ActionOption; - canReadMessages: ActionOption; - canAddUsers: ActionOption; - canDeleteUsers: ActionOption; - canPinMessages: ActionOption; - canSeeChannelMembers: ActionOption; - canInviteOtherUsers: ActionOption; - canEditChannelDescription: ActionOption; - canDeleteChat: ActionOption; + role: RoleDto; } -export class AddChannel implements IAddChannel { +export class AddChannelCommand implements IAddChannelCommand { adminId!: string; name!: string; description!: string; - constructor(data?: IAddChannel) { + constructor(data?: IAddChannelCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2089,9 +2479,9 @@ export class AddChannel implements IAddChannel { } } - static fromJS(data: any, _mappings?: any): AddChannel | null { + static fromJS(data: any, _mappings?: any): AddChannelCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, AddChannel); + return createInstance(data, _mappings, AddChannelCommand); } toJSON(data?: any) { @@ -2103,18 +2493,18 @@ export class AddChannel implements IAddChannel { } } -export interface IAddChannel { +export interface IAddChannelCommand { adminId: string; name: string; description: string; } -export class AddGroupChat implements IAddGroupChat { +export class AddGroupChatCommand implements IAddGroupChatCommand { adminId!: string; name!: string; description!: string; - constructor(data?: IAddGroupChat) { + constructor(data?: IAddGroupChatCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2131,9 +2521,9 @@ export class AddGroupChat implements IAddGroupChat { } } - static fromJS(data: any, _mappings?: any): AddGroupChat | null { + static fromJS(data: any, _mappings?: any): AddGroupChatCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, AddGroupChat); + return createInstance(data, _mappings, AddGroupChatCommand); } toJSON(data?: any) { @@ -2145,19 +2535,19 @@ export class AddGroupChat implements IAddGroupChat { } } -export interface IAddGroupChat { +export interface IAddGroupChatCommand { adminId: string; name: string; description: string; } -export class AddPersonalChat implements IAddPersonalChat { +export class AddPersonalChatCommand implements IAddPersonalChatCommand { firstUserId!: string; secondUserId!: string; name!: string; description!: string; - constructor(data?: IAddPersonalChat) { + constructor(data?: IAddPersonalChatCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2175,9 +2565,9 @@ export class AddPersonalChat implements IAddPersonalChat { } } - static fromJS(data: any, _mappings?: any): AddPersonalChat | null { + static fromJS(data: any, _mappings?: any): AddPersonalChatCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, AddPersonalChat); + return createInstance(data, _mappings, AddPersonalChatCommand); } toJSON(data?: any) { @@ -2190,19 +2580,19 @@ export class AddPersonalChat implements IAddPersonalChat { } } -export interface IAddPersonalChat { +export interface IAddPersonalChatCommand { firstUserId: string; secondUserId: string; name: string; description: string; } -export class AddSavedMessages implements IAddSavedMessages { +export class AddSavedMessagesCommand implements IAddSavedMessagesCommand { userId!: string; name!: string; description!: string; - constructor(data?: IAddSavedMessages) { + constructor(data?: IAddSavedMessagesCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2219,9 +2609,9 @@ export class AddSavedMessages implements IAddSavedMessages { } } - static fromJS(data: any, _mappings?: any): AddSavedMessages | null { + static fromJS(data: any, _mappings?: any): AddSavedMessagesCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, AddSavedMessages); + return createInstance(data, _mappings, AddSavedMessagesCommand); } toJSON(data?: any) { @@ -2233,17 +2623,17 @@ export class AddSavedMessages implements IAddSavedMessages { } } -export interface IAddSavedMessages { +export interface IAddSavedMessagesCommand { userId: string; name: string; description: string; } -export class AddUserToChat implements IAddUserToChat { +export class AddUserToChatCommand implements IAddUserToChatCommand { userId!: string; chatId!: string; - constructor(data?: IAddUserToChat) { + constructor(data?: IAddUserToChatCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2259,9 +2649,9 @@ export class AddUserToChat implements IAddUserToChat { } } - static fromJS(data: any, _mappings?: any): AddUserToChat | null { + static fromJS(data: any, _mappings?: any): AddUserToChatCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, AddUserToChat); + return createInstance(data, _mappings, AddUserToChatCommand); } toJSON(data?: any) { @@ -2272,16 +2662,16 @@ export class AddUserToChat implements IAddUserToChat { } } -export interface IAddUserToChat { +export interface IAddUserToChatCommand { userId: string; chatId: string; } -export class DeleteUserFromChat implements IDeleteUserFromChat { +export class DeleteUserFromChatCommand implements IDeleteUserFromChatCommand { userId!: string; chatId!: string; - constructor(data?: IDeleteUserFromChat) { + constructor(data?: IDeleteUserFromChatCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2297,9 +2687,9 @@ export class DeleteUserFromChat implements IDeleteUserFromChat { } } - static fromJS(data: any, _mappings?: any): DeleteUserFromChat | null { + static fromJS(data: any, _mappings?: any): DeleteUserFromChatCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, DeleteUserFromChat); + return createInstance(data, _mappings, DeleteUserFromChatCommand); } toJSON(data?: any) { @@ -2310,16 +2700,16 @@ export class DeleteUserFromChat implements IDeleteUserFromChat { } } -export interface IDeleteUserFromChat { +export interface IDeleteUserFromChatCommand { userId: string; chatId: string; } -export class CreateRoleForChat implements ICreateRoleForChat { +export class CreateRoleForChatCommand implements ICreateRoleForChatCommand { role!: RoleDto; chatId!: string; - constructor(data?: ICreateRoleForChat) { + constructor(data?: ICreateRoleForChatCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2335,9 +2725,9 @@ export class CreateRoleForChat implements ICreateRoleForChat { } } - static fromJS(data: any, _mappings?: any): CreateRoleForChat | null { + static fromJS(data: any, _mappings?: any): CreateRoleForChatCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, CreateRoleForChat); + return createInstance(data, _mappings, CreateRoleForChatCommand); } toJSON(data?: any) { @@ -2348,17 +2738,17 @@ export class CreateRoleForChat implements ICreateRoleForChat { } } -export interface ICreateRoleForChat { +export interface ICreateRoleForChatCommand { role: RoleDto; chatId: string; } -export class ChangeRoleForUserById implements IChangeRoleForUserById { +export class ChangeRoleForUserByIdCommand implements IChangeRoleForUserByIdCommand { userId!: string; chatId!: string; role!: RoleDto; - constructor(data?: IChangeRoleForUserById) { + constructor(data?: IChangeRoleForUserByIdCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2375,9 +2765,9 @@ export class ChangeRoleForUserById implements IChangeRoleForUserById { } } - static fromJS(data: any, _mappings?: any): ChangeRoleForUserById | null { + static fromJS(data: any, _mappings?: any): ChangeRoleForUserByIdCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, ChangeRoleForUserById); + return createInstance(data, _mappings, ChangeRoleForUserByIdCommand); } toJSON(data?: any) { @@ -2389,17 +2779,63 @@ export class ChangeRoleForUserById implements IChangeRoleForUserById { } } -export interface IChangeRoleForUserById { +export interface IChangeRoleForUserByIdCommand { userId: string; chatId: string; role: RoleDto; } -export class SetUserNickNameById implements ISetUserNickNameById { +export class MessengerUserDto implements IMessengerUserDto { + id!: string; + name!: string | undefined; + userName!: string | undefined; + description!: string | undefined; + + constructor(data?: IMessengerUserDto) { + if (data) { + for (var property in data) { + if (data.hasOwnProperty(property)) + (this)[property] = (data)[property]; + } + } + } + + init(_data?: any, _mappings?: any) { + if (_data) { + this.id = _data["id"]; + this.name = _data["name"]; + this.userName = _data["userName"]; + this.description = _data["description"]; + } + } + + static fromJS(data: any, _mappings?: any): MessengerUserDto | null { + data = typeof data === 'object' ? data : {}; + return createInstance(data, _mappings, MessengerUserDto); + } + + toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["id"] = this.id; + data["name"] = this.name; + data["userName"] = this.userName; + data["description"] = this.description; + return data; + } +} + +export interface IMessengerUserDto { + id: string; + name: string | undefined; + userName: string | undefined; + description: string | undefined; +} + +export class SetUserNickNameByIdCommand implements ISetUserNickNameByIdCommand { userId!: string; - nickName!: string; + userName!: string; - constructor(data?: ISetUserNickNameById) { + constructor(data?: ISetUserNickNameByIdCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2411,32 +2847,32 @@ export class SetUserNickNameById implements ISetUserNickNameById { init(_data?: any, _mappings?: any) { if (_data) { this.userId = _data["userId"]; - this.nickName = _data["nickName"]; + this.userName = _data["userName"]; } } - static fromJS(data: any, _mappings?: any): SetUserNickNameById | null { + static fromJS(data: any, _mappings?: any): SetUserNickNameByIdCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, SetUserNickNameById); + return createInstance(data, _mappings, SetUserNickNameByIdCommand); } toJSON(data?: any) { data = typeof data === 'object' ? data : {}; data["userId"] = this.userId; - data["nickName"] = this.nickName; + data["userName"] = this.userName; return data; } } -export interface ISetUserNickNameById { +export interface ISetUserNickNameByIdCommand { userId: string; - nickName: string; + userName: string; } -export class DeleteUser implements IDeleteUser { +export class DeleteUserCommand implements IDeleteUserCommand { userId!: string; - constructor(data?: IDeleteUser) { + constructor(data?: IDeleteUserCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2451,9 +2887,9 @@ export class DeleteUser implements IDeleteUser { } } - static fromJS(data: any, _mappings?: any): DeleteUser | null { + static fromJS(data: any, _mappings?: any): DeleteUserCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, DeleteUser); + return createInstance(data, _mappings, DeleteUserCommand); } toJSON(data?: any) { @@ -2463,16 +2899,16 @@ export class DeleteUser implements IDeleteUser { } } -export interface IDeleteUser { +export interface IDeleteUserCommand { userId: string; } -export class AddUser implements IAddUser { +export class AddUserCommand implements IAddUserCommand { name!: string; nickName!: string; description!: string; - constructor(data?: IAddUser) { + constructor(data?: IAddUserCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2489,9 +2925,9 @@ export class AddUser implements IAddUser { } } - static fromJS(data: any, _mappings?: any): AddUser | null { + static fromJS(data: any, _mappings?: any): AddUserCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, AddUser); + return createInstance(data, _mappings, AddUserCommand); } toJSON(data?: any) { @@ -2503,17 +2939,17 @@ export class AddUser implements IAddUser { } } -export interface IAddUser { +export interface IAddUserCommand { name: string; nickName: string; description: string; } -export class ChangeUserDescriptionById implements IChangeUserDescriptionById { +export class ChangeUserDescriptionByIdCommand implements IChangeUserDescriptionByIdCommand { userId!: string; description!: string; - constructor(data?: IChangeUserDescriptionById) { + constructor(data?: IChangeUserDescriptionByIdCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2529,9 +2965,9 @@ export class ChangeUserDescriptionById implements IChangeUserDescriptionById { } } - static fromJS(data: any, _mappings?: any): ChangeUserDescriptionById | null { + static fromJS(data: any, _mappings?: any): ChangeUserDescriptionByIdCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, ChangeUserDescriptionById); + return createInstance(data, _mappings, ChangeUserDescriptionByIdCommand); } toJSON(data?: any) { @@ -2542,16 +2978,16 @@ export class ChangeUserDescriptionById implements IChangeUserDescriptionById { } } -export interface IChangeUserDescriptionById { +export interface IChangeUserDescriptionByIdCommand { userId: string; description: string; } -export class ChangeUserNameById implements IChangeUserNameById { +export class ChangeUserNameByIdCommand implements IChangeUserNameByIdCommand { userId!: string; name!: string; - constructor(data?: IChangeUserNameById) { + constructor(data?: IChangeUserNameByIdCommand) { if (data) { for (var property in data) { if (data.hasOwnProperty(property)) @@ -2567,9 +3003,9 @@ export class ChangeUserNameById implements IChangeUserNameById { } } - static fromJS(data: any, _mappings?: any): ChangeUserNameById | null { + static fromJS(data: any, _mappings?: any): ChangeUserNameByIdCommand | null { data = typeof data === 'object' ? data : {}; - return createInstance(data, _mappings, ChangeUserNameById); + return createInstance(data, _mappings, ChangeUserNameByIdCommand); } toJSON(data?: any) { @@ -2580,7 +3016,7 @@ export class ChangeUserNameById implements IChangeUserNameById { } } -export interface IChangeUserNameById { +export interface IChangeUserNameByIdCommand { userId: string; name: string; } @@ -2646,13 +3082,6 @@ function createInstance(data: any, mappings: any, type: any): T | null { return result; } -export interface FileResponse { - data: Blob; - status: number; - fileName?: string; - headers?: { [name: string]: any }; -} - export class Do_Svyazi_User_ApiClient_Exception extends Error { override message: string; status: number; diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json index 9ed813a..bb8a830 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json @@ -6,7 +6,43 @@ "version": "2.1.0" }, "paths": { - "/api/Authenticate/login": { + "/api/Authenticate/GetAll": { + "get": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_GetAll", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessengerUser" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Authenticate/Login": { "post": { "tags": [ "Authenticate" @@ -17,7 +53,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Login" + "$ref": "#/components/schemas/LoginRequest" } } }, @@ -26,20 +62,25 @@ }, "responses": { "200": { + "description": "" + }, + "401": { "description": "", "content": { - "application/octet-stream": { + "application/json": { "schema": { - "type": "string", - "format": "binary" + "$ref": "#/components/schemas/ProblemDetails" } } } + }, + "500": { + "description": "" } } } }, - "/api/Authenticate/register": { + "/api/Authenticate/Register": { "post": { "tags": [ "Authenticate" @@ -50,29 +91,83 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Register" + "$ref": "#/components/schemas/RegisterCommand" } } }, "required": true, "x-position": 1 }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/Authenticate/AuthenticateByJwt": { + "get": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_AuthenticateByJwt", + "parameters": [ + { + "name": "jwtToken", + "in": "header", + "required": true, + "schema": { + "type": "string", + "nullable": true + }, + "x-position": 1 + } + ], "responses": { "200": { "description": "", "content": { - "application/octet-stream": { + "application/json": { "schema": { "type": "string", - "format": "binary" + "format": "guid" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" } } } + }, + "500": { + "description": "" } } } }, - "/api/Authenticate/register-admin": { + "/api/Authenticate/RegisterAdmin": { "post": { "tags": [ "Authenticate" @@ -83,7 +178,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/RegisterAdmin" + "$ref": "#/components/schemas/RegisterAdminCommand" } } }, @@ -92,15 +187,23 @@ }, "responses": { "200": { + "description": "" + }, + "401": { "description": "", "content": { - "application/octet-stream": { + "application/json": { "schema": { - "type": "string", - "format": "binary" + "$ref": "#/components/schemas/ProblemDetails" } } } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -124,6 +227,19 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -156,6 +272,19 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -192,6 +321,19 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -222,11 +364,24 @@ "schema": { "type": "array", "items": { - "$ref": "#/components/schemas/ChatUser" + "$ref": "#/components/schemas/ChatUserDto" } } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -242,7 +397,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AddChannel" + "$ref": "#/components/schemas/AddChannelCommand" } } }, @@ -252,6 +407,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" } } } @@ -267,7 +438,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AddGroupChat" + "$ref": "#/components/schemas/AddGroupChatCommand" } } }, @@ -277,6 +448,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" } } } @@ -292,7 +479,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AddPersonalChat" + "$ref": "#/components/schemas/AddPersonalChatCommand" } } }, @@ -302,6 +489,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" } } } @@ -317,7 +520,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AddSavedMessages" + "$ref": "#/components/schemas/AddSavedMessagesCommand" } } }, @@ -327,6 +530,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" } } } @@ -342,7 +561,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AddUserToChat" + "$ref": "#/components/schemas/AddUserToChatCommand" } } }, @@ -352,6 +571,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -367,7 +602,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/DeleteUserFromChat" + "$ref": "#/components/schemas/DeleteUserFromChatCommand" } } }, @@ -377,6 +612,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -419,6 +670,19 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -430,11 +694,11 @@ ], "operationId": "Roles_CreateRoleForChat", "requestBody": { - "x-name": "createRoleForChat", + "x-name": "createRoleForChatCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CreateRoleForChat" + "$ref": "#/components/schemas/CreateRoleForChatCommand" } } }, @@ -444,6 +708,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -455,11 +735,11 @@ ], "operationId": "Roles_ChangeRoleForUserById", "requestBody": { - "x-name": "changeRoleForUserById", + "x-name": "changeRoleForUserByIdCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ChangeRoleForUserById" + "$ref": "#/components/schemas/ChangeRoleForUserByIdCommand" } } }, @@ -469,6 +749,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -492,6 +788,19 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -520,10 +829,23 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/MessengerUser" + "$ref": "#/components/schemas/MessengerUserDto" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" } } } + }, + "500": { + "description": "" } } } @@ -559,8 +881,21 @@ } } } - } - } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } } }, "/api/User/GetAllChatsIdsByUserId": { @@ -595,6 +930,19 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" } } } @@ -606,11 +954,11 @@ ], "operationId": "User_SetNickNameById", "requestBody": { - "x-name": "setUserNickNameById", + "x-name": "setUserNickNameByIdCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SetUserNickNameById" + "$ref": "#/components/schemas/SetUserNickNameByIdCommand" } } }, @@ -620,6 +968,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -631,11 +995,11 @@ ], "operationId": "User_DeleteUser", "requestBody": { - "x-name": "deleteUser", + "x-name": "deleteUserCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/DeleteUser" + "$ref": "#/components/schemas/DeleteUserCommand" } } }, @@ -645,6 +1009,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -656,11 +1036,11 @@ ], "operationId": "User_AddUser", "requestBody": { - "x-name": "addUser", + "x-name": "addUserCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AddUser" + "$ref": "#/components/schemas/AddUserCommand" } } }, @@ -678,6 +1058,30 @@ } } } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string", + "format": "guid" + } + } + } } } } @@ -689,11 +1093,11 @@ ], "operationId": "User_ChangeDescription", "requestBody": { - "x-name": "changeUserDescriptionById", + "x-name": "changeUserDescriptionByIdCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ChangeUserDescriptionById" + "$ref": "#/components/schemas/ChangeUserDescriptionByIdCommand" } } }, @@ -703,6 +1107,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -714,11 +1134,11 @@ ], "operationId": "User_ChangeName", "requestBody": { - "x-name": "changeUserNameById", + "x-name": "changeUserNameByIdCommand", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ChangeUserNameById" + "$ref": "#/components/schemas/ChangeUserNameByIdCommand" } } }, @@ -728,6 +1148,22 @@ "responses": { "200": { "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" } } } @@ -735,7 +1171,122 @@ }, "components": { "schemas": { - "Login": { + "MessengerUser": { + "allOf": [ + { + "$ref": "#/components/schemas/IdentityUserOfGuid" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + } + } + ] + }, + "IdentityUserOfGuid": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "format": "guid" + }, + "userName": { + "type": "string", + "nullable": true + }, + "normalizedUserName": { + "type": "string", + "nullable": true + }, + "email": { + "type": "string", + "nullable": true + }, + "normalizedEmail": { + "type": "string", + "nullable": true + }, + "emailConfirmed": { + "type": "boolean" + }, + "passwordHash": { + "type": "string", + "nullable": true + }, + "securityStamp": { + "type": "string", + "nullable": true + }, + "concurrencyStamp": { + "type": "string", + "nullable": true + }, + "phoneNumber": { + "type": "string", + "nullable": true + }, + "phoneNumberConfirmed": { + "type": "boolean" + }, + "twoFactorEnabled": { + "type": "boolean" + }, + "lockoutEnd": { + "type": "string", + "format": "date-time", + "nullable": true + }, + "lockoutEnabled": { + "type": "boolean" + }, + "accessFailedCount": { + "type": "integer", + "format": "int32" + } + } + }, + "ProblemDetails": { + "type": "object", + "additionalProperties": { + "nullable": true + }, + "properties": { + "type": { + "type": "string", + "nullable": true + }, + "title": { + "type": "string", + "nullable": true + }, + "status": { + "type": "integer", + "format": "int32", + "nullable": true + }, + "detail": { + "type": "string", + "nullable": true + }, + "instance": { + "type": "string", + "nullable": true + }, + "extensions": { + "type": "object", + "additionalProperties": {} + } + } + }, + "LoginRequest": { "type": "object", "additionalProperties": false, "properties": { @@ -748,17 +1299,16 @@ "type": "object", "additionalProperties": false, "required": [ - "nickName", "password" ], "properties": { - "id": { + "userName": { "type": "string", - "format": "guid" + "nullable": true }, - "nickName": { + "email": { "type": "string", - "minLength": 1 + "nullable": true }, "password": { "type": "string", @@ -766,7 +1316,7 @@ } } }, - "Register": { + "RegisterCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -779,19 +1329,17 @@ "type": "object", "additionalProperties": false, "required": [ - "name", - "nickName", + "userName", "email", "password" ], "properties": { - "name": { + "userName": { "type": "string", "minLength": 1 }, - "nickName": { - "type": "string", - "minLength": 1 + "name": { + "type": "string" }, "email": { "type": "string", @@ -800,10 +1348,13 @@ "password": { "type": "string", "minLength": 1 + }, + "phoneNumber": { + "type": "string" } } }, - "RegisterAdmin": { + "RegisterAdminCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -828,14 +1379,6 @@ "type": "string", "nullable": true }, - "creator": { - "nullable": true, - "oneOf": [ - { - "$ref": "#/components/schemas/MessengerUserDto" - } - ] - }, "users": { "type": "array", "items": { @@ -851,28 +1394,6 @@ } } }, - "MessengerUserDto": { - "type": "object", - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string", - "nullable": true - }, - "nickName": { - "type": "string", - "nullable": true - }, - "description": { - "type": "string", - "nullable": true - } - } - }, "RoleDto": { "type": "object", "additionalProperties": false, @@ -929,148 +1450,23 @@ 2 ] }, - "ChatUser": { + "ChatUserDto": { "type": "object", "additionalProperties": false, "properties": { - "user": { - "$ref": "#/components/schemas/MessengerUser" - }, - "id": { - "type": "string", - "format": "guid" + "chatUserName": { + "type": "string" }, "messengerUserId": { "type": "string", "format": "guid" }, - "chat": { - "$ref": "#/components/schemas/Chat" - }, - "chatId": { - "type": "string", - "format": "guid" - }, "role": { - "$ref": "#/components/schemas/Role" - } - } - }, - "MessengerUser": { - "type": "object", - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - }, - "nickName": { - "type": "string" - }, - "description": { - "type": "string" - }, - "chats": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Chat" - } - } - } - }, - "Chat": { - "type": "object", - "x-abstract": true, - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - }, - "description": { - "type": "string" - }, - "creator": { - "$ref": "#/components/schemas/MessengerUser" - }, - "creatorId": { - "type": "string", - "format": "guid" - }, - "maxUsersAmount": { - "type": "integer", - "format": "int32" - }, - "users": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ChatUser" - } - }, - "roles": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Role" - } - } - } - }, - "Role": { - "type": "object", - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "chat": { - "$ref": "#/components/schemas/Chat" - }, - "name": { - "type": "string" - }, - "canEditMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canDeleteMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canWriteMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canReadMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canAddUsers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canDeleteUsers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canPinMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canSeeChannelMembers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canInviteOtherUsers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canEditChannelDescription": { - "$ref": "#/components/schemas/ActionOption" - }, - "canDeleteChat": { - "$ref": "#/components/schemas/ActionOption" + "$ref": "#/components/schemas/RoleDto" } } }, - "AddChannel": { + "AddChannelCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1086,7 +1482,7 @@ } } }, - "AddGroupChat": { + "AddGroupChatCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1102,7 +1498,7 @@ } } }, - "AddPersonalChat": { + "AddPersonalChatCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1122,7 +1518,7 @@ } } }, - "AddSavedMessages": { + "AddSavedMessagesCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1138,7 +1534,7 @@ } } }, - "AddUserToChat": { + "AddUserToChatCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1152,7 +1548,7 @@ } } }, - "DeleteUserFromChat": { + "DeleteUserFromChatCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1166,7 +1562,7 @@ } } }, - "CreateRoleForChat": { + "CreateRoleForChatCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1179,7 +1575,7 @@ } } }, - "ChangeRoleForUserById": { + "ChangeRoleForUserByIdCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1196,7 +1592,29 @@ } } }, - "SetUserNickNameById": { + "MessengerUserDto": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string", + "nullable": true + }, + "userName": { + "type": "string", + "nullable": true + }, + "description": { + "type": "string", + "nullable": true + } + } + }, + "SetUserNickNameByIdCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1204,12 +1622,12 @@ "type": "string", "format": "guid" }, - "nickName": { + "userName": { "type": "string" } } }, - "DeleteUser": { + "DeleteUserCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1219,7 +1637,7 @@ } } }, - "AddUser": { + "AddUserCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1234,7 +1652,7 @@ } } }, - "ChangeUserDescriptionById": { + "ChangeUserDescriptionByIdCommand": { "type": "object", "additionalProperties": false, "properties": { @@ -1247,7 +1665,7 @@ } } }, - "ChangeUserNameById": { + "ChangeUserNameByIdCommand": { "type": "object", "additionalProperties": false, "properties": { From 48dd03fb078bed67a1323676c8bf5c128fb71221 Mon Sep 17 00:00:00 2001 From: KotDimos Date: Sun, 26 Jun 2022 17:53:10 +0300 Subject: [PATCH 35/45] refactor: change role authorizate --- .../Do-Svyazi.User.Web.Controllers/ChatController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs index 49728dc..2eb1111 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/ChatController.cs @@ -100,7 +100,7 @@ public async Task AddUserToChat( } [HttpDelete(nameof(DeleteUserFromChat))] - [Authorize(Roles = $"{MessageIdentityRole.ChatAdmin}, {MessageIdentityRole.ChatCreator}")] + [Authorize(Roles = MessageIdentityRole.Admin)] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task DeleteUserFromChat( DeleteUserFromChatCommand deleteUserFromChatCommand, CancellationToken cancellationToken) From 84ce91bd28506a94d5387d2561ce95e68753a5e0 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 18:38:52 +0300 Subject: [PATCH 36/45] fix: small api rules fix --- .../Extensions/ServiceCollectionExtensions.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs index 9ac1d0b..bbd209a 100644 --- a/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Source/Infrastructure/Do-Svyazi.User.Web.Api/Extensions/ServiceCollectionExtensions.cs @@ -48,7 +48,7 @@ public static IServiceCollection AddAuthServices(this IServiceCollection service options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = true, - ValidateAudience = true, + ValidateAudience = false, ValidAudience = configuration["JWT:ValidAudience"], ValidIssuer = configuration["JWT:ValidIssuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JWT:Secret"])), @@ -90,27 +90,27 @@ public static IServiceCollection AddSwaggerServices(this IServiceCollection serv Description = "Do Svyazi User API", }); - opt.AddSecurityDefinition("Bearer (value: SecretKey)", new OpenApiSecurityScheme + var securityScheme = new OpenApiSecurityScheme { Description = "JWT Authorization header using the bearer scheme", - Name = "Authorization", + Name = "JWT Authentication", In = ParameterLocation.Header, - Scheme = "Bearer", Type = SecuritySchemeType.Http, + Scheme = "Bearer", BearerFormat = "JWT", - }); + Reference = new OpenApiReference + { + Id = JwtBearerDefaults.AuthenticationScheme, + Type = ReferenceType.SecurityScheme, + }, + }; + + opt.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme); opt.AddSecurityRequirement(new OpenApiSecurityRequirement { { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Id = "Bearer (value: SecretKey)", - Type = ReferenceType.SecurityScheme, - }, - }, + securityScheme, new List() }, }); From 90fbca2f17983ccc8e09581c3090d5ba39e19751 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 19:22:49 +0300 Subject: [PATCH 37/45] chore: ApiClients updated with prettier classes and ctors --- .../Backend/Do-Svyazi.User.Client.cs | 575 ++++---- .../Backend/Do-Svyazi.User.Contracts.cs | 1239 ++++++++++++----- 2 files changed, 1152 insertions(+), 662 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs index a12f3d9..f910264 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs @@ -1,9 +1,11 @@ //---------------------- // -// Generated using the NSwag toolchain v13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// Generated using the NSwag toolchain v13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) // //---------------------- +#nullable enable + using Do_Svyazi.User.Web.ApiClient.Contracts; #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." @@ -19,8 +21,8 @@ namespace Do_Svyazi.User.Web.ApiClient { using System = global::System; - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - internal partial class AuthenticateClient : IAuthenticateClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AuthenticateClient : IAuthenticateClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -54,15 +56,17 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllAsync() + public virtual System.Threading.Tasks.Task> GetAllAsync() { return GetAllAsync(System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/GetAll"); @@ -74,7 +78,7 @@ public string BaseUrl using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -99,7 +103,7 @@ public string BaseUrl var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -114,13 +118,13 @@ public string BaseUrl { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -142,19 +146,18 @@ public string BaseUrl } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task LoginAsync(LoginRequest model) + public virtual System.Threading.Tasks.Task LoginAsync(LoginRequest? body) { - return LoginAsync(model, System.Threading.CancellationToken.None); + return LoginAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest model, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest? body, System.Threading.CancellationToken cancellationToken) { - if (model == null) - throw new System.ArgumentNullException("model"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/Login"); @@ -164,8 +167,8 @@ public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest model, { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -202,13 +205,13 @@ public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest model, { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -230,19 +233,18 @@ public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest model, } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task RegisterAsync(RegisterCommand model) + public virtual System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body) { - return RegisterAsync(model, System.Threading.CancellationToken.None); + return RegisterAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand model, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body, System.Threading.CancellationToken cancellationToken) { - if (model == null) - throw new System.ArgumentNullException("model"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/Register"); @@ -252,8 +254,8 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand m { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -290,13 +292,13 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand m { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -323,15 +325,17 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand m } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken) + public virtual System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken) { return AuthenticateByJwtAsync(jwtToken, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/AuthenticateByJwt"); @@ -343,11 +347,10 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand m using (var request_ = new System.Net.Http.HttpRequestMessage()) { - if (jwtToken == null) - throw new System.ArgumentNullException("jwtToken"); - request_.Headers.TryAddWithoutValidation("jwtToken", ConvertToString(jwtToken, System.Globalization.CultureInfo.InvariantCulture)); + if (jwtToken != null) + request_.Headers.TryAddWithoutValidation("jwtToken", ConvertToString(jwtToken, System.Globalization.CultureInfo.InvariantCulture)); request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -387,13 +390,13 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand m { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -415,19 +418,18 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand m } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model) + public virtual System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body) { - return RegisterAdminAsync(model, System.Threading.CancellationToken.None); + return RegisterAdminAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body, System.Threading.CancellationToken cancellationToken) { - if (model == null) - throw new System.ArgumentNullException("model"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/RegisterAdmin"); @@ -437,8 +439,8 @@ public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmi { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -475,13 +477,13 @@ public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmi { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -527,7 +529,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { if (response == null || response.Content == null) { - return new ObjectResponseResult(default(T), string.Empty); + return new ObjectResponseResult(default(T)!, string.Empty); } if (ReadResponseAsString) @@ -536,7 +538,7 @@ protected virtual async System.Threading.Tasks.Task> Rea try { var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); - return new ObjectResponseResult(typedBody, responseText); + return new ObjectResponseResult(typedBody!, responseText); } catch (Newtonsoft.Json.JsonException exception) { @@ -554,7 +556,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); var typedBody = serializer.Deserialize(jsonTextReader); - return new ObjectResponseResult(typedBody, string.Empty); + return new ObjectResponseResult(typedBody!, string.Empty); } } catch (Newtonsoft.Json.JsonException exception) @@ -565,7 +567,7 @@ protected virtual async System.Threading.Tasks.Task> Rea } } - private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + private string ConvertToString(object? value, System.Globalization.CultureInfo cultureInfo) { if (value == null) { @@ -611,8 +613,8 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - internal partial class ChatClient : IChatClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChatClient : IChatClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -646,15 +648,17 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetChatsAsync() + public virtual System.Threading.Tasks.Task> GetChatsAsync() { return GetChatsAsync(System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetChats"); @@ -666,7 +670,7 @@ public string BaseUrl using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -691,7 +695,7 @@ public string BaseUrl var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -706,13 +710,13 @@ public string BaseUrl { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -734,22 +738,24 @@ public string BaseUrl } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetChatByIdAsync(System.Guid chatId) + public virtual System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId) { return GetChatByIdAsync(chatId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetChatByIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken) { - if (chatId == null) - throw new System.ArgumentNullException("chatId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetChatById?"); - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (chatId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -759,7 +765,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -799,13 +805,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -827,22 +833,24 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId) + public virtual System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId) { return GetUserIdsByChatIdAsync(chatId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken) { - if (chatId == null) - throw new System.ArgumentNullException("chatId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetUserIdsByChatId?"); - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (chatId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -852,7 +860,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -877,7 +885,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -892,13 +900,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -920,22 +928,24 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId) + public virtual System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId) { return GetUsersByChatIdAsync(chatId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken) { - if (chatId == null) - throw new System.ArgumentNullException("chatId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetUsersByChatId?"); - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (chatId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -945,7 +955,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -970,7 +980,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -985,13 +995,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -1013,19 +1023,18 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand) + public virtual System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body) { - return AddChannelAsync(addChannelCommand, System.Threading.CancellationToken.None); + return AddChannelAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body, System.Threading.CancellationToken cancellationToken) { - if (addChannelCommand == null) - throw new System.ArgumentNullException("addChannelCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddChannel"); @@ -1035,8 +1044,8 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelComma { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addChannelCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1073,13 +1082,13 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelComma { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1106,19 +1115,18 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelComma } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand) + public virtual System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body) { - return AddGroupChatAsync(addGroupChatCommand, System.Threading.CancellationToken.None); + return AddGroupChatAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body, System.Threading.CancellationToken cancellationToken) { - if (addGroupChatCommand == null) - throw new System.ArgumentNullException("addGroupChatCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddGroupChat"); @@ -1128,8 +1136,8 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatC { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addGroupChatCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1166,13 +1174,13 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatC { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1199,19 +1207,18 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatC } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand) + public virtual System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body) { - return AddPersonalChatAsync(addPersonalChatCommand, System.Threading.CancellationToken.None); + return AddPersonalChatAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body, System.Threading.CancellationToken cancellationToken) { - if (addPersonalChatCommand == null) - throw new System.ArgumentNullException("addPersonalChatCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddPersonalChat"); @@ -1221,8 +1228,8 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addPersonalChatCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1259,13 +1266,13 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1292,19 +1299,18 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand) + public virtual System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body) { - return AddSavedMessagesAsync(addSavedMessagesCommand, System.Threading.CancellationToken.None); + return AddSavedMessagesAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body, System.Threading.CancellationToken cancellationToken) { - if (addSavedMessagesCommand == null) - throw new System.ArgumentNullException("addSavedMessagesCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddSavedMessages"); @@ -1314,8 +1320,8 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addSavedMessagesCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1352,13 +1358,13 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1385,19 +1391,18 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand) + public virtual System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body) { - return AddUserToChatAsync(addUserToChatCommand, System.Threading.CancellationToken.None); + return AddUserToChatAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body, System.Threading.CancellationToken cancellationToken) { - if (addUserToChatCommand == null) - throw new System.ArgumentNullException("addUserToChatCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddUserToChat"); @@ -1407,8 +1412,8 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addUserToChatCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1445,13 +1450,13 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -1478,19 +1483,18 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand) + public virtual System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body) { - return DeleteUserFromChatAsync(deleteUserFromChatCommand, System.Threading.CancellationToken.None); + return DeleteUserFromChatAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body, System.Threading.CancellationToken cancellationToken) { - if (deleteUserFromChatCommand == null) - throw new System.ArgumentNullException("deleteUserFromChatCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/DeleteUserFromChat"); @@ -1500,8 +1504,8 @@ public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteU { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(deleteUserFromChatCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("DELETE"); @@ -1538,13 +1542,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteU { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -1590,7 +1594,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { if (response == null || response.Content == null) { - return new ObjectResponseResult(default(T), string.Empty); + return new ObjectResponseResult(default(T)!, string.Empty); } if (ReadResponseAsString) @@ -1599,7 +1603,7 @@ protected virtual async System.Threading.Tasks.Task> Rea try { var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); - return new ObjectResponseResult(typedBody, responseText); + return new ObjectResponseResult(typedBody!, responseText); } catch (Newtonsoft.Json.JsonException exception) { @@ -1617,7 +1621,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); var typedBody = serializer.Deserialize(jsonTextReader); - return new ObjectResponseResult(typedBody, string.Empty); + return new ObjectResponseResult(typedBody!, string.Empty); } } catch (Newtonsoft.Json.JsonException exception) @@ -1628,7 +1632,7 @@ protected virtual async System.Threading.Tasks.Task> Rea } } - private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + private string ConvertToString(object? value, System.Globalization.CultureInfo cultureInfo) { if (value == null) { @@ -1674,8 +1678,8 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - internal partial class RolesClient : IRolesClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RolesClient : IRolesClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -1709,26 +1713,28 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId) + public virtual System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId) { return GetRoleByUserIdAsync(userId, chatId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId, System.Threading.CancellationToken cancellationToken) { - if (userId == null) - throw new System.ArgumentNullException("userId"); - - if (chatId == null) - throw new System.ArgumentNullException("chatId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/GetRoleByUserId?"); - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (userId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } + if (chatId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -1738,7 +1744,7 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -1778,13 +1784,13 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -1806,19 +1812,18 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand) + public virtual System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body) { - return CreateRoleForChatAsync(createRoleForChatCommand, System.Threading.CancellationToken.None); + return CreateRoleForChatAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body, System.Threading.CancellationToken cancellationToken) { - if (createRoleForChatCommand == null) - throw new System.ArgumentNullException("createRoleForChatCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/CreateRoleForChat"); @@ -1828,8 +1833,8 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(createRoleForChatCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1866,13 +1871,13 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -1899,19 +1904,18 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand) + public virtual System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body) { - return ChangeRoleForUserByIdAsync(changeRoleForUserByIdCommand, System.Threading.CancellationToken.None); + return ChangeRoleForUserByIdAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body, System.Threading.CancellationToken cancellationToken) { - if (changeRoleForUserByIdCommand == null) - throw new System.ArgumentNullException("changeRoleForUserByIdCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/ChangeRoleForUserById"); @@ -1921,8 +1925,8 @@ public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(Chan { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeRoleForUserByIdCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1959,13 +1963,13 @@ public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(Chan { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2011,7 +2015,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { if (response == null || response.Content == null) { - return new ObjectResponseResult(default(T), string.Empty); + return new ObjectResponseResult(default(T)!, string.Empty); } if (ReadResponseAsString) @@ -2020,7 +2024,7 @@ protected virtual async System.Threading.Tasks.Task> Rea try { var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); - return new ObjectResponseResult(typedBody, responseText); + return new ObjectResponseResult(typedBody!, responseText); } catch (Newtonsoft.Json.JsonException exception) { @@ -2038,7 +2042,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); var typedBody = serializer.Deserialize(jsonTextReader); - return new ObjectResponseResult(typedBody, string.Empty); + return new ObjectResponseResult(typedBody!, string.Empty); } } catch (Newtonsoft.Json.JsonException exception) @@ -2049,7 +2053,7 @@ protected virtual async System.Threading.Tasks.Task> Rea } } - private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + private string ConvertToString(object? value, System.Globalization.CultureInfo cultureInfo) { if (value == null) { @@ -2095,8 +2099,8 @@ private string ConvertToString(object value, System.Globalization.CultureInfo cu } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - internal partial class UserClient : IUserClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class UserClient : IUserClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -2130,15 +2134,17 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetUsersAsync() + public virtual System.Threading.Tasks.Task> GetAllAsync() { - return GetUsersAsync(System.Threading.CancellationToken.None); + return GetAllAsync(System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetUsersAsync(System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetAll"); @@ -2150,7 +2156,7 @@ public string BaseUrl using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -2175,7 +2181,7 @@ public string BaseUrl var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2190,13 +2196,13 @@ public string BaseUrl { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -2218,22 +2224,24 @@ public string BaseUrl } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetUserAsync(System.Guid userId) + public virtual System.Threading.Tasks.Task GetUserAsync(System.Guid? userId) { return GetUserAsync(userId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetUserAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken) { - if (userId == null) - throw new System.ArgumentNullException("userId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetUser?"); - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (userId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -2243,7 +2251,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -2283,13 +2291,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -2311,22 +2319,24 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId) + public virtual System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId) { return GetAllChatsByUserIdAsync(userId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken) { - if (userId == null) - throw new System.ArgumentNullException("userId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetAllChatsByUserId?"); - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (userId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -2336,7 +2346,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -2361,7 +2371,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2376,13 +2386,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -2404,22 +2414,24 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId) + public virtual System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId) { return GetAllChatsIdsByUserIdAsync(userId, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken) { - if (userId == null) - throw new System.ArgumentNullException("userId"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetAllChatsIdsByUserId?"); - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + if (userId != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + } urlBuilder_.Length--; var client_ = _httpClient; @@ -2429,7 +2441,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -2454,7 +2466,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2469,13 +2481,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else { @@ -2497,19 +2509,18 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand) + public virtual System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body) { - return SetNickNameByIdAsync(setUserNickNameByIdCommand, System.Threading.CancellationToken.None); + return SetNickNameByIdAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body, System.Threading.CancellationToken cancellationToken) { - if (setUserNickNameByIdCommand == null) - throw new System.ArgumentNullException("setUserNickNameByIdCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/SetNickNameById"); @@ -2519,8 +2530,8 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(setUserNickNameByIdCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2557,13 +2568,13 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2590,19 +2601,18 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand) + public virtual System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body) { - return DeleteUserAsync(deleteUserCommand, System.Threading.CancellationToken.None); + return DeleteUserAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body, System.Threading.CancellationToken cancellationToken) { - if (deleteUserCommand == null) - throw new System.ArgumentNullException("deleteUserCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/DeleteUser"); @@ -2612,8 +2622,8 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(deleteUserCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2650,13 +2660,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2683,19 +2693,18 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand) + public virtual System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body) { - return AddUserAsync(addUserCommand, System.Threading.CancellationToken.None); + return AddUserAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body, System.Threading.CancellationToken cancellationToken) { - if (addUserCommand == null) - throw new System.ArgumentNullException("addUserCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/AddUser"); @@ -2705,11 +2714,11 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addUserCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); PrepareRequest(client_, request_, urlBuilder_); @@ -2749,13 +2758,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -2787,19 +2796,18 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand) + public virtual System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body) { - return ChangeDescriptionAsync(changeUserDescriptionByIdCommand, System.Threading.CancellationToken.None); + return ChangeDescriptionAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body, System.Threading.CancellationToken cancellationToken) { - if (changeUserDescriptionByIdCommand == null) - throw new System.ArgumentNullException("changeUserDescriptionByIdCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/ChangeDescription"); @@ -2809,8 +2817,8 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserDescriptionByIdCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2847,13 +2855,13 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2880,19 +2888,18 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs } } + /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand) + public virtual System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body) { - return ChangeNameAsync(changeUserNameByIdCommand, System.Threading.CancellationToken.None); + return ChangeNameAsync(body, System.Threading.CancellationToken.None); } /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body, System.Threading.CancellationToken cancellationToken) { - if (changeUserNameByIdCommand == null) - throw new System.ArgumentNullException("changeUserNameByIdCommand"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/ChangeName"); @@ -2902,8 +2909,8 @@ public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameB { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserNameByIdCommand, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2940,13 +2947,13 @@ public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameB { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2992,7 +2999,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { if (response == null || response.Content == null) { - return new ObjectResponseResult(default(T), string.Empty); + return new ObjectResponseResult(default(T)!, string.Empty); } if (ReadResponseAsString) @@ -3001,7 +3008,7 @@ protected virtual async System.Threading.Tasks.Task> Rea try { var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); - return new ObjectResponseResult(typedBody, responseText); + return new ObjectResponseResult(typedBody!, responseText); } catch (Newtonsoft.Json.JsonException exception) { @@ -3019,7 +3026,7 @@ protected virtual async System.Threading.Tasks.Task> Rea { var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); var typedBody = serializer.Deserialize(jsonTextReader); - return new ObjectResponseResult(typedBody, string.Empty); + return new ObjectResponseResult(typedBody!, string.Empty); } } catch (Newtonsoft.Json.JsonException exception) @@ -3030,7 +3037,7 @@ protected virtual async System.Threading.Tasks.Task> Rea } } - private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + private string ConvertToString(object? value, System.Globalization.CultureInfo cultureInfo) { if (value == null) { diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs index 6133af7..3f27c6d 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs @@ -1,9 +1,11 @@ //---------------------- // -// Generated using the NSwag toolchain v13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// Generated using the NSwag toolchain v13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) // //---------------------- +#nullable enable + #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." #pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." #pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' @@ -16,224 +18,295 @@ namespace Do_Svyazi.User.Web.ApiClient.Contracts { using System = global::System; + + public interface IDoSvyaziClient {} - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IAuthenticateClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IAuthenticateClient : IDoSvyaziClient { + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllAsync(); + System.Threading.Tasks.Task> GetAllAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task LoginAsync(LoginRequest model); + System.Threading.Tasks.Task LoginAsync(LoginRequest? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task LoginAsync(LoginRequest model, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task LoginAsync(LoginRequest? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task RegisterAsync(RegisterCommand model); + System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task RegisterAsync(RegisterCommand model, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken); + System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AuthenticateByJwtAsync(string jwtToken, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model); + System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body, System.Threading.CancellationToken cancellationToken); } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IChatClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IChatClient : IDoSvyaziClient { + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetChatsAsync(); + System.Threading.Tasks.Task> GetChatsAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetChatByIdAsync(System.Guid chatId); + System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetChatByIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId); + System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId); + System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand); + System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand); + System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand); + System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand); + System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand); + System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand); + System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body, System.Threading.CancellationToken cancellationToken); } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IRolesClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IRolesClient : IDoSvyaziClient { + /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId); + System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand); + System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand); + System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body, System.Threading.CancellationToken cancellationToken); } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IUserClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IUserClient : IDoSvyaziClient { + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersAsync(); + System.Threading.Tasks.Task> GetAllAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersAsync(System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetUserAsync(System.Guid userId); + System.Threading.Tasks.Task GetUserAsync(System.Guid? userId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task GetUserAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId); + System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId); + System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand); + System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand); + System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand); + System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand); + System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body, System.Threading.CancellationToken cancellationToken); + /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand); + System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body, System.Threading.CancellationToken cancellationToken); } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerUser : IdentityUserOfGuid + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddChannelCommand { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public AddChannelCommand(System.Guid @adminId, string? @description, string? @name) + + { + + this.AdminId = @adminId; + + this.Name = @name; + + this.Description = @description; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + } [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid AdminId { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -241,62 +314,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerUser FromJson(string data) + public static AddChannelCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class IdentityUserOfGuid + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddGroupChatCommand { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } - - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string UserName { get; set; } - - [Newtonsoft.Json.JsonProperty("normalizedUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string NormalizedUserName { get; set; } - - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Email { get; set; } - - [Newtonsoft.Json.JsonProperty("normalizedEmail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string NormalizedEmail { get; set; } - - [Newtonsoft.Json.JsonProperty("emailConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool EmailConfirmed { get; set; } - - [Newtonsoft.Json.JsonProperty("passwordHash", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string PasswordHash { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("securityStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string SecurityStamp { get; set; } + public AddGroupChatCommand(System.Guid @adminId, string? @description, string? @name) - [Newtonsoft.Json.JsonProperty("concurrencyStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string ConcurrencyStamp { get; set; } + { - [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string PhoneNumber { get; set; } + this.AdminId = @adminId; - [Newtonsoft.Json.JsonProperty("phoneNumberConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool PhoneNumberConfirmed { get; set; } + this.Name = @name; - [Newtonsoft.Json.JsonProperty("twoFactorEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool TwoFactorEnabled { get; set; } + this.Description = @description; - [Newtonsoft.Json.JsonProperty("lockoutEnd", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.DateTime? LockoutEnd { get; set; } + } [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid AdminId { get; } - [Newtonsoft.Json.JsonProperty("lockoutEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool LockoutEnabled { get; set; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } - [Newtonsoft.Json.JsonProperty("accessFailedCount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int AccessFailedCount { get; set; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -304,44 +353,43 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static IdentityUserOfGuid FromJson(string data) + public static AddGroupChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ProblemDetails + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddPersonalChatCommand { - [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Type { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Title { get; set; } + public AddPersonalChatCommand(string? @description, System.Guid @firstUserId, string? @name, System.Guid @secondUserId) - [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int? Status { get; set; } + { - [Newtonsoft.Json.JsonProperty("detail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Detail { get; set; } + this.FirstUserId = @firstUserId; - [Newtonsoft.Json.JsonProperty("instance", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Instance { get; set; } + this.SecondUserId = @secondUserId; - [Newtonsoft.Json.JsonProperty("extensions", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.Generic.Dictionary Extensions { get; set; } + this.Name = @name; - private System.Collections.Generic.IDictionary _additionalProperties = new System.Collections.Generic.Dictionary(); + this.Description = @description; - [Newtonsoft.Json.JsonExtensionData] - public System.Collections.Generic.IDictionary AdditionalProperties - { - get { return _additionalProperties; } - set { _additionalProperties = value; } - } + } [Newtonsoft.Json.JsonProperty("firstUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid FirstUserId { get; } + + [Newtonsoft.Json.JsonProperty("secondUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid SecondUserId { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -349,47 +397,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ProblemDetails FromJson(string data) + public static AddPersonalChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class LoginRequest + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddSavedMessagesCommand { - [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public LoginModel Model { get; set; } + [Newtonsoft.Json.JsonConstructor] - public string ToJson() - { - - return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + public AddSavedMessagesCommand(string? @description, string? @name, System.Guid @userId) - } - public static LoginRequest FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + this.UserId = @userId; - } + this.Name = @name; - } + this.Description = @description; - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class LoginModel - { - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string UserName { get; set; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Email { get; set; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } - [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] - public string Password { get; set; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -397,20 +436,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static LoginModel FromJson(string data) + public static AddSavedMessagesCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddUserCommand { - [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RegisterModel Model { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public AddUserCommand(string? @description, string? @name, string? @nickName) + + { + + this.Name = @name; + + this.NickName = @nickName; + + this.Description = @description; + + } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? NickName { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -418,32 +475,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterCommand FromJson(string data) + public static AddUserCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterModel + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddUserToChatCommand { - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Always)] - public string UserName { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + public AddUserToChatCommand(System.Guid @chatId, System.Guid @userId) - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] - public string Email { get; set; } + { - [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] - public string Password { get; set; } + this.UserId = @userId; + + this.ChatId = @chatId; - [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string PhoneNumber { get; set; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } + + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } public string ToJson() { @@ -451,20 +509,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterModel FromJson(string data) + public static AddUserToChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterAdminCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChangeRoleForUserByIdCommand { - [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RegisterModel Model { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public ChangeRoleForUserByIdCommand(System.Guid @chatId, RoleDto @role, System.Guid @userId) + + { + + this.UserId = @userId; + + this.ChatId = @chatId; + + this.Role = @role; + + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } + + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } + + [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDto Role { get; } public string ToJson() { @@ -472,32 +548,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterAdminCommand FromJson(string data) + public static ChangeRoleForUserByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerChatDto + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChangeUserDescriptionByIdCommand { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + public ChangeUserDescriptionByIdCommand(string? @description, System.Guid @userId) - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + { + + this.UserId = @userId; + + this.Description = @description; - [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Users { get; set; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("roles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.ObjectModel.ObservableCollection Roles { get; set; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -505,53 +582,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerChatDto FromJson(string data) + public static ChangeUserDescriptionByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RoleDto + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChangeUserNameByIdCommand { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } - - [Newtonsoft.Json.JsonProperty("canEditMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanEditMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canDeleteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canWriteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanWriteMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canReadMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanReadMessages { get; set; } - - [Newtonsoft.Json.JsonProperty("canAddUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanAddUsers { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("canDeleteUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteUsers { get; set; } + public ChangeUserNameByIdCommand(string? @name, System.Guid @userId) - [Newtonsoft.Json.JsonProperty("canPinMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanPinMessages { get; set; } + { - [Newtonsoft.Json.JsonProperty("canSeeChannelMembers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanSeeChannelMembers { get; set; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("canInviteOtherUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanInviteOtherUsers { get; set; } + this.Name = @name; - [Newtonsoft.Json.JsonProperty("canEditChannelDescription", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanEditChannelDescription { get; set; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("canDeleteChat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteChat { get; set; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } public string ToJson() { @@ -559,38 +616,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RoleDto FromJson(string data) + public static ChangeUserNameByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public enum ActionOption + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChatUserDto { + [Newtonsoft.Json.JsonConstructor] - Unavailable = 0, + public ChatUserDto(string? @chatUserName, System.Guid @messengerUserId, RoleDto @role) - Enabled = 1, + { - Disabled = 2, + this.ChatUserName = @chatUserName; - } + this.MessengerUserId = @messengerUserId; - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChatUserDto - { - [Newtonsoft.Json.JsonProperty("chatUserName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string ChatUserName { get; set; } + this.Role = @role; + + } [Newtonsoft.Json.JsonProperty("chatUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? ChatUserName { get; } [Newtonsoft.Json.JsonProperty("messengerUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid MessengerUserId { get; set; } + public System.Guid MessengerUserId { get; } [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDto Role { get; set; } + public RoleDto Role { get; } public string ToJson() { @@ -607,17 +664,24 @@ public static ChatUserDto FromJson(string data) } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddChannelCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CreateRoleForChatCommand { - [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid AdminId { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public CreateRoleForChatCommand(System.Guid @chatId, RoleDto @role) + + { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + this.Role = @role; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + this.ChatId = @chatId; + + } [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDto Role { get; } + + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } public string ToJson() { @@ -625,26 +689,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddChannelCommand FromJson(string data) + public static CreateRoleForChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddGroupChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class DeleteUserCommand { - [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid AdminId { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public DeleteUserCommand(System.Guid @userId) + + { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } public string ToJson() { @@ -652,29 +718,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddGroupChatCommand FromJson(string data) + public static DeleteUserCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddPersonalChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class DeleteUserFromChatCommand { - [Newtonsoft.Json.JsonProperty("firstUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid FirstUserId { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("secondUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid SecondUserId { get; set; } + public DeleteUserFromChatCommand(System.Guid @chatId, System.Guid @userId) + + { + + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + this.ChatId = @chatId; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } + + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } public string ToJson() { @@ -682,26 +752,39 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddPersonalChatCommand FromJson(string data) + public static DeleteUserFromChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddSavedMessagesCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class LoginModel { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public LoginModel(string? @email, string @password, string? @userName) + + { + + this.UserName = @userName; + + this.Email = @email; + + this.Password = @password; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? UserName { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Email { get; } + + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Password { get; } public string ToJson() { @@ -709,23 +792,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddSavedMessagesCommand FromJson(string data) + public static LoginModel FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddUserToChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class LoginRequest { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; set; } + public LoginRequest(LoginModel @model) + + { + + this.Model = @model; + + } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public LoginModel Model { get; } public string ToJson() { @@ -733,47 +821,48 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddUserToChatCommand FromJson(string data) + public static LoginRequest FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class DeleteUserFromChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class MessengerChatDto { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; set; } + public MessengerChatDto(string? @description, System.Guid @id, string? @name, System.Collections.Generic.ICollection? @roles, System.Collections.Generic.ICollection? @users) - public string ToJson() { - return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + this.Id = @id; - } - public static DeleteUserFromChatCommand FromJson(string data) - { + this.Name = @name; - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + this.Description = @description; - } + this.Users = @users; - } + this.Roles = @roles; - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class CreateRoleForChatCommand - { - [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDto Role { get; set; } + } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; } - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; set; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } + + [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.Generic.ICollection? Users { get; } + + [Newtonsoft.Json.JsonProperty("roles", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.Generic.ICollection? Roles { get; } public string ToJson() { @@ -781,26 +870,108 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static CreateRoleForChatCommand FromJson(string data) + public static MessengerChatDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeRoleForUserByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class MessengerUser { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; set; } + public MessengerUser(int @accessFailedCount, string? @concurrencyStamp, string? @description, string? @email, bool @emailConfirmed, System.Guid @id, bool @lockoutEnabled, System.DateTimeOffset? @lockoutEnd, string? @name, string? @normalizedEmail, string? @normalizedUserName, string? @passwordHash, string? @phoneNumber, bool @phoneNumberConfirmed, string? @securityStamp, bool @twoFactorEnabled, string? @userName) - [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDto Role { get; set; } + { + + this.Id = @id; + + this.UserName = @userName; + + this.NormalizedUserName = @normalizedUserName; + + this.Email = @email; + + this.NormalizedEmail = @normalizedEmail; + + this.EmailConfirmed = @emailConfirmed; + + this.PasswordHash = @passwordHash; + + this.SecurityStamp = @securityStamp; + + this.ConcurrencyStamp = @concurrencyStamp; + + this.PhoneNumber = @phoneNumber; + + this.PhoneNumberConfirmed = @phoneNumberConfirmed; + + this.TwoFactorEnabled = @twoFactorEnabled; + + this.LockoutEnd = @lockoutEnd; + + this.LockoutEnabled = @lockoutEnabled; + + this.AccessFailedCount = @accessFailedCount; + + this.Name = @name; + + this.Description = @description; + + } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; } + + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? UserName { get; } + + [Newtonsoft.Json.JsonProperty("normalizedUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? NormalizedUserName { get; } + + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Email { get; } + + [Newtonsoft.Json.JsonProperty("normalizedEmail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? NormalizedEmail { get; } + + [Newtonsoft.Json.JsonProperty("emailConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool EmailConfirmed { get; } + + [Newtonsoft.Json.JsonProperty("passwordHash", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? PasswordHash { get; } + + [Newtonsoft.Json.JsonProperty("securityStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? SecurityStamp { get; } + + [Newtonsoft.Json.JsonProperty("concurrencyStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? ConcurrencyStamp { get; } + + [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? PhoneNumber { get; } + + [Newtonsoft.Json.JsonProperty("phoneNumberConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool PhoneNumberConfirmed { get; } + + [Newtonsoft.Json.JsonProperty("twoFactorEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool TwoFactorEnabled { get; } + + [Newtonsoft.Json.JsonProperty("lockoutEnd", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset? LockoutEnd { get; } + + [Newtonsoft.Json.JsonProperty("lockoutEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool LockoutEnabled { get; } + + [Newtonsoft.Json.JsonProperty("accessFailedCount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int AccessFailedCount { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -808,29 +979,43 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeRoleForUserByIdCommand FromJson(string data) + public static MessengerUser FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] public partial class MessengerUserDto { - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public MessengerUserDto(string? @description, System.Guid @id, string? @name, string? @userName) + + { + + this.Id = @id; + + this.Name = @name; + + this.UserName = @userName; + + this.Description = @description; + + } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + public string? Name { get; } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string UserName { get; set; } + public string? UserName { get; } [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + public string? Description { get; } public string ToJson() { @@ -847,14 +1032,48 @@ public static MessengerUserDto FromJson(string data) } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class SetUserNickNameByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ProblemDetails { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public ProblemDetails(string? @detail, string? @instance, int? @status, string? @title, string? @type) + + { + + this.Type = @type; + + this.Title = @title; + + this.Status = @status; + + this.Detail = @detail; + + this.Instance = @instance; + + } [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Type { get; } + + [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Title { get; } - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string UserName { get; set; } + [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int? Status { get; } + + [Newtonsoft.Json.JsonProperty("detail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Detail { get; } + + [Newtonsoft.Json.JsonProperty("instance", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Instance { get; } + + private System.Collections.Generic.IDictionary _additionalProperties = new System.Collections.Generic.Dictionary(); + + [Newtonsoft.Json.JsonExtensionData] + public System.Collections.Generic.IDictionary AdditionalProperties + { + get { return _additionalProperties; } + set { _additionalProperties = value; } + } public string ToJson() { @@ -862,20 +1081,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static SetUserNickNameByIdCommand FromJson(string data) + public static ProblemDetails FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class DeleteUserCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RegisterAdminCommand { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public RegisterAdminCommand(RegisterModel @model) + + { + + this.Model = @model; + + } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RegisterModel Model { get; } public string ToJson() { @@ -883,26 +1110,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static DeleteUserCommand FromJson(string data) + public static RegisterAdminCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddUserCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RegisterCommand { - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string NickName { get; set; } + public RegisterCommand(RegisterModel @model) - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + { + + this.Model = @model; + + } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RegisterModel Model { get; } public string ToJson() { @@ -910,23 +1139,51 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddUserCommand FromJson(string data) + public static RegisterCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeUserDescriptionByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RegisterModel { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] + + public RegisterModel(string @email, string? @name, string @password, string? @phoneNumber, string @userName) + + { + + this.UserName = @userName; + + this.Name = @name; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Description { get; set; } + this.Email = @email; + + this.Password = @password; + + this.PhoneNumber = @phoneNumber; + + } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string UserName { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Email { get; } + + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Password { get; } + + [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? PhoneNumber { get; } public string ToJson() { @@ -934,23 +1191,83 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeUserDescriptionByIdCommand FromJson(string data) + public static RegisterModel FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeUserNameByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RoleDto { - [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; set; } + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Name { get; set; } + public RoleDto(RoleDtoCanAddUsers @canAddUsers, RoleDtoCanDeleteChat @canDeleteChat, RoleDtoCanDeleteMessages @canDeleteMessages, RoleDtoCanDeleteUsers @canDeleteUsers, RoleDtoCanEditChannelDescription @canEditChannelDescription, RoleDtoCanEditMessages @canEditMessages, RoleDtoCanInviteOtherUsers @canInviteOtherUsers, RoleDtoCanPinMessages @canPinMessages, RoleDtoCanReadMessages @canReadMessages, RoleDtoCanSeeChannelMembers @canSeeChannelMembers, RoleDtoCanWriteMessages @canWriteMessages, string? @name) + + { + + this.Name = @name; + + this.CanEditMessages = @canEditMessages; + + this.CanDeleteMessages = @canDeleteMessages; + + this.CanWriteMessages = @canWriteMessages; + + this.CanReadMessages = @canReadMessages; + + this.CanAddUsers = @canAddUsers; + + this.CanDeleteUsers = @canDeleteUsers; + + this.CanPinMessages = @canPinMessages; + + this.CanSeeChannelMembers = @canSeeChannelMembers; + + this.CanInviteOtherUsers = @canInviteOtherUsers; + + this.CanEditChannelDescription = @canEditChannelDescription; + + this.CanDeleteChat = @canDeleteChat; + + } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("canEditMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanEditMessages CanEditMessages { get; } + + [Newtonsoft.Json.JsonProperty("canDeleteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanDeleteMessages CanDeleteMessages { get; } + + [Newtonsoft.Json.JsonProperty("canWriteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanWriteMessages CanWriteMessages { get; } + + [Newtonsoft.Json.JsonProperty("canReadMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanReadMessages CanReadMessages { get; } + + [Newtonsoft.Json.JsonProperty("canAddUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanAddUsers CanAddUsers { get; } + + [Newtonsoft.Json.JsonProperty("canDeleteUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanDeleteUsers CanDeleteUsers { get; } + + [Newtonsoft.Json.JsonProperty("canPinMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanPinMessages CanPinMessages { get; } + + [Newtonsoft.Json.JsonProperty("canSeeChannelMembers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanSeeChannelMembers CanSeeChannelMembers { get; } + + [Newtonsoft.Json.JsonProperty("canInviteOtherUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanInviteOtherUsers CanInviteOtherUsers { get; } + + [Newtonsoft.Json.JsonProperty("canEditChannelDescription", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanEditChannelDescription CanEditChannelDescription { get; } + + [Newtonsoft.Json.JsonProperty("canDeleteChat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDtoCanDeleteChat CanDeleteChat { get; } public string ToJson() { @@ -958,27 +1275,193 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeUserNameByIdCommand FromJson(string data) + public static RoleDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SetUserNickNameByIdCommand + { + [Newtonsoft.Json.JsonConstructor] + + public SetUserNickNameByIdCommand(System.Guid @userId, string? @userName) + + { + + this.UserId = @userId; + + this.UserName = @userName; + + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } + + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? UserName { get; } + + public string ToJson() + { + + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + + } + public static SetUserNickNameByIdCommand FromJson(string data) + { + + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanAddUsers + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanDeleteChat + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanDeleteMessages + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanDeleteUsers + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanEditChannelDescription + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanEditMessages + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanInviteOtherUsers + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanPinMessages + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanReadMessages + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanSeeChannelMembers + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum RoleDtoCanWriteMessages + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] public partial class Do_Svyazi_User_ApiClient_Exception : System.Exception { public int StatusCode { get; private set; } - public string Response { get; private set; } + public string? Response { get; private set; } public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } - public Do_Svyazi_User_ApiClient_Exception(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + public Do_Svyazi_User_ApiClient_Exception(string message, int statusCode, string? response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception? innerException) : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) { StatusCode = statusCode; @@ -992,12 +1475,12 @@ public override string ToString() } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] public partial class Do_Svyazi_User_ApiClient_Exception : Do_Svyazi_User_ApiClient_Exception { public TResult Result { get; private set; } - public Do_Svyazi_User_ApiClient_Exception(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + public Do_Svyazi_User_ApiClient_Exception(string message, int statusCode, string? response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception? innerException) : base(message, statusCode, response, headers, innerException) { Result = result; From cd0ecd08421ee5fb7e4411c9234b90cc86fb08d3 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sun, 26 Jun 2022 19:31:02 +0300 Subject: [PATCH 38/45] chore: small fixes in ApiClients --- .../Backend/Do-Svyazi.User.Client.cs | 6 +- .../Backend/Do-Svyazi.User.Contracts.cs | 194 +++++------------- 2 files changed, 56 insertions(+), 144 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs index f910264..de46ed5 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs @@ -327,7 +327,7 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? /// Success /// A server side error occurred. - public virtual System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken) + public virtual System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken) { return AuthenticateByJwtAsync(jwtToken, System.Threading.CancellationToken.None); } @@ -335,7 +335,7 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/AuthenticateByJwt"); @@ -375,7 +375,7 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs index 3f27c6d..94b1595 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs @@ -53,12 +53,12 @@ public partial interface IAuthenticateClient : IDoSvyaziClient /// Success /// A server side error occurred. - System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken); + System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// Success /// A server side error occurred. - System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken); /// Success /// A server side error occurred. @@ -518,6 +518,40 @@ public static AddUserToChatCommand FromJson(string data) } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AuthenticateResponse + { + [Newtonsoft.Json.JsonConstructor] + + public AuthenticateResponse(System.Guid @userId, System.DateTimeOffset @validTo) + + { + + this.UserId = @userId; + + this.ValidTo = @validTo; + + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } + + [Newtonsoft.Json.JsonProperty("validTo", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset ValidTo { get; } + + public string ToJson() + { + + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + + } + public static AuthenticateResponse FromJson(string data) + { + + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + + } + + } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] public partial class ChangeRoleForUserByIdCommand { @@ -1205,7 +1239,7 @@ public partial class RoleDto { [Newtonsoft.Json.JsonConstructor] - public RoleDto(RoleDtoCanAddUsers @canAddUsers, RoleDtoCanDeleteChat @canDeleteChat, RoleDtoCanDeleteMessages @canDeleteMessages, RoleDtoCanDeleteUsers @canDeleteUsers, RoleDtoCanEditChannelDescription @canEditChannelDescription, RoleDtoCanEditMessages @canEditMessages, RoleDtoCanInviteOtherUsers @canInviteOtherUsers, RoleDtoCanPinMessages @canPinMessages, RoleDtoCanReadMessages @canReadMessages, RoleDtoCanSeeChannelMembers @canSeeChannelMembers, RoleDtoCanWriteMessages @canWriteMessages, string? @name) + public RoleDto(ActionOption @canAddUsers, ActionOption @canDeleteChat, ActionOption @canDeleteMessages, ActionOption @canDeleteUsers, ActionOption @canEditChannelDescription, ActionOption @canEditMessages, ActionOption @canInviteOtherUsers, ActionOption @canPinMessages, ActionOption @canReadMessages, ActionOption @canSeeChannelMembers, ActionOption @canWriteMessages, string? @name) { @@ -1237,37 +1271,37 @@ public RoleDto(RoleDtoCanAddUsers @canAddUsers, RoleDtoCanDeleteChat @canDeleteC public string? Name { get; } [Newtonsoft.Json.JsonProperty("canEditMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanEditMessages CanEditMessages { get; } + public ActionOption CanEditMessages { get; } [Newtonsoft.Json.JsonProperty("canDeleteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanDeleteMessages CanDeleteMessages { get; } + public ActionOption CanDeleteMessages { get; } [Newtonsoft.Json.JsonProperty("canWriteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanWriteMessages CanWriteMessages { get; } + public ActionOption CanWriteMessages { get; } [Newtonsoft.Json.JsonProperty("canReadMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanReadMessages CanReadMessages { get; } + public ActionOption CanReadMessages { get; } [Newtonsoft.Json.JsonProperty("canAddUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanAddUsers CanAddUsers { get; } + public ActionOption CanAddUsers { get; } [Newtonsoft.Json.JsonProperty("canDeleteUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanDeleteUsers CanDeleteUsers { get; } + public ActionOption CanDeleteUsers { get; } [Newtonsoft.Json.JsonProperty("canPinMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanPinMessages CanPinMessages { get; } + public ActionOption CanPinMessages { get; } [Newtonsoft.Json.JsonProperty("canSeeChannelMembers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanSeeChannelMembers CanSeeChannelMembers { get; } + public ActionOption CanSeeChannelMembers { get; } [Newtonsoft.Json.JsonProperty("canInviteOtherUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanInviteOtherUsers CanInviteOtherUsers { get; } + public ActionOption CanInviteOtherUsers { get; } [Newtonsoft.Json.JsonProperty("canEditChannelDescription", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanEditChannelDescription CanEditChannelDescription { get; } + public ActionOption CanEditChannelDescription { get; } [Newtonsoft.Json.JsonProperty("canDeleteChat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDtoCanDeleteChat CanDeleteChat { get; } + public ActionOption CanDeleteChat { get; } public string ToJson() { @@ -1318,140 +1352,18 @@ public static SetUserNickNameByIdCommand FromJson(string data) } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanAddUsers - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanDeleteChat - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanDeleteMessages - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanDeleteUsers - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanEditChannelDescription - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanEditMessages - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanInviteOtherUsers + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public enum ActionOption { - _0 = 0, + Unavailable = 0, - _1 = 1, + Enabled = 1, - _2 = 2, + Disabled = 2, } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanPinMessages - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanReadMessages - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanSeeChannelMembers - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public enum RoleDtoCanWriteMessages - { - - _0 = 0, - - _1 = 1, - - _2 = 2, - - } - - - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] public partial class Do_Svyazi_User_ApiClient_Exception : System.Exception { From 65f40331305778a6fd96836ec5ea66a9f6106009 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:09:35 +0300 Subject: [PATCH 39/45] chore: `nswag` configuration updated --- .../Do-Svyazi.User.Web.ApiClient/nswag.json | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json index 5b16940..eec5f08 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json @@ -57,25 +57,25 @@ }, "codeGenerators": { "openApiToCSharpClient": { - "clientBaseClass": null, + "clientBaseClass": "Do_SvyaziClientBase", "configurationClass": null, "generateClientClasses": true, "generateClientInterfaces": true, "clientBaseInterface": null, "injectHttpClient": true, - "disposeHttpClient": false, + "disposeHttpClient": true, "protectedMethods": [], "generateExceptionClasses": true, "exceptionClass": "Do_Svyazi_User_ApiClient_Exception", "wrapDtoExceptions": true, "useHttpClientCreationMethod": false, "httpClientType": "System.Net.Http.HttpClient", - "useHttpRequestMessageCreationMethod": false, + "useHttpRequestMessageCreationMethod": true, "useBaseUrl": true, "generateBaseUrlProperty": true, "generateSyncMethods": false, "exposeJsonSerializerSettings": false, - "clientClassAccessModifier": "internal", + "clientClassAccessModifier": "public", "typeAccessModifier": "public", "generateContractsOutput": true, "contractsNamespace": "Do_Svyazi.User.Web.ApiClient.Contracts", @@ -88,14 +88,14 @@ "queryNullValue": "", "className": "{controller}Client", "operationGenerationMode": "MultipleClientsFromOperationId", - "additionalNamespaceUsages": [], - "additionalContractNamespaceUsages": [], - "generateOptionalParameters": false, + "additionalNamespaceUsages": ["Do_Svyazi.User.Web.ApiClient.Backend"], + "additionalContractNamespaceUsages": ["Do_Svyazi.User.Web.ApiClient.Backend"], + "generateOptionalParameters": true, "generateJsonMethods": true, "enforceFlagEnums": false, "parameterArrayType": "System.Collections.Generic.IEnumerable", "parameterDictionaryType": "System.Collections.Generic.IDictionary", - "responseArrayType": "System.Collections.ObjectModel.ObservableCollection", + "responseArrayType": "System.Collections.Generic.IReadOnlyList", "responseDictionaryType": "System.Collections.Generic.Dictionary", "wrapResponses": false, "wrapResponseMethods": [], @@ -115,7 +115,7 @@ "dictionaryInstanceType": "System.Collections.Generic.Dictionary", "arrayBaseType": "System.Collections.ObjectModel.ObservableCollection", "dictionaryBaseType": "System.Collections.Generic.Dictionary", - "classStyle": "Poco", + "classStyle": "Record", "generateDefaultValues": true, "generateDataAnnotations": false, "excludedTypeNames": [], @@ -130,7 +130,7 @@ "inlineNamedAny": false, "generateDtoTypes": true, "generateOptionalPropertiesAsNullable": false, - "generateNullableReferenceTypes": false, + "generateNullableReferenceTypes": true, "templateDirectory": null, "typeNameGeneratorType": null, "propertyNameGeneratorType": null, @@ -157,9 +157,9 @@ "generateClientInterfaces": true, "generateOptionalParameters": true, "exportTypes": true, - "wrapDtoExceptions": false, + "wrapDtoExceptions": true, "exceptionClass": "Do_Svyazi_User_ApiClient_Exception", - "clientBaseClass": "", + "clientBaseClass": null, "wrapResponses": false, "wrapResponseMethods": [], "generateResponseClasses": true, From 132afc320f60ab53fa027b9eebed4ea00be76189 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:09:52 +0300 Subject: [PATCH 40/45] chore: ApiClients updated --- .../Backend/Do-Svyazi.User.Client.cs | 670 ++++------ .../Backend/Do-Svyazi.User.Contracts.cs | 1174 ++++++++--------- .../Frontend/do-svyazi.user.clients.ts | 56 +- .../Frontend/package-lock.json | 15 +- .../Frontend/package.json | 12 +- .../{openApiContracts.json => swagger.json} | 17 +- 6 files changed, 867 insertions(+), 1077 deletions(-) rename Source/Presentation/Do-Svyazi.User.Web.ApiClient/{openApiContracts.json => swagger.json} (99%) diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs index de46ed5..0e01add 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Client.cs @@ -1,11 +1,12 @@ //---------------------- // -// Generated using the NSwag toolchain v13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// Generated using the NSwag toolchain v13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) // //---------------------- #nullable enable +using Do_Svyazi.User.Web.ApiClient.Backend; using Do_Svyazi.User.Web.ApiClient.Contracts; #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." @@ -21,8 +22,8 @@ namespace Do_Svyazi.User.Web.ApiClient { using System = global::System; - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AuthenticateClient : IAuthenticateClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AuthenticateClient : Do_SvyaziClientBase, IAuthenticateClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -56,17 +57,9 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllAsync() - { - return GetAllAsync(System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/GetAll"); @@ -75,10 +68,10 @@ public string BaseUrl var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -103,7 +96,7 @@ public string BaseUrl var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -118,13 +111,13 @@ public string BaseUrl { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -146,18 +139,13 @@ public string BaseUrl } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task LoginAsync(LoginRequest? body) - { - return LoginAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest model, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (model == null) + throw new System.ArgumentNullException("model"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/Login"); @@ -165,10 +153,10 @@ public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest? body, var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -205,13 +193,13 @@ public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest? body, { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -233,18 +221,13 @@ public virtual async System.Threading.Tasks.Task LoginAsync(LoginRequest? body, } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body) - { - return RegisterAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand model, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (model == null) + throw new System.ArgumentNullException("model"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/Register"); @@ -252,10 +235,10 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -292,13 +275,13 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -325,17 +308,9 @@ public virtual async System.Threading.Tasks.Task RegisterAsync(RegisterCommand? } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken) - { - return AuthenticateByJwtAsync(jwtToken, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/AuthenticateByJwt"); @@ -344,13 +319,14 @@ public virtual async System.Threading.Tasks.Task Authentic var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - if (jwtToken != null) - request_.Headers.TryAddWithoutValidation("jwtToken", ConvertToString(jwtToken, System.Globalization.CultureInfo.InvariantCulture)); + if (jwtToken == null) + throw new System.ArgumentNullException("jwtToken"); + request_.Headers.TryAddWithoutValidation("jwtToken", ConvertToString(jwtToken, System.Globalization.CultureInfo.InvariantCulture)); request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -390,13 +366,13 @@ public virtual async System.Threading.Tasks.Task Authentic { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -418,18 +394,13 @@ public virtual async System.Threading.Tasks.Task Authentic } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body) - { - return RegisterAdminAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (model == null) + throw new System.ArgumentNullException("model"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Authenticate/RegisterAdmin"); @@ -437,10 +408,10 @@ public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmi var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -477,13 +448,13 @@ public virtual async System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdmi { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -613,8 +584,8 @@ private string ConvertToString(object? value, System.Globalization.CultureInfo c } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChatClient : IChatClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChatClient : Do_SvyaziClientBase, IChatClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -648,17 +619,9 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetChatsAsync() - { - return GetChatsAsync(System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetChats"); @@ -667,10 +630,10 @@ public string BaseUrl var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -695,7 +658,7 @@ public string BaseUrl var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -710,13 +673,13 @@ public string BaseUrl { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -738,34 +701,26 @@ public string BaseUrl } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId) - { - return GetChatByIdAsync(chatId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetChatByIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (chatId == null) + throw new System.ArgumentNullException("chatId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetChatById?"); - if (chatId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -805,13 +760,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -833,34 +788,26 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId) - { - return GetUserIdsByChatIdAsync(chatId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (chatId == null) + throw new System.ArgumentNullException("chatId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetUserIdsByChatId?"); - if (chatId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -885,7 +832,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -900,13 +847,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -928,34 +875,26 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId) - { - return GetUsersByChatIdAsync(chatId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (chatId == null) + throw new System.ArgumentNullException("chatId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/GetUsersByChatId?"); - if (chatId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -980,7 +919,7 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -995,13 +934,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -1023,18 +962,13 @@ public virtual async System.Threading.Tasks.Task GetChatByIdAs } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body) - { - return AddChannelAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (addChannelCommand == null) + throw new System.ArgumentNullException("addChannelCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddChannel"); @@ -1042,10 +976,10 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelComma var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addChannelCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1082,13 +1016,13 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelComma { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1115,18 +1049,13 @@ public virtual async System.Threading.Tasks.Task AddChannelAsync(AddChannelComma } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body) - { - return AddGroupChatAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (addGroupChatCommand == null) + throw new System.ArgumentNullException("addGroupChatCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddGroupChat"); @@ -1134,10 +1063,10 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatC var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addGroupChatCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1174,13 +1103,13 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatC { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1207,18 +1136,13 @@ public virtual async System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatC } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body) - { - return AddPersonalChatAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (addPersonalChatCommand == null) + throw new System.ArgumentNullException("addPersonalChatCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddPersonalChat"); @@ -1226,10 +1150,10 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addPersonalChatCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1266,13 +1190,13 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1299,18 +1223,13 @@ public virtual async System.Threading.Tasks.Task AddPersonalChatAsync(AddPersona } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body) - { - return AddSavedMessagesAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (addSavedMessagesCommand == null) + throw new System.ArgumentNullException("addSavedMessagesCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddSavedMessages"); @@ -1318,10 +1237,10 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addSavedMessagesCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1358,13 +1277,13 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -1391,18 +1310,13 @@ public virtual async System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedM } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body) - { - return AddUserToChatAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (addUserToChatCommand == null) + throw new System.ArgumentNullException("addUserToChatCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/AddUserToChat"); @@ -1410,10 +1324,10 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addUserToChatCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1450,13 +1364,13 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -1483,18 +1397,13 @@ public virtual async System.Threading.Tasks.Task AddUserToChatAsync(AddUserToCha } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body) - { - return DeleteUserFromChatAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (deleteUserFromChatCommand == null) + throw new System.ArgumentNullException("deleteUserFromChatCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Chat/DeleteUserFromChat"); @@ -1502,10 +1411,10 @@ public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteU var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(deleteUserFromChatCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("DELETE"); @@ -1542,13 +1451,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteU { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -1678,8 +1587,8 @@ private string ConvertToString(object? value, System.Globalization.CultureInfo c } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RolesClient : IRolesClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RolesClient : Do_SvyaziClientBase, IRolesClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -1713,38 +1622,30 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId) - { - return GetRoleByUserIdAsync(userId, chatId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (userId == null) + throw new System.ArgumentNullException("userId"); + + if (chatId == null) + throw new System.ArgumentNullException("chatId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/GetRoleByUserId?"); - if (userId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } - if (chatId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); + urlBuilder_.Append(System.Uri.EscapeDataString("chatId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(chatId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -1784,13 +1685,13 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -1812,18 +1713,13 @@ public virtual async System.Threading.Tasks.Task GetRoleByUserIdAsync(S } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body) - { - return CreateRoleForChatAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (createRoleForChatCommand == null) + throw new System.ArgumentNullException("createRoleForChatCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/CreateRoleForChat"); @@ -1831,10 +1727,10 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(createRoleForChatCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1871,13 +1767,13 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -1904,18 +1800,13 @@ public virtual async System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRo } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body) - { - return ChangeRoleForUserByIdAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (changeRoleForUserByIdCommand == null) + throw new System.ArgumentNullException("changeRoleForUserByIdCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Roles/ChangeRoleForUserById"); @@ -1923,10 +1814,10 @@ public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(Chan var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeRoleForUserByIdCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -1963,13 +1854,13 @@ public virtual async System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(Chan { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2099,8 +1990,8 @@ private string ConvertToString(object? value, System.Globalization.CultureInfo c } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class UserClient : IUserClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class UserClient : Do_SvyaziClientBase, IUserClient { private string _baseUrl = ""; private System.Net.Http.HttpClient _httpClient; @@ -2134,17 +2025,9 @@ public string BaseUrl partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllAsync() - { - return GetAllAsync(System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetUsersAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetAll"); @@ -2153,10 +2036,10 @@ public string BaseUrl var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -2181,7 +2064,7 @@ public string BaseUrl var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2196,13 +2079,13 @@ public string BaseUrl { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -2224,34 +2107,26 @@ public string BaseUrl } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task GetUserAsync(System.Guid? userId) - { - return GetUserAsync(userId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetUserAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (userId == null) + throw new System.ArgumentNullException("userId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetUser?"); - if (userId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -2291,13 +2166,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -2319,34 +2194,26 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId) - { - return GetAllChatsByUserIdAsync(userId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (userId == null) + throw new System.ArgumentNullException("userId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetAllChatsByUserId?"); - if (userId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -2371,7 +2238,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2386,13 +2253,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -2414,34 +2281,26 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId) - { - return GetAllChatsIdsByUserIdAsync(userId, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (userId == null) + throw new System.ArgumentNullException("userId"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/GetAllChatsIdsByUserId?"); - if (userId != null) - { - urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); - } + urlBuilder_.Append(System.Uri.EscapeDataString("userId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { request_.Method = new System.Net.Http.HttpMethod("GET"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -2466,7 +2325,7 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( var status_ = (int)response_.StatusCode; if (status_ == 200) { - var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); @@ -2481,13 +2340,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else { @@ -2509,18 +2368,13 @@ public virtual async System.Threading.Tasks.Task GetUserAsync( } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body) - { - return SetNickNameByIdAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (setUserNickNameByIdCommand == null) + throw new System.ArgumentNullException("setUserNickNameByIdCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/SetNickNameById"); @@ -2528,10 +2382,10 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(setUserNickNameByIdCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2568,13 +2422,13 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2601,18 +2455,13 @@ public virtual async System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNic } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body) - { - return DeleteUserAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (deleteUserCommand == null) + throw new System.ArgumentNullException("deleteUserCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/DeleteUser"); @@ -2620,10 +2469,10 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(deleteUserCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2660,13 +2509,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2693,18 +2542,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body) - { - return AddUserAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (addUserCommand == null) + throw new System.ArgumentNullException("addUserCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/AddUser"); @@ -2712,13 +2556,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(addUserCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); - request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); @@ -2758,13 +2602,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 201) @@ -2796,18 +2640,13 @@ public virtual async System.Threading.Tasks.Task DeleteUserAsync(DeleteUserComma } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body) - { - return ChangeDescriptionAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (changeUserDescriptionByIdCommand == null) + throw new System.ArgumentNullException("changeUserDescriptionByIdCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/ChangeDescription"); @@ -2815,10 +2654,10 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserDescriptionByIdCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2855,13 +2694,13 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) @@ -2888,18 +2727,13 @@ public virtual async System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUs } } - /// Success - /// A server side error occurred. - public virtual System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body) - { - return ChangeNameAsync(body, System.Threading.CancellationToken.None); - } - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body, System.Threading.CancellationToken cancellationToken) + public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { + if (changeUserNameByIdCommand == null) + throw new System.ArgumentNullException("changeUserNameByIdCommand"); + var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/User/ChangeName"); @@ -2907,10 +2741,10 @@ public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameB var disposeClient_ = false; try { - using (var request_ = new System.Net.Http.HttpRequestMessage()) + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) { - var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value)); - content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json"); + var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(changeUserNameByIdCommand, _settings.Value)); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -2947,13 +2781,13 @@ public virtual async System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameB { throw new Do_Svyazi_User_ApiClient_Exception("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } - throw new Do_Svyazi_User_ApiClient_Exception("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else if (status_ == 500) { string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); - throw new Do_Svyazi_User_ApiClient_Exception("Server Error", status_, responseText_, headers_, null); + throw new Do_Svyazi_User_ApiClient_Exception("A server side error occurred.", status_, responseText_, headers_, null); } else if (status_ == 204) diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs index 94b1595..fbd2f47 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do-Svyazi.User.Contracts.cs @@ -1,11 +1,13 @@ //---------------------- // -// Generated using the NSwag toolchain v13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// Generated using the NSwag toolchain v13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) // //---------------------- #nullable enable +using Do_Svyazi.User.Web.ApiClient.Backend; + #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." #pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." #pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' @@ -18,295 +20,159 @@ namespace Do_Svyazi.User.Web.ApiClient.Contracts { using System = global::System; - - public interface IDoSvyaziClient {} - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IAuthenticateClient : IDoSvyaziClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IAuthenticateClient { - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetAllAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task LoginAsync(LoginRequest? body); + System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task LoginAsync(LoginRequest? body, System.Threading.CancellationToken cancellationToken); - - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body); + System.Threading.Tasks.Task LoginAsync(LoginRequest model, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task RegisterAsync(RegisterCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken); + System.Threading.Tasks.Task RegisterAsync(RegisterCommand model, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken); - - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body); + System.Threading.Tasks.Task AuthenticateByJwtAsync(string? jwtToken, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand? body, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task RegisterAdminAsync(RegisterAdminCommand model, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IChatClient : IDoSvyaziClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IChatClient { - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetChatsAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId); + System.Threading.Tasks.Task> GetChatsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task GetChatByIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId); + System.Threading.Tasks.Task GetChatByIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId); + System.Threading.Tasks.Task> GetUserIdsByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid? chatId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body); + System.Threading.Tasks.Task> GetUsersByChatIdAsync(System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body); + System.Threading.Tasks.Task AddChannelAsync(AddChannelCommand addChannelCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body); + System.Threading.Tasks.Task AddGroupChatAsync(AddGroupChatCommand addGroupChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body); + System.Threading.Tasks.Task AddPersonalChatAsync(AddPersonalChatCommand addPersonalChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body); + System.Threading.Tasks.Task AddSavedMessagesAsync(AddSavedMessagesCommand addSavedMessagesCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body); + System.Threading.Tasks.Task AddUserToChatAsync(AddUserToChatCommand addUserToChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand? body, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task DeleteUserFromChatAsync(DeleteUserFromChatCommand deleteUserFromChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IRolesClient : IDoSvyaziClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IRolesClient { - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid? userId, System.Guid? chatId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body); + System.Threading.Tasks.Task GetRoleByUserIdAsync(System.Guid userId, System.Guid chatId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body); + System.Threading.Tasks.Task CreateRoleForChatAsync(CreateRoleForChatCommand createRoleForChatCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand? body, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeRoleForUserByIdAsync(ChangeRoleForUserByIdCommand changeRoleForUserByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial interface IUserClient : IDoSvyaziClient + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial interface IUserClient { - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetAllAsync(); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetAllAsync(System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task GetUserAsync(System.Guid? userId); + System.Threading.Tasks.Task> GetUsersAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task GetUserAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId); + System.Threading.Tasks.Task GetUserAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId); + System.Threading.Tasks.Task> GetAllChatsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid? userId, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body); + System.Threading.Tasks.Task> GetAllChatsIdsByUserIdAsync(System.Guid userId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body); + System.Threading.Tasks.Task SetNickNameByIdAsync(SetUserNickNameByIdCommand setUserNickNameByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body); + System.Threading.Tasks.Task DeleteUserAsync(DeleteUserCommand deleteUserCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task AddUserAsync(AddUserCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body); + System.Threading.Tasks.Task AddUserAsync(AddUserCommand addUserCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success - /// A server side error occurred. - System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand? body, System.Threading.CancellationToken cancellationToken); - - /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body); + System.Threading.Tasks.Task ChangeDescriptionAsync(ChangeUserDescriptionByIdCommand changeUserDescriptionByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// Success /// A server side error occurred. - System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand? body, System.Threading.CancellationToken cancellationToken); + System.Threading.Tasks.Task ChangeNameAsync(ChangeUserNameByIdCommand changeUserNameByIdCommand, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddChannelCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class MessengerUser : IdentityUserOfGuid { [Newtonsoft.Json.JsonConstructor] - public AddChannelCommand(System.Guid @adminId, string? @description, string? @name) + public MessengerUser(int @accessFailedCount, string? @concurrencyStamp, string @description, string? @email, bool @emailConfirmed, System.Guid @id, bool @lockoutEnabled, System.DateTime? @lockoutEnd, string @name, string? @normalizedEmail, string? @normalizedUserName, string? @passwordHash, string? @phoneNumber, bool @phoneNumberConfirmed, string? @securityStamp, bool @twoFactorEnabled, string? @userName) - { + : base(accessFailedCount, concurrencyStamp, email, emailConfirmed, id, lockoutEnabled, lockoutEnd, normalizedEmail, normalizedUserName, passwordHash, phoneNumber, phoneNumberConfirmed, securityStamp, twoFactorEnabled, userName) - this.AdminId = @adminId; + { this.Name = @name; this.Description = @description; - } [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid AdminId { get; } - - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } public string ToJson() { @@ -314,82 +180,98 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddChannelCommand FromJson(string data) + public static MessengerUser FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddGroupChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class IdentityUserOfGuid { [Newtonsoft.Json.JsonConstructor] - public AddGroupChatCommand(System.Guid @adminId, string? @description, string? @name) + public IdentityUserOfGuid(int @accessFailedCount, string? @concurrencyStamp, string? @email, bool @emailConfirmed, System.Guid @id, bool @lockoutEnabled, System.DateTime? @lockoutEnd, string? @normalizedEmail, string? @normalizedUserName, string? @passwordHash, string? @phoneNumber, bool @phoneNumberConfirmed, string? @securityStamp, bool @twoFactorEnabled, string? @userName) { - this.AdminId = @adminId; + this.Id = @id; - this.Name = @name; + this.UserName = @userName; - this.Description = @description; + this.NormalizedUserName = @normalizedUserName; - } [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid AdminId { get; } + this.Email = @email; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + this.NormalizedEmail = @normalizedEmail; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + this.EmailConfirmed = @emailConfirmed; - public string ToJson() - { + this.PasswordHash = @passwordHash; - return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + this.SecurityStamp = @securityStamp; - } - public static AddGroupChatCommand FromJson(string data) - { + this.ConcurrencyStamp = @concurrencyStamp; - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + this.PhoneNumber = @phoneNumber; - } + this.PhoneNumberConfirmed = @phoneNumberConfirmed; - } + this.TwoFactorEnabled = @twoFactorEnabled; - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddPersonalChatCommand - { - [Newtonsoft.Json.JsonConstructor] + this.LockoutEnd = @lockoutEnd; - public AddPersonalChatCommand(string? @description, System.Guid @firstUserId, string? @name, System.Guid @secondUserId) + this.LockoutEnabled = @lockoutEnabled; - { + this.AccessFailedCount = @accessFailedCount; - this.FirstUserId = @firstUserId; + } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; } - this.SecondUserId = @secondUserId; + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? UserName { get; } - this.Name = @name; + [Newtonsoft.Json.JsonProperty("normalizedUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? NormalizedUserName { get; } - this.Description = @description; + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Email { get; } - } [Newtonsoft.Json.JsonProperty("firstUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid FirstUserId { get; } + [Newtonsoft.Json.JsonProperty("normalizedEmail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? NormalizedEmail { get; } - [Newtonsoft.Json.JsonProperty("secondUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid SecondUserId { get; } + [Newtonsoft.Json.JsonProperty("emailConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool EmailConfirmed { get; } - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + [Newtonsoft.Json.JsonProperty("passwordHash", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? PasswordHash { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + [Newtonsoft.Json.JsonProperty("securityStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? SecurityStamp { get; } + + [Newtonsoft.Json.JsonProperty("concurrencyStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? ConcurrencyStamp { get; } + + [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? PhoneNumber { get; } + + [Newtonsoft.Json.JsonProperty("phoneNumberConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool PhoneNumberConfirmed { get; } + + [Newtonsoft.Json.JsonProperty("twoFactorEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool TwoFactorEnabled { get; } + + [Newtonsoft.Json.JsonProperty("lockoutEnd", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTime? LockoutEnd { get; } + + [Newtonsoft.Json.JsonProperty("lockoutEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool LockoutEnabled { get; } + + [Newtonsoft.Json.JsonProperty("accessFailedCount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int AccessFailedCount { get; } public string ToJson() { @@ -397,38 +279,62 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddPersonalChatCommand FromJson(string data) + public static IdentityUserOfGuid FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddSavedMessagesCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ProblemDetails { [Newtonsoft.Json.JsonConstructor] - public AddSavedMessagesCommand(string? @description, string? @name, System.Guid @userId) + public ProblemDetails(string? @detail, System.Collections.Generic.Dictionary @extensions, string? @instance, int? @status, string? @title, string? @type) { - this.UserId = @userId; + this.Type = @type; - this.Name = @name; + this.Title = @title; - this.Description = @description; + this.Status = @status; - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } + this.Detail = @detail; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + this.Instance = @instance; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + this.Extensions = @extensions; + + } [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Type { get; } + + [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Title { get; } + + [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int? Status { get; } + + [Newtonsoft.Json.JsonProperty("detail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Detail { get; } + + [Newtonsoft.Json.JsonProperty("instance", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Instance { get; } + + [Newtonsoft.Json.JsonProperty("extensions", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.Generic.Dictionary Extensions { get; } + + private System.Collections.Generic.IDictionary _additionalProperties = new System.Collections.Generic.Dictionary(); + + [Newtonsoft.Json.JsonExtensionData] + public System.Collections.Generic.IDictionary AdditionalProperties + { + get { return _additionalProperties; } + set { _additionalProperties = value; } + } public string ToJson() { @@ -436,38 +342,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddSavedMessagesCommand FromJson(string data) + public static ProblemDetails FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddUserCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class LoginRequest { [Newtonsoft.Json.JsonConstructor] - public AddUserCommand(string? @description, string? @name, string? @nickName) + public LoginRequest(LoginModel @model) { - this.Name = @name; - - this.NickName = @nickName; - - this.Description = @description; - - } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } - - [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? NickName { get; } + this.Model = @model; - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public LoginModel Model { get; } public string ToJson() { @@ -475,33 +371,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddUserCommand FromJson(string data) + public static LoginRequest FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AddUserToChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class LoginModel { [Newtonsoft.Json.JsonConstructor] - public AddUserToChatCommand(System.Guid @chatId, System.Guid @userId) + public LoginModel(string? @email, string @password, string? @userName) { - this.UserId = @userId; + this.UserName = @userName; - this.ChatId = @chatId; + this.Email = @email; - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } + this.Password = @password; - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; } + } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? UserName { get; } + + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Email { get; } + + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + public string Password { get; } public string ToJson() { @@ -509,33 +410,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AddUserToChatCommand FromJson(string data) + public static LoginModel FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class AuthenticateResponse + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RegisterCommand { [Newtonsoft.Json.JsonConstructor] - public AuthenticateResponse(System.Guid @userId, System.DateTimeOffset @validTo) + public RegisterCommand(RegisterModel @model) { - this.UserId = @userId; + this.Model = @model; - this.ValidTo = @validTo; - - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } - - [Newtonsoft.Json.JsonProperty("validTo", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.DateTimeOffset ValidTo { get; } + } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RegisterModel Model { get; } public string ToJson() { @@ -543,38 +439,48 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static AuthenticateResponse FromJson(string data) + public static RegisterCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeRoleForUserByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RegisterModel { [Newtonsoft.Json.JsonConstructor] - public ChangeRoleForUserByIdCommand(System.Guid @chatId, RoleDto @role, System.Guid @userId) + public RegisterModel(string @email, string @name, string @password, string @phoneNumber, string @userName) { - this.UserId = @userId; + this.UserName = @userName; - this.ChatId = @chatId; + this.Name = @name; - this.Role = @role; + this.Email = @email; - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } + this.Password = @password; - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; } + this.PhoneNumber = @phoneNumber; - [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDto Role { get; } + } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Always)] + public string UserName { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } + + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] + public string Email { get; } + + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + public string Password { get; } + + [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string PhoneNumber { get; } public string ToJson() { @@ -582,33 +488,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeRoleForUserByIdCommand FromJson(string data) + public static RegisterModel FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeUserDescriptionByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AuthenticateResponse { [Newtonsoft.Json.JsonConstructor] - public ChangeUserDescriptionByIdCommand(string? @description, System.Guid @userId) + public AuthenticateResponse(System.Guid @userId, System.DateTime @validTo) { this.UserId = @userId; - this.Description = @description; + this.ValidTo = @validTo; } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + [Newtonsoft.Json.JsonProperty("validTo", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTime ValidTo { get; } public string ToJson() { @@ -616,33 +522,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeUserDescriptionByIdCommand FromJson(string data) + public static AuthenticateResponse FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChangeUserNameByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RegisterAdminCommand { [Newtonsoft.Json.JsonConstructor] - public ChangeUserNameByIdCommand(string? @name, System.Guid @userId) + public RegisterAdminCommand(RegisterModel @model) { - this.UserId = @userId; - - this.Name = @name; - - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } + this.Model = @model; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RegisterModel Model { get; } public string ToJson() { @@ -650,38 +551,48 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChangeUserNameByIdCommand FromJson(string data) + public static RegisterAdminCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ChatUserDto + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class MessengerChatDto { [Newtonsoft.Json.JsonConstructor] - public ChatUserDto(string? @chatUserName, System.Guid @messengerUserId, RoleDto @role) + public MessengerChatDto(string? @description, System.Guid @id, string? @name, System.Collections.ObjectModel.ObservableCollection @roles, System.Collections.ObjectModel.ObservableCollection @users) { - this.ChatUserName = @chatUserName; + this.Id = @id; - this.MessengerUserId = @messengerUserId; + this.Name = @name; - this.Role = @role; + this.Description = @description; - } [Newtonsoft.Json.JsonProperty("chatUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? ChatUserName { get; } + this.Users = @users; - [Newtonsoft.Json.JsonProperty("messengerUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid MessengerUserId { get; } + this.Roles = @roles; - [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDto Role { get; } + } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } + + [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.ObjectModel.ObservableCollection Users { get; } + + [Newtonsoft.Json.JsonProperty("roles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.ObjectModel.ObservableCollection Roles { get; } public string ToJson() { @@ -689,62 +600,83 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ChatUserDto FromJson(string data) + public static MessengerChatDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class CreateRoleForChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class RoleDto { [Newtonsoft.Json.JsonConstructor] - public CreateRoleForChatCommand(System.Guid @chatId, RoleDto @role) + public RoleDto(ActionOption @canAddUsers, ActionOption @canDeleteChat, ActionOption @canDeleteMessages, ActionOption @canDeleteUsers, ActionOption @canEditChannelDescription, ActionOption @canEditMessages, ActionOption @canInviteOtherUsers, ActionOption @canPinMessages, ActionOption @canReadMessages, ActionOption @canSeeChannelMembers, ActionOption @canWriteMessages, string @name) { - this.Role = @role; + this.Name = @name; - this.ChatId = @chatId; + this.CanEditMessages = @canEditMessages; - } [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RoleDto Role { get; } + this.CanDeleteMessages = @canDeleteMessages; - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; } + this.CanWriteMessages = @canWriteMessages; - public string ToJson() - { + this.CanReadMessages = @canReadMessages; - return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); + this.CanAddUsers = @canAddUsers; - } - public static CreateRoleForChatCommand FromJson(string data) - { + this.CanDeleteUsers = @canDeleteUsers; - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + this.CanPinMessages = @canPinMessages; - } + this.CanSeeChannelMembers = @canSeeChannelMembers; - } + this.CanInviteOtherUsers = @canInviteOtherUsers; - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class DeleteUserCommand - { - [Newtonsoft.Json.JsonConstructor] + this.CanEditChannelDescription = @canEditChannelDescription; - public DeleteUserCommand(System.Guid @userId) + this.CanDeleteChat = @canDeleteChat; - { + } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } - this.UserId = @userId; + [Newtonsoft.Json.JsonProperty("canEditMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanEditMessages { get; } - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } + [Newtonsoft.Json.JsonProperty("canDeleteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanDeleteMessages { get; } + + [Newtonsoft.Json.JsonProperty("canWriteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanWriteMessages { get; } + + [Newtonsoft.Json.JsonProperty("canReadMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanReadMessages { get; } + + [Newtonsoft.Json.JsonProperty("canAddUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanAddUsers { get; } + + [Newtonsoft.Json.JsonProperty("canDeleteUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanDeleteUsers { get; } + + [Newtonsoft.Json.JsonProperty("canPinMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanPinMessages { get; } + + [Newtonsoft.Json.JsonProperty("canSeeChannelMembers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanSeeChannelMembers { get; } + + [Newtonsoft.Json.JsonProperty("canInviteOtherUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanInviteOtherUsers { get; } + + [Newtonsoft.Json.JsonProperty("canEditChannelDescription", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanEditChannelDescription { get; } + + [Newtonsoft.Json.JsonProperty("canDeleteChat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ActionOption CanDeleteChat { get; } public string ToJson() { @@ -752,33 +684,50 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static DeleteUserCommand FromJson(string data) + public static RoleDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class DeleteUserFromChatCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public enum ActionOption + { + + Unavailable = 0, + + Enabled = 1, + + Disabled = 2, + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChatUserDto { [Newtonsoft.Json.JsonConstructor] - public DeleteUserFromChatCommand(System.Guid @chatId, System.Guid @userId) + public ChatUserDto(string @chatUserName, System.Guid @messengerUserId, RoleDto @role) { - this.UserId = @userId; + this.ChatUserName = @chatUserName; - this.ChatId = @chatId; + this.MessengerUserId = @messengerUserId; - } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid UserId { get; } + this.Role = @role; - [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid ChatId { get; } + } [Newtonsoft.Json.JsonProperty("chatUserName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ChatUserName { get; } + + [Newtonsoft.Json.JsonProperty("messengerUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid MessengerUserId { get; } + + [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDto Role { get; } public string ToJson() { @@ -786,39 +735,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static DeleteUserFromChatCommand FromJson(string data) + public static ChatUserDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class LoginModel + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddChannelCommand { [Newtonsoft.Json.JsonConstructor] - public LoginModel(string? @email, string @password, string? @userName) + public AddChannelCommand(System.Guid @adminId, string @description, string @name) { - this.UserName = @userName; + this.AdminId = @adminId; - this.Email = @email; + this.Name = @name; - this.Password = @password; + this.Description = @description; - } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? UserName { get; } + } [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid AdminId { get; } - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Email { get; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } - [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string Password { get; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } public string ToJson() { @@ -826,28 +774,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static LoginModel FromJson(string data) + public static AddChannelCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class LoginRequest + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddGroupChatCommand { [Newtonsoft.Json.JsonConstructor] - public LoginRequest(LoginModel @model) + public AddGroupChatCommand(System.Guid @adminId, string @description, string @name) { - this.Model = @model; + this.AdminId = @adminId; - } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public LoginModel Model { get; } + this.Name = @name; + + this.Description = @description; + + } [Newtonsoft.Json.JsonProperty("adminId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid AdminId { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } public string ToJson() { @@ -855,48 +813,43 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static LoginRequest FromJson(string data) + public static AddGroupChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerChatDto - { + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddPersonalChatCommand + { [Newtonsoft.Json.JsonConstructor] - public MessengerChatDto(string? @description, System.Guid @id, string? @name, System.Collections.Generic.ICollection? @roles, System.Collections.Generic.ICollection? @users) + public AddPersonalChatCommand(string @description, System.Guid @firstUserId, string @name, System.Guid @secondUserId) { - this.Id = @id; + this.FirstUserId = @firstUserId; + + this.SecondUserId = @secondUserId; this.Name = @name; this.Description = @description; - this.Users = @users; - - this.Roles = @roles; - - } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; } - - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + } [Newtonsoft.Json.JsonProperty("firstUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid FirstUserId { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + [Newtonsoft.Json.JsonProperty("secondUserId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid SecondUserId { get; } - [Newtonsoft.Json.JsonProperty("users", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.Generic.ICollection? Users { get; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } - [Newtonsoft.Json.JsonProperty("roles", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Collections.Generic.ICollection? Roles { get; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } public string ToJson() { @@ -904,108 +857,106 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerChatDto FromJson(string data) + public static AddPersonalChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerUser + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddSavedMessagesCommand { [Newtonsoft.Json.JsonConstructor] - public MessengerUser(int @accessFailedCount, string? @concurrencyStamp, string? @description, string? @email, bool @emailConfirmed, System.Guid @id, bool @lockoutEnabled, System.DateTimeOffset? @lockoutEnd, string? @name, string? @normalizedEmail, string? @normalizedUserName, string? @passwordHash, string? @phoneNumber, bool @phoneNumberConfirmed, string? @securityStamp, bool @twoFactorEnabled, string? @userName) + public AddSavedMessagesCommand(string @description, string @name, System.Guid @userId) { - this.Id = @id; - - this.UserName = @userName; - - this.NormalizedUserName = @normalizedUserName; + this.UserId = @userId; - this.Email = @email; + this.Name = @name; - this.NormalizedEmail = @normalizedEmail; + this.Description = @description; - this.EmailConfirmed = @emailConfirmed; + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - this.PasswordHash = @passwordHash; + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } - this.SecurityStamp = @securityStamp; + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } - this.ConcurrencyStamp = @concurrencyStamp; + public string ToJson() + { - this.PhoneNumber = @phoneNumber; + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); - this.PhoneNumberConfirmed = @phoneNumberConfirmed; + } + public static AddSavedMessagesCommand FromJson(string data) + { - this.TwoFactorEnabled = @twoFactorEnabled; + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); - this.LockoutEnd = @lockoutEnd; + } - this.LockoutEnabled = @lockoutEnabled; + } - this.AccessFailedCount = @accessFailedCount; + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddUserToChatCommand + { + [Newtonsoft.Json.JsonConstructor] - this.Name = @name; + public AddUserToChatCommand(System.Guid @chatId, System.Guid @userId) - this.Description = @description; + { - } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? UserName { get; } + this.ChatId = @chatId; - [Newtonsoft.Json.JsonProperty("normalizedUserName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? NormalizedUserName { get; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Email { get; } + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } - [Newtonsoft.Json.JsonProperty("normalizedEmail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? NormalizedEmail { get; } + public string ToJson() + { - [Newtonsoft.Json.JsonProperty("emailConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool EmailConfirmed { get; } + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); - [Newtonsoft.Json.JsonProperty("passwordHash", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? PasswordHash { get; } + } + public static AddUserToChatCommand FromJson(string data) + { - [Newtonsoft.Json.JsonProperty("securityStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? SecurityStamp { get; } + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); - [Newtonsoft.Json.JsonProperty("concurrencyStamp", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? ConcurrencyStamp { get; } + } - [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? PhoneNumber { get; } + } - [Newtonsoft.Json.JsonProperty("phoneNumberConfirmed", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool PhoneNumberConfirmed { get; } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class DeleteUserFromChatCommand + { + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("twoFactorEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool TwoFactorEnabled { get; } + public DeleteUserFromChatCommand(System.Guid @chatId, System.Guid @userId) - [Newtonsoft.Json.JsonProperty("lockoutEnd", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.DateTimeOffset? LockoutEnd { get; } + { - [Newtonsoft.Json.JsonProperty("lockoutEnabled", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public bool LockoutEnabled { get; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("accessFailedCount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int AccessFailedCount { get; } + this.ChatId = @chatId; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } public string ToJson() { @@ -1013,43 +964,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerUser FromJson(string data) + public static DeleteUserFromChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class MessengerUserDto + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CreateRoleForChatCommand { [Newtonsoft.Json.JsonConstructor] - public MessengerUserDto(string? @description, System.Guid @id, string? @name, string? @userName) + public CreateRoleForChatCommand(System.Guid @chatId, RoleDto @role) { - this.Id = @id; - - this.Name = @name; - - this.UserName = @userName; - - this.Description = @description; - - } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public System.Guid Id { get; } + this.Role = @role; - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + this.ChatId = @chatId; - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? UserName { get; } + } [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDto Role { get; } - [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Description { get; } + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } public string ToJson() { @@ -1057,57 +998,38 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static MessengerUserDto FromJson(string data) + public static CreateRoleForChatCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class ProblemDetails + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChangeRoleForUserByIdCommand { [Newtonsoft.Json.JsonConstructor] - public ProblemDetails(string? @detail, string? @instance, int? @status, string? @title, string? @type) + public ChangeRoleForUserByIdCommand(System.Guid @chatId, RoleDto @role, System.Guid @userId) { - this.Type = @type; - - this.Title = @title; - - this.Status = @status; - - this.Detail = @detail; - - this.Instance = @instance; - - } [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Type { get; } - - [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Title { get; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public int? Status { get; } + this.ChatId = @chatId; - [Newtonsoft.Json.JsonProperty("detail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Detail { get; } + this.Role = @role; - [Newtonsoft.Json.JsonProperty("instance", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Instance { get; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - private System.Collections.Generic.IDictionary _additionalProperties = new System.Collections.Generic.Dictionary(); + [Newtonsoft.Json.JsonProperty("chatId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ChatId { get; } - [Newtonsoft.Json.JsonExtensionData] - public System.Collections.Generic.IDictionary AdditionalProperties - { - get { return _additionalProperties; } - set { _additionalProperties = value; } - } + [Newtonsoft.Json.JsonProperty("role", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public RoleDto Role { get; } public string ToJson() { @@ -1115,28 +1037,43 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static ProblemDetails FromJson(string data) + public static ChangeRoleForUserByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterAdminCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class MessengerUserDto { [Newtonsoft.Json.JsonConstructor] - public RegisterAdminCommand(RegisterModel @model) + public MessengerUserDto(string? @description, System.Guid @id, string? @name, string? @userName) { - this.Model = @model; + this.Id = @id; - } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RegisterModel Model { get; } + this.Name = @name; + + this.UserName = @userName; + + this.Description = @description; + + } [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid Id { get; } + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Name { get; } + + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? UserName { get; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string? Description { get; } public string ToJson() { @@ -1144,28 +1081,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterAdminCommand FromJson(string data) + public static MessengerUserDto FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SetUserNickNameByIdCommand { [Newtonsoft.Json.JsonConstructor] - public RegisterCommand(RegisterModel @model) + public SetUserNickNameByIdCommand(System.Guid @userId, string @userName) { - this.Model = @model; + this.UserId = @userId; - } [Newtonsoft.Json.JsonProperty("model", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public RegisterModel Model { get; } + this.UserName = @userName; + + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } + + [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string UserName { get; } public string ToJson() { @@ -1173,51 +1115,28 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterCommand FromJson(string data) + public static SetUserNickNameByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RegisterModel + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class DeleteUserCommand { [Newtonsoft.Json.JsonConstructor] - public RegisterModel(string @email, string? @name, string @password, string? @phoneNumber, string @userName) + public DeleteUserCommand(System.Guid @userId) { - this.UserName = @userName; - - this.Name = @name; - - this.Email = @email; - - this.Password = @password; - - this.PhoneNumber = @phoneNumber; - - } [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string UserName { get; } - - [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } - - [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string Email { get; } - - [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] - [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] - public string Password { get; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("phoneNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? PhoneNumber { get; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } public string ToJson() { @@ -1225,83 +1144,72 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RegisterModel FromJson(string data) + public static DeleteUserCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class RoleDto + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddUserCommand { [Newtonsoft.Json.JsonConstructor] - public RoleDto(ActionOption @canAddUsers, ActionOption @canDeleteChat, ActionOption @canDeleteMessages, ActionOption @canDeleteUsers, ActionOption @canEditChannelDescription, ActionOption @canEditMessages, ActionOption @canInviteOtherUsers, ActionOption @canPinMessages, ActionOption @canReadMessages, ActionOption @canSeeChannelMembers, ActionOption @canWriteMessages, string? @name) + public AddUserCommand(string @description, string @name, string @nickName) { this.Name = @name; - this.CanEditMessages = @canEditMessages; - - this.CanDeleteMessages = @canDeleteMessages; - - this.CanWriteMessages = @canWriteMessages; - - this.CanReadMessages = @canReadMessages; + this.NickName = @nickName; - this.CanAddUsers = @canAddUsers; + this.Description = @description; - this.CanDeleteUsers = @canDeleteUsers; + } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } - this.CanPinMessages = @canPinMessages; + [Newtonsoft.Json.JsonProperty("nickName", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string NickName { get; } - this.CanSeeChannelMembers = @canSeeChannelMembers; + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } - this.CanInviteOtherUsers = @canInviteOtherUsers; - - this.CanEditChannelDescription = @canEditChannelDescription; - - this.CanDeleteChat = @canDeleteChat; + public string ToJson() + { - } [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Name { get; } + return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); - [Newtonsoft.Json.JsonProperty("canEditMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanEditMessages { get; } + } + public static AddUserCommand FromJson(string data) + { - [Newtonsoft.Json.JsonProperty("canDeleteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteMessages { get; } + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); - [Newtonsoft.Json.JsonProperty("canWriteMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanWriteMessages { get; } + } - [Newtonsoft.Json.JsonProperty("canReadMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanReadMessages { get; } + } - [Newtonsoft.Json.JsonProperty("canAddUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanAddUsers { get; } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChangeUserDescriptionByIdCommand + { + [Newtonsoft.Json.JsonConstructor] - [Newtonsoft.Json.JsonProperty("canDeleteUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteUsers { get; } + public ChangeUserDescriptionByIdCommand(string @description, System.Guid @userId) - [Newtonsoft.Json.JsonProperty("canPinMessages", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanPinMessages { get; } + { - [Newtonsoft.Json.JsonProperty("canSeeChannelMembers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanSeeChannelMembers { get; } + this.UserId = @userId; - [Newtonsoft.Json.JsonProperty("canInviteOtherUsers", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanInviteOtherUsers { get; } + this.Description = @description; - [Newtonsoft.Json.JsonProperty("canEditChannelDescription", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanEditChannelDescription { get; } + } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("canDeleteChat", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public ActionOption CanDeleteChat { get; } + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; } public string ToJson() { @@ -1309,33 +1217,33 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static RoleDto FromJson(string data) + public static ChangeUserDescriptionByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class SetUserNickNameByIdCommand + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ChangeUserNameByIdCommand { [Newtonsoft.Json.JsonConstructor] - public SetUserNickNameByIdCommand(System.Guid @userId, string? @userName) + public ChangeUserNameByIdCommand(string @name, System.Guid @userId) { this.UserId = @userId; - this.UserName = @userName; + this.Name = @name; } [Newtonsoft.Json.JsonProperty("userId", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid UserId { get; } - [Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? UserName { get; } + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; } public string ToJson() { @@ -1343,28 +1251,18 @@ public string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, new Newtonsoft.Json.JsonSerializerSettings()); } - public static SetUserNickNameByIdCommand FromJson(string data) + public static ChangeUserNameByIdCommand FromJson(string data) { - return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); + return Newtonsoft.Json.JsonConvert.DeserializeObject(data, new Newtonsoft.Json.JsonSerializerSettings()); } } - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] - public enum ActionOption - { - - Unavailable = 0, - Enabled = 1, - - Disabled = 2, - - } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] public partial class Do_Svyazi_User_ApiClient_Exception : System.Exception { public int StatusCode { get; private set; } @@ -1387,7 +1285,7 @@ public override string ToString() } } - [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))")] + [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.0.0 (NJsonSchema v10.7.1.0 (Newtonsoft.Json v13.0.0.0))")] public partial class Do_Svyazi_User_ApiClient_Exception : Do_Svyazi_User_ApiClient_Exception { public TResult Result { get; private set; } diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts index 89de025..65ffaf3 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/do-svyazi.user.clients.ts @@ -17,7 +17,7 @@ export interface IAuthenticateClient { getAll(): Promise; login(model: LoginRequest): Promise; register(model: RegisterCommand): Promise; - authenticateByJwt(jwtToken: string | null): Promise; + authenticateByJwt(jwtToken: string | null): Promise; registerAdmin(model: RegisterAdminCommand): Promise; } @@ -225,7 +225,7 @@ export class AuthenticateClient implements IAuthenticateClient { return Promise.resolve(null as any); } - authenticateByJwt(jwtToken: string | null , cancelToken?: CancelToken | undefined): Promise { + authenticateByJwt(jwtToken: string | null , cancelToken?: CancelToken | undefined): Promise { let url_ = this.baseUrl + "/api/Authenticate/AuthenticateByJwt"; url_ = url_.replace(/[?&]$/, ""); @@ -250,7 +250,7 @@ export class AuthenticateClient implements IAuthenticateClient { }); } - protected processAuthenticateByJwt(response: AxiosResponse): Promise { + protected processAuthenticateByJwt(response: AxiosResponse): Promise { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { @@ -265,9 +265,8 @@ export class AuthenticateClient implements IAuthenticateClient { const _responseText = response.data; let result200: any = null; let resultData200 = _responseText; - result200 = resultData200 !== undefined ? resultData200 : null; - - return Promise.resolve(result200); + result200 = AuthenticateResponse.fromJS(resultData200, _mappings); + return Promise.resolve(result200); } else if (status === 401) { const _responseText = response.data; @@ -284,7 +283,7 @@ export class AuthenticateClient implements IAuthenticateClient { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } - return Promise.resolve(null as any); + return Promise.resolve(null as any); } registerAdmin(model: RegisterAdminCommand , cancelToken?: CancelToken | undefined): Promise { @@ -2231,6 +2230,44 @@ export interface IRegisterModel { phoneNumber: string; } +export class AuthenticateResponse implements IAuthenticateResponse { + userId!: string; + validTo!: moment.Moment; + + constructor(data?: IAuthenticateResponse) { + if (data) { + for (var property in data) { + if (data.hasOwnProperty(property)) + (this)[property] = (data)[property]; + } + } + } + + init(_data?: any, _mappings?: any) { + if (_data) { + this.userId = _data["userId"]; + this.validTo = _data["validTo"] ? moment.parseZone(_data["validTo"].toString()) : undefined; + } + } + + static fromJS(data: any, _mappings?: any): AuthenticateResponse | null { + data = typeof data === 'object' ? data : {}; + return createInstance(data, _mappings, AuthenticateResponse); + } + + toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["userId"] = this.userId; + data["validTo"] = this.validTo ? this.validTo.toISOString(true) : undefined; + return data; + } +} + +export interface IAuthenticateResponse { + userId: string; + validTo: moment.Moment; +} + export class RegisterAdminCommand implements IRegisterAdminCommand { model!: RegisterModel; @@ -3107,10 +3144,7 @@ export class Do_Svyazi_User_ApiClient_Exception extends Error { } function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any { - if (result !== null && result !== undefined) - throw result; - else - throw new Do_Svyazi_User_ApiClient_Exception(message, status, response, headers, null); + throw new Do_Svyazi_User_ApiClient_Exception(message, status, response, headers, result); } function isAxiosError(obj: any | undefined): obj is AxiosError { diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package-lock.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package-lock.json index 2e92b54..85a2a1c 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package-lock.json +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package-lock.json @@ -1,13 +1,14 @@ { "name": "@do-svyazi/user.clients", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@do-svyazi/user.clients", - "version": "2.0.0", + "version": "2.1.0", "dependencies": { + "@types/node": "^18.0.3", "asynckit": "^0.4.0", "axios": "^0.27.2", "combined-stream": "^1.0.8", @@ -20,6 +21,11 @@ }, "devDependencies": {} }, + "node_modules/@types/node": { + "version": "18.0.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.3.tgz", + "integrity": "sha512-HzNRZtp4eepNitP+BD6k2L6DROIDG4Q0fm4x+dwfsr6LGmROENnok75VGw40628xf+iR24WeMFcHuuBDUAzzsQ==" + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -114,6 +120,11 @@ } }, "dependencies": { + "@types/node": { + "version": "18.0.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.3.tgz", + "integrity": "sha512-HzNRZtp4eepNitP+BD6k2L6DROIDG4Q0fm4x+dwfsr6LGmROENnok75VGw40628xf+iR24WeMFcHuuBDUAzzsQ==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package.json index 6f3db8e..8f02e3e 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package.json +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Frontend/package.json @@ -3,15 +3,15 @@ "version": "2.1.0", "description": "User module clients", "dependencies": { - "axios": "^0.27.2", + "@types/node": "^18.0.3", "asynckit": "^0.4.0", - "follow-redirects": "^1.15.1", + "axios": "^0.27.2", "combined-stream": "^1.0.8", - "form-data": "^4.0.0", "delayed-stream": "^1.0.0", - "mime-types": "^2.1.35", + "follow-redirects": "^1.15.1", + "form-data": "^4.0.0", "mime-db": "^1.52.0", + "mime-types": "^2.1.35", "moment": "^2.29.3" - }, - "devDependencies": {} + } } diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/swagger.json similarity index 99% rename from Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json rename to Source/Presentation/Do-Svyazi.User.Web.ApiClient/swagger.json index bb8a830..b81dc19 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/swagger.json @@ -145,8 +145,7 @@ "content": { "application/json": { "schema": { - "type": "string", - "format": "guid" + "$ref": "#/components/schemas/AuthenticateResponse" } } } @@ -1354,6 +1353,20 @@ } } }, + "AuthenticateResponse": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "validTo": { + "type": "string", + "format": "date-time" + } + } + }, "RegisterAdminCommand": { "type": "object", "additionalProperties": false, From e2020b31a4a89e35874da518ca9c43ca1b8c51bc Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:10:09 +0300 Subject: [PATCH 41/45] feat: ClientBase class added --- .../Backend/Do_SvyaziClientBase.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do_SvyaziClientBase.cs diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do_SvyaziClientBase.cs b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do_SvyaziClientBase.cs new file mode 100644 index 0000000..cd89447 --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/Backend/Do_SvyaziClientBase.cs @@ -0,0 +1,21 @@ +namespace Do_Svyazi.User.Web.ApiClient.Backend; + +public abstract class Do_SvyaziClientBase +{ + public string BearerToken { get; private set; } + + public void SetBearerToken(string token) + { + BearerToken = token; + } + + // Called by implementing swagger client classes + public Task CreateHttpRequestMessageAsync(CancellationToken cancellationToken) + { + var msg = new HttpRequestMessage(); + + msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", BearerToken); + return Task.FromResult(msg); + } + +} \ No newline at end of file From 4a641118da75ff2b30efc4eeb517683eb83dae9a Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:10:24 +0300 Subject: [PATCH 42/45] fix: unused files removed --- .../Extensions/AuthorizeAtributre.cs | 18 + .../openApiContracts.json | 1696 +++++++++++++++++ 2 files changed, 1714 insertions(+) create mode 100644 Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs create mode 100644 Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json diff --git a/Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs b/Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs new file mode 100644 index 0000000..fe28a66 --- /dev/null +++ b/Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs @@ -0,0 +1,18 @@ +using Do_Svyazi.User.Domain.Authenticate; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; + +namespace Do_Svyazi.User.Application.Extensions; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] +public class AuthorizeAttribute : Attribute, IAuthorizationFilter +{ + public void OnAuthorization(AuthorizationFilterContext context) + { + if (context.HttpContext.Items["User"] is not LoginModel _) + { + context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized }; + } + } +} \ No newline at end of file diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json new file mode 100644 index 0000000..b81dc19 --- /dev/null +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json @@ -0,0 +1,1696 @@ +{ + "x-generator": "NSwag v13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))", + "openapi": "3.0.0", + "info": { + "title": "Do-Svyazi user module", + "version": "2.1.0" + }, + "paths": { + "/api/Authenticate/GetAll": { + "get": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_GetAll", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessengerUser" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Authenticate/Login": { + "post": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_Login", + "requestBody": { + "x-name": "model", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LoginRequest" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Authenticate/Register": { + "post": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_Register", + "requestBody": { + "x-name": "model", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RegisterCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/Authenticate/AuthenticateByJwt": { + "get": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_AuthenticateByJwt", + "parameters": [ + { + "name": "jwtToken", + "in": "header", + "required": true, + "schema": { + "type": "string", + "nullable": true + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AuthenticateResponse" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Authenticate/RegisterAdmin": { + "post": { + "tags": [ + "Authenticate" + ], + "operationId": "Authenticate_RegisterAdmin", + "requestBody": { + "x-name": "model", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RegisterAdminCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/Chat/GetChats": { + "get": { + "tags": [ + "Chat" + ], + "operationId": "Chat_GetChats", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessengerChatDto" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Chat/GetChatById": { + "get": { + "tags": [ + "Chat" + ], + "operationId": "Chat_GetChatById", + "parameters": [ + { + "name": "chatId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MessengerChatDto" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Chat/GetUserIdsByChatId": { + "get": { + "tags": [ + "Chat" + ], + "operationId": "Chat_GetUserIdsByChatId", + "parameters": [ + { + "name": "chatId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "string", + "format": "guid" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Chat/GetUsersByChatId": { + "get": { + "tags": [ + "Chat" + ], + "operationId": "Chat_GetUsersByChatId", + "parameters": [ + { + "name": "chatId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ChatUserDto" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Chat/AddChannel": { + "post": { + "tags": [ + "Chat" + ], + "operationId": "Chat_AddChannel", + "requestBody": { + "x-name": "addChannelCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddChannelCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" + } + } + } + }, + "/api/Chat/AddGroupChat": { + "post": { + "tags": [ + "Chat" + ], + "operationId": "Chat_AddGroupChat", + "requestBody": { + "x-name": "addGroupChatCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddGroupChatCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" + } + } + } + }, + "/api/Chat/AddPersonalChat": { + "post": { + "tags": [ + "Chat" + ], + "operationId": "Chat_AddPersonalChat", + "requestBody": { + "x-name": "addPersonalChatCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddPersonalChatCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" + } + } + } + }, + "/api/Chat/AddSavedMessages": { + "post": { + "tags": [ + "Chat" + ], + "operationId": "Chat_AddSavedMessages", + "requestBody": { + "x-name": "addSavedMessagesCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddSavedMessagesCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "" + } + } + } + }, + "/api/Chat/AddUserToChat": { + "post": { + "tags": [ + "Chat" + ], + "operationId": "Chat_AddUserToChat", + "requestBody": { + "x-name": "addUserToChatCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddUserToChatCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/Chat/DeleteUserFromChat": { + "delete": { + "tags": [ + "Chat" + ], + "operationId": "Chat_DeleteUserFromChat", + "requestBody": { + "x-name": "deleteUserFromChatCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeleteUserFromChatCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/Roles/GetRoleByUserId": { + "get": { + "tags": [ + "Roles" + ], + "operationId": "Roles_GetRoleByUserId", + "parameters": [ + { + "name": "userId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + }, + { + "name": "chatId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 2 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RoleDto" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/Roles/CreateRoleForChat": { + "post": { + "tags": [ + "Roles" + ], + "operationId": "Roles_CreateRoleForChat", + "requestBody": { + "x-name": "createRoleForChatCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateRoleForChatCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/Roles/ChangeRoleForUserById": { + "post": { + "tags": [ + "Roles" + ], + "operationId": "Roles_ChangeRoleForUserById", + "requestBody": { + "x-name": "changeRoleForUserByIdCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ChangeRoleForUserByIdCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/User/GetAll": { + "get": { + "tags": [ + "User" + ], + "operationId": "User_GetUsers", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessengerUserDto" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/User/GetUser": { + "get": { + "tags": [ + "User" + ], + "operationId": "User_GetUser", + "parameters": [ + { + "name": "userId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MessengerUserDto" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/User/GetAllChatsByUserId": { + "get": { + "tags": [ + "User" + ], + "operationId": "User_GetAllChatsByUserId", + "parameters": [ + { + "name": "userId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/MessengerChatDto" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/User/GetAllChatsIdsByUserId": { + "get": { + "tags": [ + "User" + ], + "operationId": "User_GetAllChatsIdsByUserId", + "parameters": [ + { + "name": "userId", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "guid" + }, + "x-position": 1 + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "string", + "format": "guid" + } + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + } + } + } + }, + "/api/User/SetNickNameById": { + "post": { + "tags": [ + "User" + ], + "operationId": "User_SetNickNameById", + "requestBody": { + "x-name": "setUserNickNameByIdCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SetUserNickNameByIdCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/User/DeleteUser": { + "post": { + "tags": [ + "User" + ], + "operationId": "User_DeleteUser", + "requestBody": { + "x-name": "deleteUserCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeleteUserCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/User/AddUser": { + "post": { + "tags": [ + "User" + ], + "operationId": "User_AddUser", + "requestBody": { + "x-name": "addUserCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AddUserCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string", + "format": "guid" + } + } + } + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "201": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "string", + "format": "guid" + } + } + } + } + } + } + }, + "/api/User/ChangeDescription": { + "post": { + "tags": [ + "User" + ], + "operationId": "User_ChangeDescription", + "requestBody": { + "x-name": "changeUserDescriptionByIdCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ChangeUserDescriptionByIdCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + }, + "/api/User/ChangeName": { + "post": { + "tags": [ + "User" + ], + "operationId": "User_ChangeName", + "requestBody": { + "x-name": "changeUserNameByIdCommand", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ChangeUserNameByIdCommand" + } + } + }, + "required": true, + "x-position": 1 + }, + "responses": { + "200": { + "description": "" + }, + "401": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "500": { + "description": "" + }, + "204": { + "description": "" + } + } + } + } + }, + "components": { + "schemas": { + "MessengerUser": { + "allOf": [ + { + "$ref": "#/components/schemas/IdentityUserOfGuid" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + } + } + ] + }, + "IdentityUserOfGuid": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "format": "guid" + }, + "userName": { + "type": "string", + "nullable": true + }, + "normalizedUserName": { + "type": "string", + "nullable": true + }, + "email": { + "type": "string", + "nullable": true + }, + "normalizedEmail": { + "type": "string", + "nullable": true + }, + "emailConfirmed": { + "type": "boolean" + }, + "passwordHash": { + "type": "string", + "nullable": true + }, + "securityStamp": { + "type": "string", + "nullable": true + }, + "concurrencyStamp": { + "type": "string", + "nullable": true + }, + "phoneNumber": { + "type": "string", + "nullable": true + }, + "phoneNumberConfirmed": { + "type": "boolean" + }, + "twoFactorEnabled": { + "type": "boolean" + }, + "lockoutEnd": { + "type": "string", + "format": "date-time", + "nullable": true + }, + "lockoutEnabled": { + "type": "boolean" + }, + "accessFailedCount": { + "type": "integer", + "format": "int32" + } + } + }, + "ProblemDetails": { + "type": "object", + "additionalProperties": { + "nullable": true + }, + "properties": { + "type": { + "type": "string", + "nullable": true + }, + "title": { + "type": "string", + "nullable": true + }, + "status": { + "type": "integer", + "format": "int32", + "nullable": true + }, + "detail": { + "type": "string", + "nullable": true + }, + "instance": { + "type": "string", + "nullable": true + }, + "extensions": { + "type": "object", + "additionalProperties": {} + } + } + }, + "LoginRequest": { + "type": "object", + "additionalProperties": false, + "properties": { + "model": { + "$ref": "#/components/schemas/LoginModel" + } + } + }, + "LoginModel": { + "type": "object", + "additionalProperties": false, + "required": [ + "password" + ], + "properties": { + "userName": { + "type": "string", + "nullable": true + }, + "email": { + "type": "string", + "nullable": true + }, + "password": { + "type": "string", + "minLength": 1 + } + } + }, + "RegisterCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "model": { + "$ref": "#/components/schemas/RegisterModel" + } + } + }, + "RegisterModel": { + "type": "object", + "additionalProperties": false, + "required": [ + "userName", + "email", + "password" + ], + "properties": { + "userName": { + "type": "string", + "minLength": 1 + }, + "name": { + "type": "string" + }, + "email": { + "type": "string", + "minLength": 1 + }, + "password": { + "type": "string", + "minLength": 1 + }, + "phoneNumber": { + "type": "string" + } + } + }, + "AuthenticateResponse": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "validTo": { + "type": "string", + "format": "date-time" + } + } + }, + "RegisterAdminCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "model": { + "$ref": "#/components/schemas/RegisterModel" + } + } + }, + "MessengerChatDto": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string", + "nullable": true + }, + "description": { + "type": "string", + "nullable": true + }, + "users": { + "type": "array", + "items": { + "type": "string", + "format": "guid" + } + }, + "roles": { + "type": "array", + "items": { + "$ref": "#/components/schemas/RoleDto" + } + } + } + }, + "RoleDto": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "canEditMessages": { + "$ref": "#/components/schemas/ActionOption" + }, + "canDeleteMessages": { + "$ref": "#/components/schemas/ActionOption" + }, + "canWriteMessages": { + "$ref": "#/components/schemas/ActionOption" + }, + "canReadMessages": { + "$ref": "#/components/schemas/ActionOption" + }, + "canAddUsers": { + "$ref": "#/components/schemas/ActionOption" + }, + "canDeleteUsers": { + "$ref": "#/components/schemas/ActionOption" + }, + "canPinMessages": { + "$ref": "#/components/schemas/ActionOption" + }, + "canSeeChannelMembers": { + "$ref": "#/components/schemas/ActionOption" + }, + "canInviteOtherUsers": { + "$ref": "#/components/schemas/ActionOption" + }, + "canEditChannelDescription": { + "$ref": "#/components/schemas/ActionOption" + }, + "canDeleteChat": { + "$ref": "#/components/schemas/ActionOption" + } + } + }, + "ActionOption": { + "type": "integer", + "description": "", + "x-enumNames": [ + "Unavailable", + "Enabled", + "Disabled" + ], + "enum": [ + 0, + 1, + 2 + ] + }, + "ChatUserDto": { + "type": "object", + "additionalProperties": false, + "properties": { + "chatUserName": { + "type": "string" + }, + "messengerUserId": { + "type": "string", + "format": "guid" + }, + "role": { + "$ref": "#/components/schemas/RoleDto" + } + } + }, + "AddChannelCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "adminId": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + } + }, + "AddGroupChatCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "adminId": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + } + }, + "AddPersonalChatCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "firstUserId": { + "type": "string", + "format": "guid" + }, + "secondUserId": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + } + }, + "AddSavedMessagesCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + } + } + }, + "AddUserToChatCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "chatId": { + "type": "string", + "format": "guid" + } + } + }, + "DeleteUserFromChatCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "chatId": { + "type": "string", + "format": "guid" + } + } + }, + "CreateRoleForChatCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "role": { + "$ref": "#/components/schemas/RoleDto" + }, + "chatId": { + "type": "string", + "format": "guid" + } + } + }, + "ChangeRoleForUserByIdCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "chatId": { + "type": "string", + "format": "guid" + }, + "role": { + "$ref": "#/components/schemas/RoleDto" + } + } + }, + "MessengerUserDto": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string", + "nullable": true + }, + "userName": { + "type": "string", + "nullable": true + }, + "description": { + "type": "string", + "nullable": true + } + } + }, + "SetUserNickNameByIdCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "userName": { + "type": "string" + } + } + }, + "DeleteUserCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + } + } + }, + "AddUserCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "nickName": { + "type": "string" + }, + "description": { + "type": "string" + } + } + }, + "ChangeUserDescriptionByIdCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "description": { + "type": "string" + } + } + }, + "ChangeUserNameByIdCommand": { + "type": "object", + "additionalProperties": false, + "properties": { + "userId": { + "type": "string", + "format": "guid" + }, + "name": { + "type": "string" + } + } + } + } + } +} \ No newline at end of file From 5822be8b1130105f70a6391d0af587239d313226 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:11:02 +0300 Subject: [PATCH 43/45] fix: wrong response type --- .../Do-Svyazi.User.Web.Controllers/AuthenticateController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs index 118c39a..1ce044d 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs +++ b/Source/Presentation/Do-Svyazi.User.Web.Controllers/AuthenticateController.cs @@ -49,7 +49,7 @@ public async Task Register([FromBody] RegisterCommand model, Cance } [HttpGet(nameof(AuthenticateByJwt))] - public async Task> AuthenticateByJwt( + public async Task> AuthenticateByJwt( [FromHeader] string jwtToken, CancellationToken cancellationToken) { var result = await _mediator.Send(new AuthenticateByJwtRequest(jwtToken), cancellationToken); From 1467862bd1b77392879224011e9b54ced9f1adab Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:12:17 +0300 Subject: [PATCH 44/45] fix: unused files removed again --- .../Extensions/AuthorizeAtributre.cs | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs diff --git a/Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs b/Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs deleted file mode 100644 index fe28a66..0000000 --- a/Source/Application/Do-Svyazi.User.Application/Extensions/AuthorizeAtributre.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Do_Svyazi.User.Domain.Authenticate; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Do_Svyazi.User.Application.Extensions; - -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] -public class AuthorizeAttribute : Attribute, IAuthorizationFilter -{ - public void OnAuthorization(AuthorizationFilterContext context) - { - if (context.HttpContext.Items["User"] is not LoginModel _) - { - context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized }; - } - } -} \ No newline at end of file From b27375a70d0e3a9102c9d3ff55b65d7eba3660f5 Mon Sep 17 00:00:00 2001 From: Mikhail Libchenko Date: Sat, 9 Jul 2022 00:13:32 +0300 Subject: [PATCH 45/45] fix: OpenApiContracts output renamed --- .../Do-Svyazi.User.Web.ApiClient/nswag.json | 2 +- .../openApiContracts.json | 1696 ----------------- 2 files changed, 1 insertion(+), 1697 deletions(-) delete mode 100644 Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json index eec5f08..f598733 100644 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json +++ b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/nswag.json @@ -46,7 +46,7 @@ "createWebHostBuilderMethod": null, "startupType": null, "allowNullableBodyParameters": true, - "output": "openApiContracts.json", + "output": "swagger.json", "outputType": "OpenApi3", "newLineBehavior": "Auto", "assemblyPaths": [], diff --git a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json b/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json deleted file mode 100644 index b81dc19..0000000 --- a/Source/Presentation/Do-Svyazi.User.Web.ApiClient/openApiContracts.json +++ /dev/null @@ -1,1696 +0,0 @@ -{ - "x-generator": "NSwag v13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v13.0.0.0))", - "openapi": "3.0.0", - "info": { - "title": "Do-Svyazi user module", - "version": "2.1.0" - }, - "paths": { - "/api/Authenticate/GetAll": { - "get": { - "tags": [ - "Authenticate" - ], - "operationId": "Authenticate_GetAll", - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/MessengerUser" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Authenticate/Login": { - "post": { - "tags": [ - "Authenticate" - ], - "operationId": "Authenticate_Login", - "requestBody": { - "x-name": "model", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/LoginRequest" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Authenticate/Register": { - "post": { - "tags": [ - "Authenticate" - ], - "operationId": "Authenticate_Register", - "requestBody": { - "x-name": "model", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/RegisterCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/Authenticate/AuthenticateByJwt": { - "get": { - "tags": [ - "Authenticate" - ], - "operationId": "Authenticate_AuthenticateByJwt", - "parameters": [ - { - "name": "jwtToken", - "in": "header", - "required": true, - "schema": { - "type": "string", - "nullable": true - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AuthenticateResponse" - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Authenticate/RegisterAdmin": { - "post": { - "tags": [ - "Authenticate" - ], - "operationId": "Authenticate_RegisterAdmin", - "requestBody": { - "x-name": "model", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/RegisterAdminCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/Chat/GetChats": { - "get": { - "tags": [ - "Chat" - ], - "operationId": "Chat_GetChats", - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/MessengerChatDto" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Chat/GetChatById": { - "get": { - "tags": [ - "Chat" - ], - "operationId": "Chat_GetChatById", - "parameters": [ - { - "name": "chatId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/MessengerChatDto" - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Chat/GetUserIdsByChatId": { - "get": { - "tags": [ - "Chat" - ], - "operationId": "Chat_GetUserIdsByChatId", - "parameters": [ - { - "name": "chatId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "type": "string", - "format": "guid" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Chat/GetUsersByChatId": { - "get": { - "tags": [ - "Chat" - ], - "operationId": "Chat_GetUsersByChatId", - "parameters": [ - { - "name": "chatId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ChatUserDto" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Chat/AddChannel": { - "post": { - "tags": [ - "Chat" - ], - "operationId": "Chat_AddChannel", - "requestBody": { - "x-name": "addChannelCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddChannelCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "201": { - "description": "" - } - } - } - }, - "/api/Chat/AddGroupChat": { - "post": { - "tags": [ - "Chat" - ], - "operationId": "Chat_AddGroupChat", - "requestBody": { - "x-name": "addGroupChatCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddGroupChatCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "201": { - "description": "" - } - } - } - }, - "/api/Chat/AddPersonalChat": { - "post": { - "tags": [ - "Chat" - ], - "operationId": "Chat_AddPersonalChat", - "requestBody": { - "x-name": "addPersonalChatCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddPersonalChatCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "201": { - "description": "" - } - } - } - }, - "/api/Chat/AddSavedMessages": { - "post": { - "tags": [ - "Chat" - ], - "operationId": "Chat_AddSavedMessages", - "requestBody": { - "x-name": "addSavedMessagesCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddSavedMessagesCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "201": { - "description": "" - } - } - } - }, - "/api/Chat/AddUserToChat": { - "post": { - "tags": [ - "Chat" - ], - "operationId": "Chat_AddUserToChat", - "requestBody": { - "x-name": "addUserToChatCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddUserToChatCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/Chat/DeleteUserFromChat": { - "delete": { - "tags": [ - "Chat" - ], - "operationId": "Chat_DeleteUserFromChat", - "requestBody": { - "x-name": "deleteUserFromChatCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DeleteUserFromChatCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/Roles/GetRoleByUserId": { - "get": { - "tags": [ - "Roles" - ], - "operationId": "Roles_GetRoleByUserId", - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - }, - { - "name": "chatId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 2 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/RoleDto" - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/Roles/CreateRoleForChat": { - "post": { - "tags": [ - "Roles" - ], - "operationId": "Roles_CreateRoleForChat", - "requestBody": { - "x-name": "createRoleForChatCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/CreateRoleForChatCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/Roles/ChangeRoleForUserById": { - "post": { - "tags": [ - "Roles" - ], - "operationId": "Roles_ChangeRoleForUserById", - "requestBody": { - "x-name": "changeRoleForUserByIdCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ChangeRoleForUserByIdCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/User/GetAll": { - "get": { - "tags": [ - "User" - ], - "operationId": "User_GetUsers", - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/MessengerUserDto" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/User/GetUser": { - "get": { - "tags": [ - "User" - ], - "operationId": "User_GetUser", - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/MessengerUserDto" - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/User/GetAllChatsByUserId": { - "get": { - "tags": [ - "User" - ], - "operationId": "User_GetAllChatsByUserId", - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/MessengerChatDto" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/User/GetAllChatsIdsByUserId": { - "get": { - "tags": [ - "User" - ], - "operationId": "User_GetAllChatsIdsByUserId", - "parameters": [ - { - "name": "userId", - "in": "query", - "required": true, - "schema": { - "type": "string", - "format": "guid" - }, - "x-position": 1 - } - ], - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "array", - "items": { - "type": "string", - "format": "guid" - } - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - } - } - } - }, - "/api/User/SetNickNameById": { - "post": { - "tags": [ - "User" - ], - "operationId": "User_SetNickNameById", - "requestBody": { - "x-name": "setUserNickNameByIdCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SetUserNickNameByIdCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/User/DeleteUser": { - "post": { - "tags": [ - "User" - ], - "operationId": "User_DeleteUser", - "requestBody": { - "x-name": "deleteUserCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DeleteUserCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/User/AddUser": { - "post": { - "tags": [ - "User" - ], - "operationId": "User_AddUser", - "requestBody": { - "x-name": "addUserCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddUserCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "string", - "format": "guid" - } - } - } - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "201": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "string", - "format": "guid" - } - } - } - } - } - } - }, - "/api/User/ChangeDescription": { - "post": { - "tags": [ - "User" - ], - "operationId": "User_ChangeDescription", - "requestBody": { - "x-name": "changeUserDescriptionByIdCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ChangeUserDescriptionByIdCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - }, - "/api/User/ChangeName": { - "post": { - "tags": [ - "User" - ], - "operationId": "User_ChangeName", - "requestBody": { - "x-name": "changeUserNameByIdCommand", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ChangeUserNameByIdCommand" - } - } - }, - "required": true, - "x-position": 1 - }, - "responses": { - "200": { - "description": "" - }, - "401": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProblemDetails" - } - } - } - }, - "500": { - "description": "" - }, - "204": { - "description": "" - } - } - } - } - }, - "components": { - "schemas": { - "MessengerUser": { - "allOf": [ - { - "$ref": "#/components/schemas/IdentityUserOfGuid" - }, - { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string" - }, - "description": { - "type": "string" - } - } - } - ] - }, - "IdentityUserOfGuid": { - "type": "object", - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "userName": { - "type": "string", - "nullable": true - }, - "normalizedUserName": { - "type": "string", - "nullable": true - }, - "email": { - "type": "string", - "nullable": true - }, - "normalizedEmail": { - "type": "string", - "nullable": true - }, - "emailConfirmed": { - "type": "boolean" - }, - "passwordHash": { - "type": "string", - "nullable": true - }, - "securityStamp": { - "type": "string", - "nullable": true - }, - "concurrencyStamp": { - "type": "string", - "nullable": true - }, - "phoneNumber": { - "type": "string", - "nullable": true - }, - "phoneNumberConfirmed": { - "type": "boolean" - }, - "twoFactorEnabled": { - "type": "boolean" - }, - "lockoutEnd": { - "type": "string", - "format": "date-time", - "nullable": true - }, - "lockoutEnabled": { - "type": "boolean" - }, - "accessFailedCount": { - "type": "integer", - "format": "int32" - } - } - }, - "ProblemDetails": { - "type": "object", - "additionalProperties": { - "nullable": true - }, - "properties": { - "type": { - "type": "string", - "nullable": true - }, - "title": { - "type": "string", - "nullable": true - }, - "status": { - "type": "integer", - "format": "int32", - "nullable": true - }, - "detail": { - "type": "string", - "nullable": true - }, - "instance": { - "type": "string", - "nullable": true - }, - "extensions": { - "type": "object", - "additionalProperties": {} - } - } - }, - "LoginRequest": { - "type": "object", - "additionalProperties": false, - "properties": { - "model": { - "$ref": "#/components/schemas/LoginModel" - } - } - }, - "LoginModel": { - "type": "object", - "additionalProperties": false, - "required": [ - "password" - ], - "properties": { - "userName": { - "type": "string", - "nullable": true - }, - "email": { - "type": "string", - "nullable": true - }, - "password": { - "type": "string", - "minLength": 1 - } - } - }, - "RegisterCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "model": { - "$ref": "#/components/schemas/RegisterModel" - } - } - }, - "RegisterModel": { - "type": "object", - "additionalProperties": false, - "required": [ - "userName", - "email", - "password" - ], - "properties": { - "userName": { - "type": "string", - "minLength": 1 - }, - "name": { - "type": "string" - }, - "email": { - "type": "string", - "minLength": 1 - }, - "password": { - "type": "string", - "minLength": 1 - }, - "phoneNumber": { - "type": "string" - } - } - }, - "AuthenticateResponse": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "validTo": { - "type": "string", - "format": "date-time" - } - } - }, - "RegisterAdminCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "model": { - "$ref": "#/components/schemas/RegisterModel" - } - } - }, - "MessengerChatDto": { - "type": "object", - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string", - "nullable": true - }, - "description": { - "type": "string", - "nullable": true - }, - "users": { - "type": "array", - "items": { - "type": "string", - "format": "guid" - } - }, - "roles": { - "type": "array", - "items": { - "$ref": "#/components/schemas/RoleDto" - } - } - } - }, - "RoleDto": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string" - }, - "canEditMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canDeleteMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canWriteMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canReadMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canAddUsers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canDeleteUsers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canPinMessages": { - "$ref": "#/components/schemas/ActionOption" - }, - "canSeeChannelMembers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canInviteOtherUsers": { - "$ref": "#/components/schemas/ActionOption" - }, - "canEditChannelDescription": { - "$ref": "#/components/schemas/ActionOption" - }, - "canDeleteChat": { - "$ref": "#/components/schemas/ActionOption" - } - } - }, - "ActionOption": { - "type": "integer", - "description": "", - "x-enumNames": [ - "Unavailable", - "Enabled", - "Disabled" - ], - "enum": [ - 0, - 1, - 2 - ] - }, - "ChatUserDto": { - "type": "object", - "additionalProperties": false, - "properties": { - "chatUserName": { - "type": "string" - }, - "messengerUserId": { - "type": "string", - "format": "guid" - }, - "role": { - "$ref": "#/components/schemas/RoleDto" - } - } - }, - "AddChannelCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "adminId": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - }, - "description": { - "type": "string" - } - } - }, - "AddGroupChatCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "adminId": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - }, - "description": { - "type": "string" - } - } - }, - "AddPersonalChatCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "firstUserId": { - "type": "string", - "format": "guid" - }, - "secondUserId": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - }, - "description": { - "type": "string" - } - } - }, - "AddSavedMessagesCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - }, - "description": { - "type": "string" - } - } - }, - "AddUserToChatCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "chatId": { - "type": "string", - "format": "guid" - } - } - }, - "DeleteUserFromChatCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "chatId": { - "type": "string", - "format": "guid" - } - } - }, - "CreateRoleForChatCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "role": { - "$ref": "#/components/schemas/RoleDto" - }, - "chatId": { - "type": "string", - "format": "guid" - } - } - }, - "ChangeRoleForUserByIdCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "chatId": { - "type": "string", - "format": "guid" - }, - "role": { - "$ref": "#/components/schemas/RoleDto" - } - } - }, - "MessengerUserDto": { - "type": "object", - "additionalProperties": false, - "properties": { - "id": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string", - "nullable": true - }, - "userName": { - "type": "string", - "nullable": true - }, - "description": { - "type": "string", - "nullable": true - } - } - }, - "SetUserNickNameByIdCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "userName": { - "type": "string" - } - } - }, - "DeleteUserCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - } - } - }, - "AddUserCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "type": "string" - }, - "nickName": { - "type": "string" - }, - "description": { - "type": "string" - } - } - }, - "ChangeUserDescriptionByIdCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "description": { - "type": "string" - } - } - }, - "ChangeUserNameByIdCommand": { - "type": "object", - "additionalProperties": false, - "properties": { - "userId": { - "type": "string", - "format": "guid" - }, - "name": { - "type": "string" - } - } - } - } - } -} \ No newline at end of file