chore: project clean
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
||||||
|
|
||||||
namespace GamificationService.Database.Repositories;
|
namespace GamificationService.Database.Repositories;
|
||||||
|
|
||||||
@@ -16,8 +15,8 @@ public class GenericRepository<TEntity> where TEntity : class
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual IQueryable<TEntity> Get(
|
public virtual IQueryable<TEntity> Get(
|
||||||
Expression<Func<TEntity, bool>> filter = null,
|
Expression<Func<TEntity, bool>>? filter = null,
|
||||||
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
|
||||||
string includeProperties = "")
|
string includeProperties = "")
|
||||||
{
|
{
|
||||||
IQueryable<TEntity> query = dbSet;
|
IQueryable<TEntity> query = dbSet;
|
||||||
|
|||||||
@@ -4,25 +4,18 @@ namespace GamificationService.Database.Repositories;
|
|||||||
|
|
||||||
public class UnitOfWork : IDisposable
|
public class UnitOfWork : IDisposable
|
||||||
{
|
{
|
||||||
#region fields
|
#region fields
|
||||||
|
|
||||||
private ApplicationContext _context;
|
protected ApplicationContext _context;
|
||||||
|
private IDbContextTransaction? _transaction;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
private IDbContextTransaction _transaction;
|
|
||||||
|
|
||||||
public UnitOfWork(ApplicationContext context)
|
public UnitOfWork(ApplicationContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public bool Save()
|
public bool Save()
|
||||||
{
|
{
|
||||||
return _context.SaveChanges() > 0;
|
return _context.SaveChanges() > 0;
|
||||||
@@ -33,26 +26,13 @@ public class UnitOfWork : IDisposable
|
|||||||
return await _context.SaveChangesAsync() > 0;
|
return await _context.SaveChangesAsync() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool disposed = false;
|
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (!this.disposed)
|
|
||||||
{
|
|
||||||
if (disposing)
|
|
||||||
{
|
|
||||||
_context.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.disposed = true;
|
|
||||||
}
|
|
||||||
public async Task BeginTransactionAsync()
|
public async Task BeginTransactionAsync()
|
||||||
{
|
{
|
||||||
if (_transaction is not null)
|
if (_transaction is not null)
|
||||||
throw new InvalidOperationException("A transaction has already been started.");
|
throw new InvalidOperationException("A transaction has already been started.");
|
||||||
_transaction = await _context.Database.BeginTransactionAsync();
|
_transaction = await _context.Database.BeginTransactionAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CommitAsync()
|
public async Task CommitAsync()
|
||||||
{
|
{
|
||||||
if (_transaction is null)
|
if (_transaction is null)
|
||||||
@@ -61,16 +41,29 @@ public class UnitOfWork : IDisposable
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _transaction.CommitAsync();
|
await _transaction.CommitAsync();
|
||||||
_transaction.Dispose();
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
await _transaction.DisposeAsync();
|
||||||
_transaction = null;
|
_transaction = null;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
}
|
||||||
|
|
||||||
|
private bool disposed = false;
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (_transaction is not null)
|
if (!disposed)
|
||||||
await _transaction.RollbackAsync();
|
{
|
||||||
throw;
|
if (disposing)
|
||||||
|
{
|
||||||
|
_transaction?.Dispose(); // Dispose transaction if it exists
|
||||||
|
_context.Dispose();
|
||||||
|
}
|
||||||
|
disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.Cookies;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception related to cookie operations.
|
|
||||||
/// </summary>
|
|
||||||
public class CookiesException : Exception
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="CookiesException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public CookiesException() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="CookiesException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public CookiesException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="CookiesException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public CookiesException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.Cookies;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception related to deleting cookies.
|
|
||||||
/// </summary>
|
|
||||||
public class DeleteCookiesException : CookiesException
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="DeleteCookiesException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public DeleteCookiesException() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="DeleteCookiesException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public DeleteCookiesException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="DeleteCookiesException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public DeleteCookiesException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.Cookies;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception related to setting cookies.
|
|
||||||
/// </summary>
|
|
||||||
public class SetCookiesException : CookiesException
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetCookiesException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public SetCookiesException() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetCookiesException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public SetCookiesException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SetCookiesException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public SetCookiesException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.Email;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception related to email operations.
|
|
||||||
/// </summary>
|
|
||||||
public class EmailException : Exception
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="EmailException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public EmailException() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="EmailException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public EmailException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="EmailException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public EmailException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.Email;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception that occurs during the process of sending an email.
|
|
||||||
/// </summary>
|
|
||||||
public class SendEmailException : EmailException
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SendEmailException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public SendEmailException() : base("An error occurred while sending the email.") { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SendEmailException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public SendEmailException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="SendEmailException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public SendEmailException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.JWT;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception that occurs while generating a JWT token.
|
|
||||||
/// </summary>
|
|
||||||
public class GenerateJWTTokenException : JWTException
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="GenerateJWTTokenException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public GenerateJWTTokenException() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="GenerateJWTTokenException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public GenerateJWTTokenException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="GenerateJWTTokenException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public GenerateJWTTokenException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
namespace GamificationService.Exceptions.UtilServices.JWT;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an exception related to JWT (JSON Web Token) operations.
|
|
||||||
/// </summary>
|
|
||||||
public class JWTException : Exception
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="JWTException"/> class.
|
|
||||||
/// </summary>
|
|
||||||
public JWTException() : base() { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="JWTException"/> class with a specified error message.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The message that describes the error.</param>
|
|
||||||
public JWTException(string message) : base(message) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="JWTException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="message">The error message that explains the reason for the exception.</param>
|
|
||||||
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
|
|
||||||
public JWTException(string message, Exception innerException) : base(message, innerException) { }
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Net.Mail;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using GamificationService.Database;
|
using GamificationService.Database;
|
||||||
using GamificationService.Database.Repositories;
|
using GamificationService.Database.Repositories;
|
||||||
using GamificationService.Logs;
|
using GamificationService.Loggging;
|
||||||
using GamificationService.Mapper;
|
using GamificationService.Mapper;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -69,7 +67,7 @@ public static class SwaggerExtensions
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddSwagger(this IServiceCollection services)
|
public static IServiceCollection AddSwagger(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
string projectName = Assembly.GetExecutingAssembly().GetName().Name;
|
string projectName = Assembly.GetExecutingAssembly().GetName().Name!;
|
||||||
services.AddOpenApi();
|
services.AddOpenApi();
|
||||||
services.AddEndpointsApiExplorer();
|
services.AddEndpointsApiExplorer();
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
|
|||||||
24
Logging/LoggingConfigurator.cs
Executable file
24
Logging/LoggingConfigurator.cs
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Exceptions;
|
||||||
|
|
||||||
|
namespace GamificationService.Loggging;
|
||||||
|
|
||||||
|
public static class LoggingConfigurator
|
||||||
|
{
|
||||||
|
public static void ConfigureLogging(){
|
||||||
|
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
|
||||||
|
var configuration = new ConfigurationBuilder()
|
||||||
|
.AddJsonFile("appsettings.json",optional:false,reloadOnChange:true).Build();
|
||||||
|
Console.WriteLine(environment);
|
||||||
|
Console.WriteLine(configuration);
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.Enrich.FromLogContext()
|
||||||
|
.Enrich.WithExceptionDetails()
|
||||||
|
.WriteTo.Debug()
|
||||||
|
.WriteTo.Console()
|
||||||
|
.Enrich.WithProperty("Environment",environment)
|
||||||
|
.ReadFrom.Configuration(configuration)
|
||||||
|
.CreateLogger();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,5 +3,5 @@ namespace GamificationService.Models.BasicResponses;
|
|||||||
public class BasicResponse
|
public class BasicResponse
|
||||||
{
|
{
|
||||||
public short Code { get; set; }
|
public short Code { get; set; }
|
||||||
public string Message { get; set; }
|
public string Message { get; set; } = "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user