fix(api): в кэш добавлены дополнительные данные о пользователе

This commit is contained in:
Mikhail Trubnikov
2023-12-05 09:14:51 +10:00
parent 4c7c5090db
commit f5ce75598c
3 changed files with 18 additions and 1 deletions

View File

@@ -3,6 +3,11 @@
public class UserCache public class UserCache
{ {
public required string UserIp { get; set; } public required string UserIp { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<UserRoleInCache> Roles { get; set; } = new List<UserRoleInCache>(); public List<UserRoleInCache> Roles { get; set; } = new List<UserRoleInCache>();
} }
} }

View File

@@ -67,6 +67,11 @@ namespace PARR.API.Controllers.V1
} }
/// <summary>
/// Записать в кэш и получить обратно значение из кэша
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost(ApiRoutes.Test.CreateCache)] [HttpPost(ApiRoutes.Test.CreateCache)]
public async Task<IActionResult> CreateCache([FromBody] CaheRequestTest request) public async Task<IActionResult> CreateCache([FromBody] CaheRequestTest request)
{ {

View File

@@ -63,7 +63,14 @@ namespace PARR.API.Services.Implementations
} }
// пользователь есть, добавляем в КЭШ и возвращаем роли // пользователь есть, добавляем в КЭШ и возвращаем роли
var cacheData = new UserCache { UserIp = ipAddress, Roles = roles }; var cacheData = new UserCache
{
UserIp = ipAddress,
Roles = roles,
Name = user!.Name,
Description = user.Description ?? string.Empty
};
await cacheService.SetCachedDataAsync(GetAllowKey(ipAddress), cacheData, userCacheSettings.UserCacheTtl); await cacheService.SetCachedDataAsync(GetAllowKey(ipAddress), cacheData, userCacheSettings.UserCacheTtl);
return cacheData; return cacheData;