Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaMustafayev committed Aug 2, 2023
2 parents 6eec7aa + c3d93ee commit a9ad0d7
Show file tree
Hide file tree
Showing 77 changed files with 337 additions and 232 deletions.
31 changes: 16 additions & 15 deletions API/API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'API - Development' "/>
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="7.4.0"/>
<PackageReference Include="GraphQL.Server.Ui.Voyager" Version="7.4.0"/>
<PackageReference Include="HotChocolate.Abstractions" Version="13.0.5"/>
<PackageReference Include="HotChocolate.AspNetCore" Version="13.0.5"/>
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="13.0.5"/>
<PackageReference Include="JetBrains.ReSharper.CommandLineTools" Version="2023.1.0">
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="7.5.0"/>
<PackageReference Include="GraphQL.Server.Ui.Voyager" Version="7.5.0"/>
<PackageReference Include="HotChocolate.Abstractions" Version="13.3.3"/>
<PackageReference Include="HotChocolate.AspNetCore" Version="13.3.3"/>
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="13.3.3"/>
<PackageReference Include="JetBrains.ReSharper.CommandLineTools" Version="2023.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.2.22"/>
<PackageReference Include="NLog.Database" Version="5.1.3"/>
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3"/>
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.3"/>
<PackageReference Include="Redis.OM" Version="0.5.0"/>
<PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.3.8"/>
<PackageReference Include="MongoDB.Driver" Version="2.20.0"/>
<PackageReference Include="NLog.Database" Version="5.2.2"/>
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.2"/>
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.2"/>
<PackageReference Include="Redis.OM" Version="0.5.2"/>
<PackageReference Include="Scrutor" Version="4.2.2"/>
<PackageReference Include="Sentry.AspNetCore" Version="3.30.0"/>
<PackageReference Include="Sentry.AspNetCore" Version="3.34.0"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0"/>
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.2.22"/>
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8"/>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0"/>
</ItemGroup>

Expand Down
29 changes: 17 additions & 12 deletions API/Containers/DependencyContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
using CORE.Concrete;
using CORE.Config;
using CORE.Constants;
using CORE.ElasticSearch;
using CORE.Logging;
using DAL.Concrete;
using DAL.UnitOfWorks.Abstract;
using DAL.UnitOfWorks.Concrete;
using DAL.ElasticSearch;
using DAL.EntityFramework.Concrete;
using DAL.EntityFramework.UnitOfWork;
using DAL.MongoDb;
using DTO.User;
using MediatR;
using MEDIATRS.MediatR;
Expand Down Expand Up @@ -188,7 +188,7 @@ public static void RegisterSignalRHubs(this IServiceCollection services)

public static void RegisterAntiForgeryToken(this IServiceCollection services)
{
services.AddAntiforgery(options => { options.HeaderName = "X-XSRF-TOKEN"; });
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
}

public static void RegisterUnitOfWork(this IServiceCollection services)
Expand All @@ -198,14 +198,25 @@ public static void RegisterUnitOfWork(this IServiceCollection services)

public static void RegisterOutputCache(this IServiceCollection services)
{
services.AddOutputCache(options => { options.AddBasePolicy(builder => { builder.Expire(TimeSpan.FromMinutes(2)); }); });
services.AddOutputCache(options => options.AddBasePolicy(builder => builder.Expire(TimeSpan.FromMinutes(2))));
}

public static void RegisterRedis(this IServiceCollection services, ConfigSettings config)
{
services.AddSingleton(new RedisConnectionProvider(config.RedisSettings.Connection));
}

public static void RegisterMongoDb(this IServiceCollection services)
{
services.AddSingleton<IMongoDbService, MongoDbService>();
}

public static void RegisterElasticSearch(this IServiceCollection services, ConfigSettings configs)
{
services.AddScoped<IElasticSearchService<UserToListDto>>(_ =>
new ElasticSearchService<UserToListDto>(configs.ElasticSearchSettings.Connection, configs.ElasticSearchSettings.DefaultIndex));
}

public static void RegisterHttpClients(this IServiceCollection services, ConfigSettings config)
{
services.AddHttpClient(config.FirstHttpClientSettings.Name, client =>
Expand All @@ -230,12 +241,6 @@ public static void RegisterMediatr(this IServiceCollection services)
);
}

public static void RegisterElasticSearch(this IServiceCollection services, ConfigSettings configs)
{
services.AddScoped<IElasticSearchService<UserToListDto>>(_ =>
new ElasticSearchService<UserToListDto>(configs.ElasticSearchSettings.Connection, configs.ElasticSearchSettings.DefaultIndex));
}

