Commit 626a2c9b authored by hasan khaddour's avatar hasan khaddour

read settings from appsitting

parent bf203fbc
...@@ -38,7 +38,8 @@ namespace PSManagement.Infrastructure.Persistence.DI ...@@ -38,7 +38,8 @@ namespace PSManagement.Infrastructure.Persistence.DI
services.AddScoped<IEmployeesRepository, EmployeesRespository>(); services.AddScoped<IEmployeesRepository, EmployeesRespository>();
services.AddScoped<IStepsRepository, StepsRepository>(); services.AddScoped<IStepsRepository, StepsRepository>();
services.AddScoped<IFinancialSpendingRepository, FinancialSpendingRepository>(); services.AddScoped<IFinancialSpendingRepository, FinancialSpendingRepository>();
services.AddScoped<ITracksRepository, TracksRepository>(); services.AddScoped<ITracksRepository, TracksRepository>();
services.AddScoped<IProjectTypesRepository, ProjectsTypesRepository>();
services.AddScoped<ProjectBuilder>(); services.AddScoped<ProjectBuilder>();
services.AddScoped(typeof(IRepository<>), typeof(BaseRepository<>)); services.AddScoped(typeof(IRepository<>), typeof(BaseRepository<>));
......
...@@ -34,7 +34,8 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration ...@@ -34,7 +34,8 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
); );
builder.HasOne(e => e.ProjectType) builder.HasOne(e => e.ProjectType)
.WithMany(); .WithMany()
.HasForeignKey(e=>e.ProjectTypeId);
...@@ -93,6 +94,7 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration ...@@ -93,6 +94,7 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
{ {
builder.HasOne(e => e.Project) builder.HasOne(e => e.Project)
.WithOne(e => e.ProjectCompletion) .WithOne(e => e.ProjectCompletion)
; ;
} }
} }
......
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class AddProjectTypeForegin : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Projects_ProjectType_ProjectTypeId",
table: "Projects");
migrationBuilder.AlterColumn<int>(
name: "ProjectTypeId",
table: "Projects",
type: "int",
nullable: true,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Projects_ProjectType_ProjectTypeId",
table: "Projects",
column: "ProjectTypeId",
principalTable: "ProjectType",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Projects_ProjectType_ProjectTypeId",
table: "Projects");
migrationBuilder.AlterColumn<int>(
name: "ProjectTypeId",
table: "Projects",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddForeignKey(
name: "FK_Projects_ProjectType_ProjectTypeId",
table: "Projects",
column: "ProjectTypeId",
principalTable: "ProjectType",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
}
}
...@@ -315,7 +315,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -315,7 +315,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.Property<int>("ProjectManagerId") b.Property<int>("ProjectManagerId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int?>("ProjectTypeId") b.Property<int>("ProjectTypeId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int?>("ProjectTypeId1") b.Property<int?>("ProjectTypeId1")
...@@ -745,7 +745,9 @@ namespace PSManagement.Infrastructure.Persistence.Migrations ...@@ -745,7 +745,9 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.HasOne("PSManagement.Domain.Projects.Entities.ProjectType", "ProjectType") b.HasOne("PSManagement.Domain.Projects.Entities.ProjectType", "ProjectType")
.WithMany() .WithMany()
.HasForeignKey("ProjectTypeId"); .HasForeignKey("ProjectTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PSManagement.Domain.Projects.Entities.ProjectType", null) b.HasOne("PSManagement.Domain.Projects.Entities.ProjectType", null)
.WithMany("Projects") .WithMany("Projects")
......
...@@ -10,4 +10,5 @@ namespace PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository ...@@ -10,4 +10,5 @@ namespace PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository
{ {
} }
} }
} }
using Microsoft.EntityFrameworkCore;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.Infrastructure.Persistence.Repositories.Base;
using PSManagement.SharedKernel.Interfaces;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PSManagement.Infrastructure.Persistence.Repositories.ProjectRepository
{
public class ProjectsTypesRepository : BaseRepository<ProjectType>, IProjectTypesRepository
{
public ProjectsTypesRepository(AppDbContext context) : base(context)
{
}
public async Task<IEnumerable<ProjectType>> GetByTypeName(string typeName, ISpecification<ProjectType> specification = null)
{
IQueryable<ProjectType> query = ApplySpecification(specification);
return await query.Where(e => e.TypeName == typeName).ToListAsync();
}
}
}
...@@ -10,12 +10,12 @@ using System.Threading.Tasks; ...@@ -10,12 +10,12 @@ using System.Threading.Tasks;
namespace PSManagement.Infrastructure.BackgroundServcies namespace PSManagement.Infrastructure.BackgroundServcies
{ {
public class BackgroundJobSyncEmployees: BackgroundService public class CronJobSyncEmployees: BackgroundService
{ {
private readonly IServiceScopeFactory _scopeFactory; private readonly IServiceScopeFactory _scopeFactory;
private readonly int _syncIntervalInMinutes; private readonly int _syncIntervalInMinutes;
public BackgroundJobSyncEmployees( public CronJobSyncEmployees(
IOptions<EmployeesSyncJobSettings> settings, IOptions<EmployeesSyncJobSettings> settings,
IServiceScopeFactory scopeFactory) IServiceScopeFactory scopeFactory)
{ {
......
...@@ -31,14 +31,16 @@ namespace PSManagement.Infrastructure.DI ...@@ -31,14 +31,16 @@ namespace PSManagement.Infrastructure.DI
services services
.AddAuthentication(configuration) .AddAuthentication(configuration)
.AddAuthorization() .AddAuthorization()
.AddServices() .AddServices(configuration)
.AddBackgroundServices(configuration); .AddBackgroundServices(configuration);
return services; return services;
} }
private static IServiceCollection AddServices(this IServiceCollection services) private static IServiceCollection AddServices(this IServiceCollection services, IConfiguration configuration)
{ {
services.Configure<FileServiceSettings>(configuration.GetSection(FileServiceSettings.SectionName));
services.AddSingleton<IDateTimeProvider, DateTimeProvider>(); services.AddSingleton<IDateTimeProvider, DateTimeProvider>();
services.AddScoped<IEmployeesProvider, EmployeesProvider>(); services.AddScoped<IEmployeesProvider, EmployeesProvider>();
services.AddScoped<ICurrentUserProvider,CurrentUserProvider>(); services.AddScoped<ICurrentUserProvider,CurrentUserProvider>();
...@@ -54,7 +56,7 @@ namespace PSManagement.Infrastructure.DI ...@@ -54,7 +56,7 @@ namespace PSManagement.Infrastructure.DI
services.AddScoped<ISyncEmployeesService, SyncEmployeesService>(); services.AddScoped<ISyncEmployeesService, SyncEmployeesService>();
services.AddScoped<IOccupancySystemNotifier,OccupancySystemNotifier>(); services.AddScoped<IOccupancySystemNotifier,OccupancySystemNotifier>();
services.AddHostedService<BackgroundJobSyncEmployees>(); services.AddHostedService<CronJobSyncEmployees>();
return services; return services;
} }
...@@ -71,6 +73,7 @@ namespace PSManagement.Infrastructure.DI ...@@ -71,6 +73,7 @@ namespace PSManagement.Infrastructure.DI
private static IServiceCollection AddAuthentication(this IServiceCollection services, IConfiguration configuration) private static IServiceCollection AddAuthentication(this IServiceCollection services, IConfiguration configuration)
{ {
services.Configure<JwtSetting>(configuration.GetSection(JwtSetting.Section)); services.Configure<JwtSetting>(configuration.GetSection(JwtSetting.Section));
services.AddSingleton<IJwtTokenGenerator, JwtTokenGenerator>(); services.AddSingleton<IJwtTokenGenerator, JwtTokenGenerator>();
services.AddScoped<IAuthenticationService, AuthenticationService>(); services.AddScoped<IAuthenticationService, AuthenticationService>();
......
...@@ -4,5 +4,4 @@ ...@@ -4,5 +4,4 @@
{ {
public int SyncIntervalInMinutes { get; set; } public int SyncIntervalInMinutes { get; set; }
} }
} }
namespace PSManagement.Infrastructure.Settings
{
public class FileServiceSettings
{
public const string SectionName = "FileServiceSettings";
public string[] AvailableExtension { get; set; } = null!;
}
}
using Ardalis.Result; using Ardalis.Result;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using PSManagement.Application.Contracts.Storage; using PSManagement.Application.Contracts.Storage;
using PSManagement.Infrastructure.Settings;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
...@@ -12,9 +14,14 @@ namespace PSManagement.Infrastructure.Services.Storage ...@@ -12,9 +14,14 @@ namespace PSManagement.Infrastructure.Services.Storage
{ {
public class FileService : IFileService public class FileService : IFileService
{ {
private readonly string[] _availableExtension;
public FileService(IOptions<FileServiceSettings> fileServiceOptions)
{
_availableExtension = fileServiceOptions.Value.AvailableExtension;
}
public async Task<Result<String>> StoreFile(string fileName, IFormFile file) public async Task<Result<String>> StoreFile(string fileName, IFormFile file)
{ {
var allowedExtensions = new string[] { ".pdf", ".png" };
if (file is null) if (file is null)
{ {
return Result.Invalid(new ValidationError("File couldn't be empty.")); return Result.Invalid(new ValidationError("File couldn't be empty."));
...@@ -22,7 +29,7 @@ namespace PSManagement.Infrastructure.Services.Storage ...@@ -22,7 +29,7 @@ namespace PSManagement.Infrastructure.Services.Storage
} }
var extension = Path.GetExtension(file.FileName); var extension = Path.GetExtension(file.FileName);
if (!allowedExtensions.Contains(extension.ToLower())) if (!_availableExtension.Contains(extension.ToLower()))
{ {
return Result.Invalid(new ValidationError("File type not allowed.")); return Result.Invalid(new ValidationError("File type not allowed."));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment