| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Business.HelperModels | namespace Diligent.WebAPI.Business.HelperModels | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class DeleteCustomerRequest | public class DeleteCustomerRequest | ||||
| { | { | ||||
| public string? Id { get; set; } | public string? Id { get; set; } |
| using MongoDB.Driver; | using MongoDB.Driver; | ||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Diligent.WebAPI.Business.Services | namespace Diligent.WebAPI.Business.Services | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class AuthorizationService : BaseMongo<Customer> | public class AuthorizationService : BaseMongo<Customer> | ||||
| { | { | ||||
| public AuthorizationService(IOptions<WebApiDatabaseSettings> webApiDatabaseSettings) : | public AuthorizationService(IOptions<WebApiDatabaseSettings> webApiDatabaseSettings) : |
| using Diligent.WebAPI.Data; | using Diligent.WebAPI.Data; | ||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Business.MongoServices | namespace Diligent.WebAPI.Business.MongoServices | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class BaseMongo<T> where T : class | public class BaseMongo<T> where T : class | ||||
| { | { | ||||
| protected readonly IMongoCollection<T> _mongoCollection; | protected readonly IMongoCollection<T> _mongoCollection; |
| using MongoDB.Driver; | using MongoDB.Driver; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Data | namespace Diligent.WebAPI.Data | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class MongoDBContext : IMongoDBContext | public class MongoDBContext : IMongoDBContext | ||||
| { | { | ||||
| private readonly IConfiguration _configuration; | private readonly IConfiguration _configuration; |
| using MongoDB.Bson; | using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Data.Entities | namespace Diligent.WebAPI.Data.Entities | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class BaseMongo | public class BaseMongo | ||||
| { | { | ||||
| [BsonId] | [BsonId] |
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Diligent.WebAPI.Data | namespace Diligent.WebAPI.Data | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class WebApiDatabaseSettings | public class WebApiDatabaseSettings | ||||
| { | { | ||||
| public string ConnectionString { get; set; } = null!; | public string ConnectionString { get; set; } = null!; |
| using Diligent.WebAPI.Host.Mediator.Authentication.Queries; | using Diligent.WebAPI.Host.Mediator.Authentication.Queries; | ||||
| using MediatR; | using MediatR; | ||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Controllers | namespace Diligent.WebAPI.Host.Controllers | ||||
| { | { | ||||
| [ApiVersion("1.0")] | [ApiVersion("1.0")] | ||||
| [ApiController] | [ApiController] | ||||
| [Route("v{version:apiVersion}/[controller]")] | [Route("v{version:apiVersion}/[controller]")] | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class AuthenticationController : ControllerBase | public class AuthenticationController : ControllerBase | ||||
| { | { | ||||
| // password for every user in database is "Nekasifra123!" | // password for every user in database is "Nekasifra123!" |
| using Diligent.WebAPI.Host.Mediator.Notifications.Queries; | using Diligent.WebAPI.Host.Mediator.Notifications.Queries; | ||||
| using MediatR; | using MediatR; | ||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Controllers | namespace Diligent.WebAPI.Host.Controllers | ||||
| { | { | ||||
| [ApiVersion("1.0")] | [ApiVersion("1.0")] | ||||
| [ApiController] | [ApiController] | ||||
| [Route("v{version:apiVersion}/[controller]")] | [Route("v{version:apiVersion}/[controller]")] | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class NotificationController : ControllerBase | public class NotificationController : ControllerBase | ||||
| { | { | ||||
| private readonly IMediator _mediator; | private readonly IMediator _mediator; |
| using Diligent.WebAPI.Host.Mediator.Request.Queries; | using Diligent.WebAPI.Host.Mediator.Request.Queries; | ||||
| using MediatR; | using MediatR; | ||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Controllers | namespace Diligent.WebAPI.Host.Controllers | ||||
| { | { | ||||
| [ApiVersion("1.0")] | [ApiVersion("1.0")] | ||||
| [ApiController] | [ApiController] | ||||
| [Route("v{version:apiVersion}/[controller]")] | [Route("v{version:apiVersion}/[controller]")] | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class RequestController:ControllerBase | public class RequestController:ControllerBase | ||||
| { | { | ||||
| private readonly IMediator _mediator; | private readonly IMediator _mediator; |
| using MediatR; | using MediatR; | ||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Controllers | namespace Diligent.WebAPI.Host.Controllers | ||||
| { | { | ||||
| [ApiVersion("1.0")] | [ApiVersion("1.0")] | ||||
| [ApiController] | [ApiController] | ||||
| [Route("v{version:apiVersion}/[controller]")] | [Route("v{version:apiVersion}/[controller]")] | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class RoomController : ControllerBase | public class RoomController : ControllerBase | ||||
| { | { | ||||
| private readonly IMediator _mediator; | private readonly IMediator _mediator; |
| namespace Diligent.WebAPI.Host.DTOs.Chat | |||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.DTOs.Chat | |||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class LeaveChatRoomDTO | public class LeaveChatRoomDTO | ||||
| { | { | ||||
| public string ConnId { get; set; } | public string ConnId { get; set; } |
| namespace Diligent.WebAPI.Host.DTOs.Notification | |||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.DTOs.Notification | |||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class NotificationReadDTO | public class NotificationReadDTO | ||||
| { | { | ||||
| public string RoomId { get; set; } | public string RoomId { get; set; } |
| namespace Diligent.WebAPI.Host.DTOs.Request | |||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.DTOs.Request | |||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class AcceptCustomerDTO | public class AcceptCustomerDTO | ||||
| { | { | ||||
| public string customerId { get; set; } | public string customerId { get; set; } |
| using System.Runtime.Serialization; | |||||
| namespace Diligent.WebAPI.Host.Exceptions | |||||
| namespace Diligent.WebAPI.Host.Exceptions | |||||
| { | { | ||||
| public class BaseException : Exception | public class BaseException : Exception | ||||
| { | { | ||||
| public BaseException() { } | public BaseException() { } | ||||
| public BaseException(string? message) : base(message) { } | public BaseException(string? message) : base(message) { } | ||||
| public BaseException(string message, Exception innerException) : base(message, innerException) { } | |||||
| public BaseException(SerializationInfo info, StreamingContext context) : base(info, context) { } | |||||
| } | } | ||||
| } | } |
| { | { | ||||
| public class NotFoundException : BaseException | public class NotFoundException : BaseException | ||||
| { | { | ||||
| public NotFoundException() { } | public NotFoundException() { } | ||||
| public NotFoundException(string? message) : base(message) { } | public NotFoundException(string? message) : base(message) { } | ||||
| public NotFoundException(string message, Exception innerException) : base(message, innerException) { } | |||||
| public NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } | |||||
| } | } | ||||
| } | } |
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Extensions | namespace Diligent.WebAPI.Host.Extensions | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public static class ApiConfiguration | public static class ApiConfiguration | ||||
| { | { | ||||
| public static void ConfigureServices(IServiceCollection services) | public static void ConfigureServices(IServiceCollection services) |
| using Diligent.WebAPI.Host.Middlewares; | using Diligent.WebAPI.Host.Middlewares; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Extensions | namespace Diligent.WebAPI.Host.Extensions | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public static class ExceptionHandlingMiddlewareExtensions | public static class ExceptionHandlingMiddlewareExtensions | ||||
| { | { | ||||
| public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) | public static void ConfigureCustomExceptionMiddleware(this IApplicationBuilder app) |
| | | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Extensions; | namespace Diligent.WebAPI.Host.Extensions; | ||||
| [ExcludeFromCodeCoverage] | |||||
| public static class WebApp | public static class WebApp | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public static void SetupData(this WebApplication app) | public static void SetupData(this WebApplication app) | ||||
| { | { | ||||
| app.ConfigureCustomExceptionMiddleware(); | app.ConfigureCustomExceptionMiddleware(); |
| using Diligent.WebAPI.Business.Services; | using Diligent.WebAPI.Business.Services; | ||||
| using Diligent.WebAPI.Host.Middlewares; | using Diligent.WebAPI.Host.Middlewares; | ||||
| using Diligent.WebAPI.Business.Interfaces; | using Diligent.WebAPI.Business.Interfaces; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Extensions; | namespace Diligent.WebAPI.Host.Extensions; | ||||
| [ExcludeFromCodeCoverage] | |||||
| public static class WebAppBuilder | public static class WebAppBuilder | ||||
| { | { | ||||
| public static void ConfigureData(this WebApplicationBuilder builder, IConfiguration configuration) | public static void ConfigureData(this WebApplicationBuilder builder, IConfiguration configuration) | ||||
| { | { | ||||
| // database configuration | // database configuration |
| using AutoMapper; | using AutoMapper; | ||||
| using Diligent.WebAPI.Data.Entities; | using Diligent.WebAPI.Data.Entities; | ||||
| using Diligent.WebAPI.Host.DTOs.Notification; | using Diligent.WebAPI.Host.DTOs.Notification; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Mapper | namespace Diligent.WebAPI.Host.Mapper | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class NotificationMappingProfile : Profile | public class NotificationMappingProfile : Profile | ||||
| { | { | ||||
| public NotificationMappingProfile() | public NotificationMappingProfile() |
| using Diligent.WebAPI.Host.Mediator.Authentication.Commands; | using Diligent.WebAPI.Host.Mediator.Authentication.Commands; | ||||
| using MediatR; | using MediatR; | ||||
| using Microsoft.AspNetCore.Identity; | using Microsoft.AspNetCore.Identity; | ||||
| using System.Diagnostics.CodeAnalysis; | |||||
| namespace Diligent.WebAPI.Host.Mediator.Authentication.Handlers | namespace Diligent.WebAPI.Host.Mediator.Authentication.Handlers | ||||
| { | { | ||||
| [ExcludeFromCodeCoverage] | |||||
| public class AddRoleHandler : IRequestHandler<AddRoleCommand, Unit> | public class AddRoleHandler : IRequestHandler<AddRoleCommand, Unit> | ||||
| { | { | ||||
| private readonly RoleManager<Roles> _roleManager; | private readonly RoleManager<Roles> _roleManager; |
| Customer customer = await _customerService.GetCustomer(customerLoginDTO.Username); | Customer customer = await _customerService.GetCustomer(customerLoginDTO.Username); | ||||
| var customerReadDTO = _mapper.Map<CustomerReadDTO>(customer); | var customerReadDTO = _mapper.Map<CustomerReadDTO>(customer); | ||||
| customerReadDTO.Token = await _authenticationService.GenerateToken(); | |||||
| customerReadDTO.Token = await _authenticationService.GenerateToken() ?? ""; | |||||
| customerReadDTO.Roles = (List<string>)await _customerManager.GetRolesAsync(customer); | customerReadDTO.Roles = (List<string>)await _customerManager.GetRolesAsync(customer); | ||||
| return customerReadDTO; | return customerReadDTO; | ||||
| } | } |