public static void RegisterMiniProfiler(this IServiceCollection services)
{
services.AddMiniProfiler(options =>
Expand Down
10 changes: 8 additions & 2 deletions API/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CORE.Config;
using CORE.Helper;
using CORE.Localization;
using DAL.MongoDb;
using DTO.Auth;
using DTO.Responses;
using Microsoft.AspNetCore.Authentication.JwtBearer;
Expand All @@ -22,17 +23,22 @@ public class AuthController : Controller
{
private readonly IAuthService _authService;
private readonly ConfigSettings _configSettings;
private readonly IMongoDbService _mongoDbService;
private readonly ITokenService _tokenService;
private readonly IUtilService _utilService;

public AuthController(IAuthService authService, ConfigSettings configSettings,
public AuthController(
IAuthService authService,
ConfigSettings configSettings,
IUtilService utilService,
ITokenService tokenService)
ITokenService tokenService,
IMongoDbService mongoDbService)
{
_authService = authService;
_configSettings = configSettings;
_utilService = utilService;
_tokenService = tokenService;
_mongoDbService = mongoDbService;
}

[SwaggerOperation(Summary = "login")]
Expand Down
11 changes: 4 additions & 7 deletions API/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ namespace API.Controllers;
[ValidateToken]
public class FileController : Controller
{
private readonly IWebHostEnvironment _environment;
private readonly IFileService _fileService;
private readonly IUserService _userService;
private readonly IUtilService _utilService;

public FileController(
IWebHostEnvironment environment,
IUserService userService,
IFileService fileService,
IUtilService utilService
)
{
_environment = environment;
_userService = userService;
_fileService = fileService;
_utilService = utilService;
Expand All @@ -60,7 +57,7 @@ public async Task<IActionResult> Upload(IFormFile file, [FromQuery] FileType typ
var hashFileName = Guid.NewGuid().ToString();
var fileExtension = Path.GetExtension(file.FileName);

var path = Path.Combine(_environment.WebRootPath, _utilService.GetFolderName(type));
var path = _utilService.GetEnvFolderPath(_utilService.GetFolderName(type));
await FileHelper.WriteFile(file, $"{hashFileName}{fileExtension}", path);

// add to database
Expand Down Expand Up @@ -95,7 +92,7 @@ public async Task<IActionResult> Delete([FromQuery] string hashName, [FromQuery]
}

// delete file
var path = Path.Combine(_environment.WebRootPath, _utilService.GetFolderName(type), hashName);
var path = Path.Combine(_utilService.GetEnvFolderPath(_utilService.GetFolderName(type)), hashName);
FileHelper.DeleteFile(path);

// remove from database
Expand Down Expand Up @@ -124,7 +121,7 @@ public async Task<IActionResult> Download([FromQuery] string hashName, [FromQuer
var file = await _fileService.GetAsync(hashName);

// read file as stream
var path = Path.Combine(_environment.WebRootPath, _utilService.GetFolderName(type), $"{hashName}{file.Data!.Extension}");
var path = Path.Combine(_utilService.GetEnvFolderPath(_utilService.GetFolderName(type)), $"{hashName}{file.Data!.Extension}");

return PhysicalFile(path, "APPLICATION/octet-stream", Path.GetFileName(hashName));
}
Expand All @@ -138,7 +135,7 @@ public async Task<IActionResult> Get([FromQuery] string hashName, [FromQuery] Fi
var file = await _fileService.GetAsync(hashName);

// read file as stream
var path = Path.Combine(_environment.WebRootPath, _utilService.GetFolderName(type), $"{hashName}{file.Data!.Extension}");
var path = Path.Combine(_utilService.GetEnvFolderPath(_utilService.GetFolderName(type)), $"{hashName}{file.Data!.Extension}");
var fileStream = System.IO.File.OpenRead(path);

if (fileStream is null) return BadRequest(new ErrorResult(Messages.FileIsNotFound.Translate()));
Expand Down
5 changes: 1 addition & 4 deletions API/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ namespace API.Controllers;
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public class UserController : Controller
{
private readonly IWebHostEnvironment _environment;
private readonly IUserService _userService;
private readonly IUtilService _utilService;

public UserController(IUserService userService, IWebHostEnvironment environment,
IUtilService utilService)
public UserController(IUserService userService, IUtilService utilService)
{
_userService = userService;
_environment = environment;
_utilService = utilService;
}

Expand Down
11 changes: 5 additions & 6 deletions API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using BLL.Mappers;
using CORE.Config;
using CORE.Constants;
using DAL.DatabaseContext;
using DAL.EntityFramework.Context;
using DTO.Auth.Validators;
using FluentValidation;
using FluentValidation.AspNetCore;
Expand Down Expand Up @@ -51,6 +51,7 @@
}

if (config.ElasticSearchSettings.IsEnabled) builder.Services.RegisterElasticSearch(config);
if (config.MongoDbSettings.IsEnabled) builder.Services.RegisterMongoDb();

builder.Services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 60 * 1024 * 1024); //60mb

Expand All @@ -70,14 +71,12 @@
.AddSorting()
.AddFiltering();


builder.Services.AddHealthChecks();

builder.Services.RegisterAuthentication(config);

builder.Services.AddCors(o =>
o.AddPolicy(Constants.EnableAllCorsName,
b => b.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin()));
o.AddPolicy(Constants.EnableAllCorsName, b => b.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin()));

builder.Services.AddScoped<LogActionFilter>();

Expand All @@ -98,7 +97,7 @@
if (config.SwaggerSettings.IsEnabled) app.UseSwagger();

if (config.SwaggerSettings.IsEnabled)
app.UseSwaggerUI(c => c.InjectStylesheet($"/swagger_ui/{config.SwaggerSettings.Theme}.css"));
app.UseSwaggerUI(c => c.InjectStylesheet(config.SwaggerSettings.Theme));

AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

Expand All @@ -108,7 +107,7 @@
app.UseMiddleware<ExceptionMiddleware>();

// anti forgery token implementation
//app.UseMiddleware<AntiForgeryTokenValidator>();
// app.UseMiddleware<AntiForgeryTokenValidator>();

app.UseOutputCache();
app.UseHttpsRedirection();
Expand Down
7 changes: 6 additions & 1 deletion API/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"Connection": "http://localhost:9200",
"DefaultIndex": "logmodeltest1"
},
"MongoDbSettings": {
"IsEnabled": true,
"Connection": "mongodb://localhost:27017",
"Database": "testdb"
},
"SentrySettings": {
"IsEnabled": false
},
Expand All @@ -49,7 +54,7 @@
"IsEnabled": true,
"Title": "REST API - DEV",
"Version": "v1",
"Theme": "dark"
"Theme": "/swagger_ui/dark.css"
},
"RequestSettings": {
"PageIndex": "PageIndex",
Expand Down
7 changes: 6 additions & 1 deletion API/appsettings.Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"Connection": "http://localhost:9200",
"DefaultIndex": "logmodeltest1"
},
"MongoDbSettings": {
"IsEnabled": true,
"Connection": "mongodb://localhost:27017",
"Database": "logdbtest1"
},
"SentrySettings": {
"IsEnabled": false
},
Expand All @@ -49,7 +54,7 @@
"IsEnabled": true,
"Title": "REST API - PROD",
"Version": "v1",
"Theme": "dark"
"Theme": "/swagger_ui/dark.css"
},
"RequestSettings": {
"PageIndex": "PageIndex",
Expand Down
2 changes: 1 addition & 1 deletion BLL/Abstract/IPermissionService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DAL.Utility;
using DAL.EntityFramework.Utility;
using DTO.Permission;
using DTO.Responses;

Expand Down
2 changes: 1 addition & 1 deletion BLL/Abstract/IUserService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DAL.Utility;
using DAL.EntityFramework.Utility;
using DTO.Responses;
using DTO.User;

Expand Down
2 changes: 1 addition & 1 deletion BLL/BLL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1"/>
<PackageReference Include="JetBrains.ReSharper.CommandLineTools" Version="2023.1.0">
<PackageReference Include="JetBrains.ReSharper.CommandLineTools" Version="2023.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion BLL/Concrete/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using CORE.Abstract;
using CORE.Helper;
using CORE.Localization;
using DAL.UnitOfWorks.Abstract;
using DAL.EntityFramework.UnitOfWork;
using DTO.Auth;
using DTO.Responses;
using DTO.User;
Expand Down
2 changes: 1 addition & 1 deletion BLL/Concrete/FileService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using AutoMapper;
using BLL.Abstract;
using CORE.Localization;
using DAL.UnitOfWorks.Abstract;
using DAL.EntityFramework.UnitOfWork;
using DTO.File;
using DTO.Responses;
using File = ENTITIES.Entities.File;
Expand Down
2 changes: 1 addition & 1 deletion BLL/Concrete/LoggingService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AutoMapper;
using BLL.Abstract;
using DAL.UnitOfWorks.Abstract;
using DAL.EntityFramework.UnitOfWork;
using DTO.Logging;
using ENTITIES.Entities;

Expand Down
4 changes: 2 additions & 2 deletions BLL/Concrete/PermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using BLL.Abstract;
using CORE.Abstract;
using CORE.Localization;
using DAL.UnitOfWorks.Abstract;
using DAL.Utility;
using DAL.EntityFramework.UnitOfWork;
using DAL.EntityFramework.Utility;
using DTO.Permission;
using DTO.Responses;
using ENTITIES.Entities;
Expand Down
2 changes: 1 addition & 1 deletion BLL/Concrete/RoleService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using AutoMapper;
using BLL.Abstract;
using CORE.Localization;
using DAL.UnitOfWorks.Abstract;
using DAL.EntityFramework.UnitOfWork;
using DTO.Permission;
using DTO.Responses;
using DTO.Role;
Expand Down
2 changes: 1 addition & 1 deletion BLL/Concrete/TokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using CORE.Config;
using CORE.Helper;
using CORE.Localization;
using DAL.UnitOfWorks.Abstract;
using DAL.EntityFramework.UnitOfWork;
using DTO.Auth;
using DTO.Responses;
using DTO.Token;
Expand Down
4 changes: 2 additions & 2 deletions BLL/Concrete/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using CORE.Abstract;
using CORE.Helper;
using CORE.Localization;
using DAL.UnitOfWorks.Abstract;
using DAL.Utility;
using DAL.EntityFramework.UnitOfWork;
using DAL.EntityFramework.Utility;
using DTO.Responses;
using DTO.User;
using ENTITIES.Entities;
Expand Down
Loading

0 comments on commit a9ad0d7

Please sign in to comment.