Skip to content

Commit

Permalink
New Repositories, working on background services
Browse files Browse the repository at this point in the history
  • Loading branch information
novru authored and novru committed May 18, 2024
1 parent b577f6e commit dacd385
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Api.Extensions;
using Api.GlobalException;
using Application.Models.Configurations;
using Infrastructure.BackgroundServices;
using Infrastructure.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Persistence.Context;
Expand All @@ -18,9 +19,8 @@
builder.Services.AddSwaggerGen();

builder.Services
.AddInfrastructureServices()
.AddPersistenceRepositories();

.AddPersistenceRepositories()
.AddInfrastructureServices();

builder.Services.AddAuthenticationAndAuthorization(builder.Configuration);
builder.Services.AddSwagger();
Expand Down
2 changes: 2 additions & 0 deletions Core/Application/Models/Requests/BanUserRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ public class BanUserRequest
public string UserId { get; set; }
public DateTime BanDate { get; set; }
public string ReasonContent { get; set; }
public int UnbanAfter { get; set; }
public bool UnbanWithHours { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Application.Repositories.Repository;
using Domain.Models;

namespace Application.Repositories.BannedUserRepository;

public interface IReadBannedUserRepository : IReadRepository<BannedUser>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Application.Repositories.Repository;
using Domain.Models;

namespace Application.Repositories.BannedUserRepository;

public interface IWriteBannedUserRepository : IWriteRepository<BannedUser>
{
}
6 changes: 5 additions & 1 deletion Core/Application/Repositories/IUnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Application.Repositories.BookRepository;
using Application.Repositories.BannedUserRepository;
using Application.Repositories.BookRepository;
using Application.Repositories.CommentRepository;
using Application.Repositories.CourseRepository;
using Application.Repositories.UserRepository;
Expand All @@ -17,4 +18,7 @@ public interface IUnitOfWork
IWriteCourseRepository WriteCourseRepository { get; }
IReadCommentRepository ReadCommentRepository { get; }
IWriteCommentRepository WriteCommentRepository { get;}

IReadBannedUserRepository ReadBannedUserRepository { get; }
IWriteBannedUserRepository WriteBannedUserRepository { get; }
}
10 changes: 10 additions & 0 deletions Domain/Models/BannedUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Domain.Models.Common;

namespace Domain.Models;

public class BannedUser : BaseEntity
{
public string ReasonContent { get; set; }
public DateTime BannedDate { get; set; }
public DateTime UnbanDate { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Repositories;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace Infrastructure.BackgroundServices;

public class ForbiddenCommentChecker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Log.Information("Forbidden Message Checker -- B Service started working.");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Application.Services;
using Infrastructure.BackgroundServices;
using Infrastructure.Services;
using Microsoft.Extensions.DependencyInjection;
using System.Runtime.CompilerServices;
Expand All @@ -23,6 +24,10 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti

services.AddScoped<IBlobService, BlobService>();

// hosted services

services.AddHostedService<ForbiddenCommentChecker>();

return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Persistence.Repositories.CourseRepository;
using Persistence.Repositories.UserRepository;
using Persistence.Repositories;
using Application.Repositories.BannedUserRepository;
using Persistence.Repositories.BannedUserRepository;

namespace Persistence.DependencyInjection;

Expand All @@ -28,6 +30,9 @@ public static IServiceCollection AddPersistenceRepositories(this IServiceCollect
services.AddScoped<IReadCommentRepository, ReadCommentRepository>();
services.AddScoped<IWriteCommentRepository, WriteCommentRepository>();

services.AddScoped<IReadBannedUserRepository, ReadBannedUserRepository>();
services.AddScoped<IWriteBannedUserRepository, WriteBannedUserRepository>();

services.AddScoped<IUnitOfWork, UnitOfWork>();

return services;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Repositories.BannedUserRepository;
using Domain.Models;
using Persistence.Context;
using Persistence.Repositories.Repository;

namespace Persistence.Repositories.BannedUserRepository;

public class ReadBannedUserRepository : ReadRepository<BannedUser>, IReadBannedUserRepository
{
public ReadBannedUserRepository(AppDbContext context) : base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Application.Repositories.BannedUserRepository;
using Domain.Models;
using Persistence.Context;
using Persistence.Repositories.Repository;

namespace Persistence.Repositories.BannedUserRepository;

public class WriteBannedUserRepository : WriteRepository<BannedUser>, IWriteBannedUserRepository
{
public WriteBannedUserRepository(AppDbContext context) : base(context)
{
}
}
7 changes: 6 additions & 1 deletion Infrastructure/Persistence/Repositories/UnitOfWork.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Application.Repositories;
using Application.Repositories.BannedUserRepository;
using Application.Repositories.BookRepository;
using Application.Repositories.CommentRepository;
using Application.Repositories.CourseRepository;
Expand All @@ -8,7 +9,7 @@ namespace Persistence.Repositories;

public class UnitOfWork : IUnitOfWork
{
public UnitOfWork(IReadBookRepository readBookRepository, IWriteBookRepository writeBookRepository, IReadUserRepository readUserRepository, IWriteUserRepository writeUserRepository, IReadCourseRepository readCourseRepository, IWriteCourseRepository writeCourseRepository, IReadCommentRepository readCommentRepository, IWriteCommentRepository writeCommentRepository)
public UnitOfWork(IReadBookRepository readBookRepository, IWriteBookRepository writeBookRepository, IReadUserRepository readUserRepository, IWriteUserRepository writeUserRepository, IReadCourseRepository readCourseRepository, IWriteCourseRepository writeCourseRepository, IReadCommentRepository readCommentRepository, IWriteCommentRepository writeCommentRepository, IReadBannedUserRepository readBannedUserRepository, IWriteBannedUserRepository writeBannedUserRepository)
{
ReadBookRepository = readBookRepository;
WriteBookRepository = writeBookRepository;
Expand All @@ -18,6 +19,8 @@ public UnitOfWork(IReadBookRepository readBookRepository, IWriteBookRepository w
WriteCourseRepository = writeCourseRepository;
ReadCommentRepository = readCommentRepository;
WriteCommentRepository = writeCommentRepository;
ReadBannedUserRepository = readBannedUserRepository;
WriteBannedUserRepository = writeBannedUserRepository;
}

public IReadBookRepository ReadBookRepository { get; }
Expand All @@ -28,4 +31,6 @@ public UnitOfWork(IReadBookRepository readBookRepository, IWriteBookRepository w
public IWriteCourseRepository WriteCourseRepository { get; }
public IReadCommentRepository ReadCommentRepository { get; }
public IWriteCommentRepository WriteCommentRepository { get; }
public IReadBannedUserRepository ReadBannedUserRepository { get; }
public IWriteBannedUserRepository WriteBannedUserRepository { get; }
}

0 comments on commit dacd385

Please sign in to comment.