Skip to content

Commit

Permalink
Merge pull request #638 from ita-social-projects/revert-637-revert-63…
Browse files Browse the repository at this point in the history
…1-develop

Revert "Revert "Develop""
  • Loading branch information
MementoMorj authored Aug 22, 2023
2 parents 01def6b + f8b70ab commit a004670
Show file tree
Hide file tree
Showing 269 changed files with 9,599 additions and 517 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,5 @@ healthchecksdb

# BlobStorage
BlobStorage/
BlobStorageTestFolder/
BlobStorageTestFolder/
/Streetcode/StreetCode.Client
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.SharedResource;
using Streetcode.DAL.Repositories.Interfaces.Base;

namespace Streetcode.BLL.MediatR.AdditionalContent.Coordinate.Create;
Expand All @@ -9,11 +11,19 @@ public class CreateCoordinateHandler : IRequestHandler<CreateCoordinateCommand,
{
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly IStringLocalizer<CannotConvertNullSharedResource> _stringLocalizer;
private readonly IStringLocalizer<FailedToCreateSharedResource> _stringLocalizerFaild;

public CreateCoordinateHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper)
public CreateCoordinateHandler(
IRepositoryWrapper repositoryWrapper,
IMapper mapper,
IStringLocalizer<CannotConvertNullSharedResource> stringLocalizer,
IStringLocalizer<FailedToCreateSharedResource> stringLocalizerFaild)
{
_stringLocalizer = stringLocalizer;
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_stringLocalizerFaild = stringLocalizerFaild;
}

public async Task<Result<Unit>> Handle(CreateCoordinateCommand request, CancellationToken cancellationToken)
Expand All @@ -22,12 +32,12 @@ public async Task<Result<Unit>> Handle(CreateCoordinateCommand request, Cancella

if (streetcodeCoordinate is null)
{
return Result.Fail(new Error("Cannot convert null to streetcodeCoordinate"));
return Result.Fail(new Error(_stringLocalizer?["CannotConvertNullToStreetcodeCoordinate"].Value));
}

_repositoryWrapper.StreetcodeCoordinateRepository.Create(streetcodeCoordinate);

var resultIsSuccess = await _repositoryWrapper.SaveChangesAsync() > 0;
return resultIsSuccess ? Result.Ok(Unit.Value) : Result.Fail(new Error("Failed to create a streetcodeCoordinate"));
return resultIsSuccess ? Result.Ok(Unit.Value) : Result.Fail(new Error(_stringLocalizerFaild?["FailedToCreateStreetcodeCoordinate"].Value));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
using FluentResults;
using System.Xml.Linq;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.SharedResource;
using Streetcode.DAL.Repositories.Interfaces.Base;

namespace Streetcode.BLL.MediatR.AdditionalContent.Coordinate.Delete;

public class DeleteCoordinateHandler : IRequestHandler<DeleteCoordinateCommand, Result<Unit>>
{
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;
private readonly IStringLocalizer<FailedToDeleteSharedResource> _stringLocalizerFailedToDelete;

public DeleteCoordinateHandler(IRepositoryWrapper repositoryWrapper)
public DeleteCoordinateHandler(
IRepositoryWrapper repositoryWrapper,
IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind,
IStringLocalizer<FailedToDeleteSharedResource> stringLocalizerFailedToDelete)
{
_repositoryWrapper = repositoryWrapper;
_stringLocalizerCannotFind = stringLocalizerCannotFind;
_stringLocalizerFailedToDelete = stringLocalizerFailedToDelete;
}

public async Task<Result<Unit>> Handle(DeleteCoordinateCommand request, CancellationToken cancellationToken)
Expand All @@ -19,12 +29,12 @@ public async Task<Result<Unit>> Handle(DeleteCoordinateCommand request, Cancella

if (streetcodeCoordinate is null)
{
return Result.Fail(new Error($"Cannot find a coordinate with corresponding categoryId: {request.Id}"));
return Result.Fail(new Error(_stringLocalizerCannotFind["CannotFindCoordinateWithCorrespondingCategoryId", request.Id].Value));
}

_repositoryWrapper.StreetcodeCoordinateRepository.Delete(streetcodeCoordinate);

var resultIsSuccess = await _repositoryWrapper.SaveChangesAsync() > 0;
return resultIsSuccess ? Result.Ok(Unit.Value) : Result.Fail(new Error("Failed to delete a coordinate"));
return resultIsSuccess ? Result.Ok(Unit.Value) : Result.Fail(new Error(_stringLocalizerFailedToDelete["FailedToDeleteStreetcodeCoordinate"].Value));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent.Coordinates.Types;
using Streetcode.BLL.SharedResource;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.DAL.Repositories.Interfaces.Base;

Expand All @@ -12,28 +14,30 @@ public class GetCoordinatesByStreetcodeIdHandler : IRequestHandler<GetCoordinate
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ILoggerService _logger;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;

public GetCoordinatesByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger)
{
public GetCoordinatesByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_logger = logger;
_stringLocalizerCannotFind = stringLocalizerCannotFind;
}

public async Task<Result<IEnumerable<StreetcodeCoordinateDTO>>> Handle(GetCoordinatesByStreetcodeIdQuery request, CancellationToken cancellationToken)
{
if ((await _repositoryWrapper.StreetcodeRepository.GetFirstOrDefaultAsync(s => s.Id == request.StreetcodeId)) is null)
{
return Result.Fail(
new Error($"Cannot find a coordinates by a streetcode id: {request.StreetcodeId}, because such streetcode doesn`t exist"));
new Error(_stringLocalizerCannotFind["CannotFindCoordinatesByStreetcodeId", request.StreetcodeId].Value));
}

var coordinates = await _repositoryWrapper.StreetcodeCoordinateRepository
.GetAllAsync(c => c.StreetcodeId == request.StreetcodeId);

if (coordinates is null)
{
string errorMsg = $"Cannot find a coordinates by a streetcode id: {request.StreetcodeId}";
string errorMsg = _stringLocalizerCannotFind["CannotFindCoordinatesByStreetcodeId", request.StreetcodeId].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.SharedResource;
using Streetcode.DAL.Repositories.Interfaces.Base;

namespace Streetcode.BLL.MediatR.AdditionalContent.Coordinate.Update;
Expand All @@ -9,11 +11,19 @@ public class UpdateCoordinateHandler : IRequestHandler<UpdateCoordinateCommand,
{
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly IStringLocalizer<CannotConvertNullSharedResource> _stringLocalizerCannotConvert;
private readonly IStringLocalizer<FailedToCreateSharedResource> _stringLocalizerFailedToCreate;

public UpdateCoordinateHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper)
public UpdateCoordinateHandler(
IRepositoryWrapper repositoryWrapper,
IMapper mapper,
IStringLocalizer<CannotConvertNullSharedResource> stringLocalizerCannotConvert,
IStringLocalizer<FailedToCreateSharedResource> stringLocalizerFailedToCreate)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_stringLocalizerCannotConvert = stringLocalizerCannotConvert;
_stringLocalizerFailedToCreate = stringLocalizerFailedToCreate;
}

public async Task<Result<Unit>> Handle(UpdateCoordinateCommand request, CancellationToken cancellationToken)
Expand All @@ -22,12 +32,12 @@ public async Task<Result<Unit>> Handle(UpdateCoordinateCommand request, Cancella

if (streetcodeCoordinate is null)
{
return Result.Fail(new Error("Cannot convert null to streetcodeCoordinate"));
return Result.Fail(new Error(_stringLocalizerCannotConvert?["CannotConvertNullToStreetcodeCoordinate"].Value));
}

_repositoryWrapper.StreetcodeCoordinateRepository.Update(streetcodeCoordinate);

var resultIsSuccess = await _repositoryWrapper.SaveChangesAsync() > 0;
return resultIsSuccess ? Result.Ok(Unit.Value) : Result.Fail(new Error("Failed to update a streetcodeCoordinate"));
return resultIsSuccess ? Result.Ok(Unit.Value) : Result.Fail(new Error(_stringLocalizerFailedToCreate?["FailedToCreateStreetcodeCoordinate"].Value));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.BLL.SharedResource;
using Streetcode.DAL.Repositories.Interfaces.Base;

namespace Streetcode.BLL.MediatR.AdditionalContent.Subtitle.GetAll;
Expand All @@ -12,12 +14,14 @@ public class GetAllSubtitlesHandler : IRequestHandler<GetAllSubtitlesQuery, Resu
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ILoggerService _logger;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;

public GetAllSubtitlesHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger)
public GetAllSubtitlesHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_logger = logger;
_stringLocalizerCannotFind = stringLocalizerCannotFind;
}

public async Task<Result<IEnumerable<SubtitleDTO>>> Handle(GetAllSubtitlesQuery request, CancellationToken cancellationToken)
Expand All @@ -26,7 +30,7 @@ public async Task<Result<IEnumerable<SubtitleDTO>>> Handle(GetAllSubtitlesQuery

if (subtitles is null)
{
const string errorMsg = $"Cannot find any subtitles";
string errorMsg = _stringLocalizerCannotFind?["CannotFindAnySubtitles"].Value;

_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.BLL.MediatR.AdditionalContent.GetById;
using Streetcode.BLL.SharedResource;
using Streetcode.DAL.Repositories.Interfaces.Base;

namespace Streetcode.BLL.MediatR.AdditionalContent.Subtitle.GetById;
Expand All @@ -13,12 +15,14 @@ public class GetSubtitleByIdHandler : IRequestHandler<GetSubtitleByIdQuery, Resu
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ILoggerService _logger;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;

public GetSubtitleByIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger)
public GetSubtitleByIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_logger = logger;
_stringLocalizerCannotFind = stringLocalizerCannotFind;
}

public async Task<Result<SubtitleDTO>> Handle(GetSubtitleByIdQuery request, CancellationToken cancellationToken)
Expand All @@ -27,7 +31,7 @@ public async Task<Result<SubtitleDTO>> Handle(GetSubtitleByIdQuery request, Canc

if (subtitle is null)
{
string errorMsg = $"Cannot find a subtitle with corresponding id: {request.Id}";
string errorMsg = _stringLocalizerCannotFind["CannotFindSubtitleWithCorrespondingId", request.Id].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.BLL.MediatR.ResultVariations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent;
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
using Streetcode.BLL.DTO.AdditionalContent.Tag;
using Streetcode.BLL.SharedResource;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.DAL.Repositories.Interfaces.Base;

Expand All @@ -14,12 +16,14 @@ public class GetAllTagsHandler : IRequestHandler<GetAllTagsQuery, Result<IEnumer
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ILoggerService _logger;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;

public GetAllTagsHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger)
public GetAllTagsHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> CannotFindSharedResource)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_logger = logger;
_stringLocalizerCannotFind = CannotFindSharedResource;
}

