Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master #994

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d47c768
change appsettings
ValDekh Nov 8, 2023
67b3766
Add local connection string
ValDekh Nov 8, 2023
67171a0
Fix some integrated tests
ValDekh Nov 10, 2023
29ada6a
Fix some tests
ValDekh Nov 14, 2023
6647f17
Add some changes
ValDekh Nov 17, 2023
09b3db8
Fix all Integration tests
ValDekh Nov 18, 2023
510a12a
Return all appSetting.json
ValDekh Nov 18, 2023
b84d738
Merge branch 'master' into fix-integrated-tests-valerii
ValDekh Nov 18, 2023
6a9606a
Delete CleanBlobService and its test. Clean BaseApiController
ValDekh Nov 28, 2023
5bdc0d6
Add appsetting json
ValDekh Dec 5, 2023
520e3dc
Add some cases
ValDekh Dec 6, 2023
1560f3f
Changed datestring max length to 100 instead of 50 (#901)
KateYatsiuk Dec 7, 2023
5cce849
Add some changes
ValDekh Dec 8, 2023
f10a07a
Some addition
ValDekh Dec 10, 2023
1bea96e
Add some cases
ValDekh Dec 11, 2023
5f1b948
Add some logic
ValDekh Dec 11, 2023
1062711
Add some test cases
ValDekh Dec 12, 2023
ba54842
Add Update StreetCode Integration Tests
ValDekh Dec 13, 2023
26b34e6
Merge with Develop
ValDekh Dec 14, 2023
ac8c2d9
Correct AppSettings
ValDekh Dec 14, 2023
36e1f75
Add update folder
ValDekh Dec 15, 2023
2b1b477
Change naming
ValDekh Dec 18, 2023
4d8ed34
Correct some errors
ValDekh Dec 18, 2023
e0f822f
Some edition
ValDekh Dec 18, 2023
008e979
Merge branch 'fix-integrated-tests-valerii' of https://github.com/ita…
ValDekh Dec 18, 2023
feb7f9e
Merge with update
ValDekh Dec 18, 2023
b0db67f
Add some corrections
ValDekh Dec 18, 2023
b30e441
merge master into develop (#974)
Oleh-Kril Dec 20, 2023
52ad4ec
Adding unit tests (#884)
mykola-krai Dec 29, 2023
62f6f3d
fix swagger for stage (#993)
Adeodonne Dec 30, 2023
2b1a678
Merge pull request #863 from ita-social-projects/fix-integrated-tests…
BohdanBybliv Jan 7, 2024
793d4c0
Revert "Integration tests for Streetcode Update Controller"
BohdanBybliv Jan 7, 2024
65ed037
Merge pull request #1019 from ita-social-projects/revert-955-integrat…
BohdanBybliv Jan 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public async Task<Result<SubtitleDTO>> Handle(GetSubtitleByIdQuery request, Canc
{
string errorMsg = _stringLocalizerCannotFind["CannotFindSubtitleWithCorrespondingId", request.Id].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
var returner = Result.Fail(new Error(errorMsg));
return returner;
}

return Result.Ok(_mapper.Map<SubtitleDTO>(subtitle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<Result<IEnumerable<StreetcodeTagDTO>>> Handle(GetTagByStreetco
t => t.StreetcodeId == request.StreetcodeId,
include: q => q.Include(t => t.Tag));

if (tagIndexed is null)
if (tagIndexed is null || request.StreetcodeId < 1)
{
string errorMsg = _stringLocalizerCannotFind?["CannotFindAnyTagByTheStreetcodeId", request.StreetcodeId].Value;
_logger.LogError(request, errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<Result<IEnumerable<ArtDTO>>> Handle(GetArtsByStreetcodeIdQuery
include: scl => scl
.Include(sc => sc.Image) !);

if (arts is null)
if (arts is null || request.StreetcodeId < 1)
{
string errorMsg = _stringLocalizerCannotFind["CannotFindAnyArtWithCorrespondingStreetcodeId", request.StreetcodeId].Value;
_logger.LogError(request, errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<Result<IEnumerable<ImageDTO>>> Handle(GetImageByStreetcodeIdQu
f => f.Streetcodes.Any(s => s.Id == request.StreetcodeId),
include: q => q.Include(img => img.ImageDetails))).OrderBy(img => img.ImageDetails?.Alt);

if (images is null || images.Count() == 0)
if (images is null || request.StreetcodeId < 1)
{
string errorMsg = _stringLocalizerCannotFind["CannotFindAnImageWithTheCorrespondingStreetcodeId", request.StreetcodeId].Value;
_logger.LogError(request, errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<Result<IEnumerable<StreetcodeArtDTO>>> Handle(GetStreetcodeArt
.Include(a => a.Art)
.Include(i => i.Art.Image) !);

if (art is null)
if (art is null || request.StreetcodeId < 1)
{
string errorMsg = _stringLocalizerCannotFind["CannotFindAnyArtWithCorrespondingStreetcodeId", request.StreetcodeId].Value;
_logger.LogError(request, errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public string SaveFileInStorage(string base64, string name, string extension)

public void SaveFileInStorageBase64(string base64, string name, string extension)
{
byte[] imageBytes = Convert.FromBase64String(base64);
byte[] imageBytes = Convert.FromBase64String(base64.Trim());
Directory.CreateDirectory(_blobPath);
EncryptFile(imageBytes, extension, name);
}
Expand All @@ -87,26 +87,6 @@ public string UpdateFileInStorage(
return hashBlobStorageName;
}

public async Task CleanBlobStorage()
{
var base64Files = GetAllBlobNames();

var existingImagesInDatabase = await _repositoryWrapper.ImageRepository.GetAllAsync();
var existingAudiosInDatabase = await _repositoryWrapper.AudioRepository.GetAllAsync();

List<string> existingMedia = new ();
existingMedia.AddRange(existingImagesInDatabase.Select(img => img.BlobName));
existingMedia.AddRange(existingAudiosInDatabase.Select(img => img.BlobName));

var filesToRemove = base64Files.Except(existingMedia).ToList();

foreach (var file in filesToRemove)
{
Console.WriteLine($"Deleting {file}...");
DeleteFileInStorage(file);
}
}

private IEnumerable<string> GetAllBlobNames()
{
var paths = Directory.EnumerateFiles(_blobPath);
Expand Down
69 changes: 37 additions & 32 deletions Streetcode/Streetcode.BLL/Services/CacheService/CacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Streetcode.BLL.Interfaces.Cache;
using Streetcode.BLL.Interfaces.Logging;

Expand All @@ -14,54 +15,58 @@ namespace Streetcode.BLL.Services.CacheService
public class CacheService : ICacheService
{
private readonly IMemoryCache _cache;
private readonly ILoggerService _logger;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly ConcurrentDictionary<object, SemaphoreSlim> _locks = new ConcurrentDictionary<object, SemaphoreSlim>();

public CacheService(IMemoryCache cache, ILoggerService logger)
public CacheService(IMemoryCache cache, IServiceScopeFactory serviceScopeFactory )
{
_cache = cache;
_logger = logger;
_serviceScopeFactory = serviceScopeFactory;
}

public async Task<T> GetOrSetAsync<T>(string key, Func<Task<T>> getItemCallback, TimeSpan cacheDuration)
{
_logger.LogInformation(key + "GetOrSetAsync function start!");
if (_cache.TryGetValue(key, out T cachedItem))
using (var scope = _serviceScopeFactory.CreateAsyncScope())
{
_logger.LogInformation(key + "TryGetValue function true");
return cachedItem;
}

_logger.LogInformation(key + "TryGetValue function false");
SemaphoreSlim mylock = _locks.GetOrAdd(key, k => new SemaphoreSlim(1, 1));

await mylock.WaitAsync();

try
{
if (_cache.TryGetValue(key, out cachedItem))
var logger = scope.ServiceProvider.GetRequiredService<ILoggerService>();
logger.LogInformation(key + "GetOrSetAsync function start!");
if (_cache.TryGetValue(key, out T cachedItem))
{
_logger.LogInformation(key + "TryGetValue function true");
logger.LogInformation(key + "TryGetValue function true");
return cachedItem;
}

_logger.LogInformation(key + "TryGetValue function false");
T item = await getItemCallback();
logger.LogInformation(key + "TryGetValue function false");
SemaphoreSlim mylock = _locks.GetOrAdd(key, k => new SemaphoreSlim(1, 1));

await mylock.WaitAsync();

var cacheEntryOptions = new MemoryCacheEntryOptions
try
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30),
SlidingExpiration = cacheDuration,
Priority = CacheItemPriority.Normal,
};
if (_cache.TryGetValue(key, out cachedItem))
{
logger.LogInformation(key + "TryGetValue function true");
return cachedItem;
}

_cache.Set(key, item, cacheEntryOptions);
_logger.LogInformation(key + "Set function true");
return item;
}
finally
{
mylock.Release();
logger.LogInformation(key + "TryGetValue function false");
T item = await getItemCallback();

var cacheEntryOptions = new MemoryCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30),
SlidingExpiration = cacheDuration,
Priority = CacheItemPriority.Normal,
};

_cache.Set(key, item, cacheEntryOptions);
logger.LogInformation(key + "Set function true");
return item;
}
finally
{
mylock.Release();
}
}
}

Expand Down
39 changes: 0 additions & 39 deletions Streetcode/Streetcode.BLL/Util/DateToStringConverter.cs

This file was deleted.

23 changes: 0 additions & 23 deletions Streetcode/Streetcode.BLL/Util/IdComparer.cs

This file was deleted.

10 changes: 5 additions & 5 deletions Streetcode/Streetcode.DAL/Streetcode.DAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<ItemGroup>
<PackageReference Include="EfCore.SchemaCompare" Version="6.0.0" />
<PackageReference Include="MailKit" Version="3.6.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.11">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.11">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
12 changes: 0 additions & 12 deletions Streetcode/Streetcode.WebApi/Attributes/AuthorizeRoles.cs

This file was deleted.

22 changes: 4 additions & 18 deletions Streetcode/Streetcode.WebApi/Controllers/BaseApiController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Resources;
using FluentResults;
using FluentResults;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.MediatR.ResultVariations;

namespace Streetcode.WebApi.Controllers;
Expand All @@ -11,12 +9,7 @@ namespace Streetcode.WebApi.Controllers;
[Route("api/[controller]/[action]")]
public class BaseApiController : ControllerBase
{
private readonly IStringLocalizer _stringLocalizer;
private IMediator? _mediator;
public BaseApiController(IStringLocalizer<BaseApiController> stringLocalizer)
{
_stringLocalizer = stringLocalizer;
}

public BaseApiController()
{
Expand All @@ -28,23 +21,16 @@ protected ActionResult HandleResult<T>(Result<T> result)
{
if (result.IsSuccess)
{
if(result is NullResult<T>)
if (result is NullResult<T>)
{
return Ok(result.Value);
}

return (result.Value is null) ?
NotFound(_stringLocalizer?["NotFound"].Value) : Ok(result.Value);
}

foreach (var item in result.Reasons)
{
if (item.Message.Contains(_stringLocalizer?["NotFound"].Value))
{
return Ok();
}
NotFound("Not Found") : Ok(result.Value);
}

return BadRequest(result.Reasons);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Streetcode.BLL.MediatR.Media.Audio.Update;
using Streetcode.BLL.MediatR.Media.Image.GetByStreetcodeId;
using Streetcode.DAL.Enums;
using Streetcode.WebApi.Attributes;

namespace Streetcode.WebApi.Controllers.Media;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<IActionResult> GetById([FromRoute] int id)
}

[HttpGet("{streetcodeId:int}")]
public async Task<IActionResult> GetAllByStreetcodeId([FromRoute] int streetcodeId)
public async Task<IActionResult> GetArtsByStreetcodeId([FromRoute] int streetcodeId)
{
return HandleResult(await Mediator.Send(new GetArtsByStreetcodeIdQuery(streetcodeId)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Streetcode.BLL.MediatR.Media.Image.Create;
using Streetcode.BLL.MediatR.Media.Image.Delete;
using Streetcode.BLL.MediatR.Media.Image.Update;
using Streetcode.WebApi.Attributes;
using Streetcode.DAL.Enums;
using Microsoft.Net.Http.Headers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Streetcode.BLL.MediatR.Partners.GetByStreetcodeIdToUpdate;
using Streetcode.DAL.Entities.Partners;
using Streetcode.DAL.Enums;
using Streetcode.WebApi.Attributes;

namespace Streetcode.WebApi.Controllers.Partners;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Streetcode.BLL.MediatR.Sources.SourceLink.Update;
using Streetcode.BLL.MediatR.Sources.SourceLink.Delete;
using Streetcode.DAL.Enums;
using Streetcode.WebApi.Attributes;
using Streetcode.BLL.MediatR.Sources.SourceLinkCategory.GetAll;
using Streetcode.BLL.MediatR.Sources.SourceLinkCategory.GetCategoryContentByStreetcodeId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Streetcode.BLL.MediatR.Streetcode.Fact.GetByStreetcodeId;
using Streetcode.BLL.MediatR.Streetcode.Fact.Update;
using Streetcode.DAL.Enums;
using Streetcode.WebApi.Attributes;

namespace Streetcode.WebApi.Controllers.Streetcode.TextContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Streetcode.BLL.MediatR.Team.GetByRoleId;
using Streetcode.BLL.MediatR.Team.Update;
using Streetcode.DAL.Enums;
using Streetcode.WebApi.Attributes;

namespace Streetcode.WebApi.Controllers.Team
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Streetcode.BLL.MediatR.Users.Login;
using Streetcode.BLL.MediatR.Users.RefreshToken;
using Streetcode.DAL.Enums;
using Streetcode.WebApi.Attributes;

namespace Streetcode.WebApi.Controllers.Users
{
Expand Down
Loading
Loading