initial commit from an older template

This commit is contained in:
2025-09-20 22:33:35 +03:00
commit b6778046c2
134 changed files with 6657 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
using GamificationService.Exceptions.UtilServices.Cookies;
namespace GamificationService.Services.Cookies;
public class CookieService : ICookieService
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly ILogger<CookieService> _logger;
private readonly IConfiguration _configuration;
public CookieService(IHttpContextAccessor httpContextAccessor, ILogger<CookieService> logger, IConfiguration configuration)
{
_httpContextAccessor = httpContextAccessor;
_logger = logger;
_configuration = configuration;
}
public Task<bool> SetCookie(string key, string value, CookieOptions options)
{
try
{
_logger.LogDebug("Adding cookie {CookieKey} with value {CookieValue}", key, value);
_httpContextAccessor.HttpContext.Response.Cookies.Append(key, value, options);
return Task.FromResult(true);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to add cookie {CookieKey}", key);
throw new SetCookiesException(ex.Message);
}
}
public async Task<bool> RemoveCookie(string key)
{
try
{
_logger.LogDebug("Deleting cookie {CookieKey}", key);
_httpContextAccessor.HttpContext.Response.Cookies.Delete(key);
return await Task.FromResult(true);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to delete cookie {CookieKey}", key);
throw new DeleteCookiesException(ex.Message);
}
}
}