public async Task<Result<IEnumerable<TagDTO>>> Handle(GetAllTagsQuery request, CancellationToken cancellationToken)
Expand All @@ -28,7 +32,7 @@ public async Task<Result<IEnumerable<TagDTO>>> Handle(GetAllTagsQuery request, C

if (tags is null)
{
const string errorMsg = $"Cannot find any tags";
string errorMsg = _stringLocalizerCannotFind?["CannotFindAnyTags"].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using AutoMapper;
using FluentResults;
using MediatR;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent;
using Streetcode.BLL.MediatR.AdditionalContent.Tag.GetAll;
using Streetcode.BLL.SharedResource;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.DAL.Repositories.Interfaces.Base;

Expand All @@ -12,12 +15,14 @@ public class GetTagByIdHandler : IRequestHandler<GetTagByIdQuery, Result<TagDTO>
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ILoggerService _logger;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;

public GetTagByIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger)
public GetTagByIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_logger = logger;
_stringLocalizerCannotFind = stringLocalizerCannotFind;
}

public async Task<Result<TagDTO>> Handle(GetTagByIdQuery request, CancellationToken cancellationToken)
Expand All @@ -26,7 +31,7 @@ public async Task<Result<TagDTO>> Handle(GetTagByIdQuery request, CancellationTo

if (tag is null)
{
string errorMsg = $"Cannot find a Tag with corresponding id: {request.Id}";
string errorMsg = _stringLocalizerCannotFind?["CannotFindTagWithCorrespondingId", request.Id].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
using Microsoft.Extensions.Localization;
using Streetcode.BLL.DTO.AdditionalContent.Tag;
using Streetcode.BLL.Interfaces.Logging;
using Streetcode.DAL.Entities.Streetcode;
using Streetcode.BLL.SharedResource;
using Streetcode.DAL.Repositories.Interfaces.Base;

namespace Streetcode.BLL.MediatR.AdditionalContent.Tag.GetByStreetcodeId;
Expand All @@ -15,31 +17,26 @@ public class GetTagByStreetcodeIdHandler : IRequestHandler<GetTagByStreetcodeIdQ
private readonly IMapper _mapper;
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ILoggerService _logger;
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;

public GetTagByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger)
public GetTagByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
{
_repositoryWrapper = repositoryWrapper;
_mapper = mapper;
_logger = logger;
_stringLocalizerCannotFind = stringLocalizerCannotFind;
}

public async Task<Result<IEnumerable<StreetcodeTagDTO>>> Handle(GetTagByStreetcodeIdQuery request, CancellationToken cancellationToken)
{
/*
StreetcodeContent streetcode = await _repositoryWrapper.StreetcodeRepository.GetFirstOrDefaultAsync(s => s.Id == request.StreetcodeId);
if(streetcode is null)
{
return Result.Fail(new Error($"Streetcode with id: {request.StreetcodeId} doesn`t exist"));
}
*/
var tagIndexed = await _repositoryWrapper.StreetcodeTagIndexRepository
.GetAllAsync(
t => t.StreetcodeId == request.StreetcodeId,
include: q => q.Include(t => t.Tag));

if (tagIndexed is null)
{
string errorMsg = $"Cannot find any tag by the streetcode id: {request.StreetcodeId}";
string errorMsg = _stringLocalizerCannotFind?["CannotFindAnyTagByTheStreetcodeId", request.StreetcodeId].Value;
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
}
Expand Down
Loading

0 comments on commit a004670

Please sign in to comment.