Skip to content

Commit 4395aa9

Browse files
UbuntuUbuntu
authored andcommitted
Merge branch 'release/1.2.3'
2 parents cfdc2de + 372d66c commit 4395aa9

File tree

246 files changed

+2206
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+2206
-858
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Linq.Expressions;
2+
using Streetcode.DAL.Enums;
3+
4+
namespace Streetcode.BLL.Interfaces.EntityAccessManager;
5+
6+
public interface IEntityAccessManager<TEntity>
7+
{
8+
Expression<Func<TEntity, bool>>? GetAccessPredicate(UserRole? userRole);
9+
}

Streetcode/Streetcode.BLL/MediatR/AdditionalContent/Coordinate/GetByStreetcodeId/GetCoordinatesByStreetcodeIdHandler.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using AutoMapper;
1+
using System.Linq.Expressions;
2+
using AutoMapper;
23
using FluentResults;
34
using MediatR;
5+
using Microsoft.EntityFrameworkCore;
46
using Microsoft.Extensions.Localization;
57
using Streetcode.BLL.DTO.AdditionalContent.Coordinates.Types;
68
using Streetcode.BLL.SharedResource;
79
using Streetcode.BLL.Interfaces.Logging;
10+
using Streetcode.BLL.Services.EntityAccessManager;
11+
using Streetcode.DAL.Entities.Streetcode;
812
using Streetcode.DAL.Repositories.Interfaces.Base;
913

1014
namespace Streetcode.BLL.MediatR.AdditionalContent.Coordinate.GetByStreetcodeId;
@@ -16,8 +20,12 @@ public class GetCoordinatesByStreetcodeIdHandler : IRequestHandler<GetCoordinate
1620
private readonly ILoggerService _logger;
1721
private readonly IStringLocalizer<CannotFindSharedResource> _stringLocalizerCannotFind;
1822

19-
public GetCoordinatesByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, ILoggerService logger, IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
20-
{
23+
public GetCoordinatesByStreetcodeIdHandler(
24+
IRepositoryWrapper repositoryWrapper,
25+
IMapper mapper,
26+
ILoggerService logger,
27+
IStringLocalizer<CannotFindSharedResource> stringLocalizerCannotFind)
28+
{
2129
_repositoryWrapper = repositoryWrapper;
2230
_mapper = mapper;
2331
_logger = logger;
@@ -26,6 +34,18 @@ public GetCoordinatesByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper,
2634

2735
public async Task<Result<IEnumerable<StreetcodeCoordinateDTO>>> Handle(GetCoordinatesByStreetcodeIdQuery request, CancellationToken cancellationToken)
2836
{
37+
Expression<Func<StreetcodeContent, bool>>? basePredicate = str => str.Id == request.StreetcodeId;
38+
var predicate = basePredicate.ExtendWithAccessPredicate(new StreetcodeAccessManager(), request.UserRole);
39+
40+
var isStreetcodeExists = await _repositoryWrapper.StreetcodeRepository.FindAll(predicate: predicate).AnyAsync(cancellationToken);
41+
42+
if (!isStreetcodeExists)
43+
{
44+
string errorMsg = _stringLocalizerCannotFind["CannotFindAnyStreetcodeWithCorrespondingId", request.StreetcodeId].Value;
45+
_logger.LogError(request, errorMsg);
46+
return Result.Fail(new Error(errorMsg));
47+
}
48+
2949
var coordinates = await _repositoryWrapper.StreetcodeCoordinateRepository
3050
.GetAllAsync(c => c.StreetcodeId == request.StreetcodeId);
3151

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using FluentResults;
22
using MediatR;
33
using Streetcode.BLL.DTO.AdditionalContent.Coordinates.Types;
4+
using Streetcode.DAL.Enums;
45

56
namespace Streetcode.BLL.MediatR.AdditionalContent.Coordinate.GetByStreetcodeId
67
{
7-
public record GetCoordinatesByStreetcodeIdQuery(int StreetcodeId)
8+
public record GetCoordinatesByStreetcodeIdQuery(int StreetcodeId, UserRole? UserRole)
89
: IRequest<Result<IEnumerable<StreetcodeCoordinateDTO>>>;
910
}

Streetcode/Streetcode.BLL/MediatR/AdditionalContent/Subtitle/GetAll/GetAllSubtitlesHandler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using AutoMapper;
1+
using System.Linq.Expressions;
2+
using AutoMapper;
23
using FluentResults;
34
using MediatR;
45
using Microsoft.Extensions.Localization;
56
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
67
using Streetcode.BLL.Interfaces.Logging;
8+
using Streetcode.BLL.Services.EntityAccessManager;
79
using Streetcode.BLL.SharedResource;
810
using Streetcode.DAL.Repositories.Interfaces.Base;
911

@@ -26,7 +28,10 @@ public GetAllSubtitlesHandler(IRepositoryWrapper repositoryWrapper, IMapper mapp
2628

2729
public async Task<Result<IEnumerable<SubtitleDTO>>> Handle(GetAllSubtitlesQuery request, CancellationToken cancellationToken)
2830
{
29-
var subtitles = await _repositoryWrapper.SubtitleRepository.GetAllAsync();
31+
Expression<Func<DAL.Entities.AdditionalContent.Subtitle, bool>>? basePredicate = null;
32+
var predicate = basePredicate.ExtendWithAccessPredicate(new StreetcodeAccessManager(), request.UserRole, sub => sub.Streetcode);
33+
34+
var subtitles = await _repositoryWrapper.SubtitleRepository.GetAllAsync(predicate: predicate);
3035

3136
if (subtitles is null)
3237
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using FluentResults;
22
using MediatR;
33
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
4+
using Streetcode.DAL.Enums;
45

56
namespace Streetcode.BLL.MediatR.AdditionalContent.Subtitle.GetAll;
67

7-
public record GetAllSubtitlesQuery : IRequest<Result<IEnumerable<SubtitleDTO>>>;
8+
public record GetAllSubtitlesQuery(UserRole? UserRole) : IRequest<Result<IEnumerable<SubtitleDTO>>>;

Streetcode/Streetcode.BLL/MediatR/AdditionalContent/Subtitle/GetById/GetSubtitleByIdHandler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using AutoMapper;
1+
using System.Linq.Expressions;
2+
using AutoMapper;
23
using FluentResults;
34
using MediatR;
45
using Microsoft.Extensions.Localization;
56
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
67
using Streetcode.BLL.Interfaces.Logging;
78
using Streetcode.BLL.MediatR.AdditionalContent.GetById;
9+
using Streetcode.BLL.Services.EntityAccessManager;
810
using Streetcode.BLL.SharedResource;
911
using Streetcode.DAL.Repositories.Interfaces.Base;
1012

@@ -27,7 +29,10 @@ public GetSubtitleByIdHandler(IRepositoryWrapper repositoryWrapper, IMapper mapp
2729

2830
public async Task<Result<SubtitleDTO>> Handle(GetSubtitleByIdQuery request, CancellationToken cancellationToken)
2931
{
30-
var subtitle = await _repositoryWrapper.SubtitleRepository.GetFirstOrDefaultAsync(f => f.Id == request.Id);
32+
Expression<Func<DAL.Entities.AdditionalContent.Subtitle, bool>>? basePredicate = sub => sub.Id == request.Id;
33+
var predicate = basePredicate.ExtendWithAccessPredicate(new StreetcodeAccessManager(), request.UserRole, sub => sub.Streetcode);
34+
35+
var subtitle = await _repositoryWrapper.SubtitleRepository.GetFirstOrDefaultAsync(predicate: predicate);
3136

3237
if (subtitle is null)
3338
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using FluentResults;
22
using MediatR;
33
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
4+
using Streetcode.DAL.Enums;
45

56
namespace Streetcode.BLL.MediatR.AdditionalContent.GetById;
67

7-
public record GetSubtitleByIdQuery(int Id)
8+
public record GetSubtitleByIdQuery(int Id, UserRole? UserRole)
89
: IRequest<Result<SubtitleDTO>>;

Streetcode/Streetcode.BLL/MediatR/AdditionalContent/Subtitle/GetByStreetcodeId/GetSubtitlesByStreetcodeIdHandler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System.Linq.Expressions;
12
using AutoMapper;
23
using FluentResults;
34
using MediatR;
45
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
56
using Streetcode.BLL.Interfaces.Logging;
67
using Streetcode.BLL.MediatR.ResultVariations;
8+
using Streetcode.BLL.Services.EntityAccessManager;
79
using Streetcode.DAL.Repositories.Interfaces.Base;
810

911
namespace Streetcode.BLL.MediatR.AdditionalContent.Subtitle.GetByStreetcodeId
@@ -23,11 +25,15 @@ public GetSubtitlesByStreetcodeIdHandler(IRepositoryWrapper repositoryWrapper, I
2325

2426
public async Task<Result<SubtitleDTO>> Handle(GetSubtitlesByStreetcodeIdQuery request, CancellationToken cancellationToken)
2527
{
28+
Expression<Func<DAL.Entities.AdditionalContent.Subtitle, bool>>? basePredicate = sub => sub.StreetcodeId == request.StreetcodeId;
29+
var predicate = basePredicate.ExtendWithAccessPredicate(new StreetcodeAccessManager(), request.UserRole, sub => sub.Streetcode);
30+
2631
var subtitle = await _repositoryWrapper.SubtitleRepository
27-
.GetFirstOrDefaultAsync(Subtitle => Subtitle.StreetcodeId == request.StreetcodeId);
32+
.GetFirstOrDefaultAsync(predicate: predicate);
2833

2934
NullResult<SubtitleDTO> result = new NullResult<SubtitleDTO>();
3035
result.WithValue(_mapper.Map<SubtitleDTO>(subtitle));
36+
3137
return result;
3238
}
3339
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using FluentResults;
22
using MediatR;
33
using Streetcode.BLL.DTO.AdditionalContent.Subtitles;
4+
using Streetcode.DAL.Enums;
45

56
namespace Streetcode.BLL.MediatR.AdditionalContent.Subtitle.GetByStreetcodeId
67
{
7-
public record GetSubtitlesByStreetcodeIdQuery(int StreetcodeId)
8+
public record GetSubtitlesByStreetcodeIdQuery(int StreetcodeId, UserRole? UserRole)
89
: IRequest<Result<SubtitleDTO>>;
910
}

Streetcode/Streetcode.BLL/MediatR/AdditionalContent/Tag/GetAll/GetAllTagsHandler.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq.Expressions;
12
using AutoMapper;
23
using FluentResults;
34
using MediatR;
@@ -6,10 +7,9 @@
67
using Streetcode.BLL.Interfaces.Logging;
78
using Streetcode.BLL.SharedResource;
89
using Streetcode.DAL.Repositories.Interfaces.Base;
9-
using Microsoft.EntityFrameworkCore;
10-
using Streetcode.DAL.Entities.News;
1110
using Streetcode.DAL.Helpers;
1211
using Streetcode.BLL.DTO.AdditionalContent.Tag;
12+
using Streetcode.BLL.Services.EntityAccessManager;
1313

1414
namespace Streetcode.BLL.MediatR.AdditionalContent.Tag.GetAll;
1515

@@ -30,12 +30,16 @@ public GetAllTagsHandler(IRepositoryWrapper repositoryWrapper, IMapper mapper, I
3030

3131
public Task<Result<GetAllTagsResponseDTO>> Handle(GetAllTagsQuery request, CancellationToken cancellationToken)
3232
{
33+
Expression<Func<DAL.Entities.AdditionalContent.Tag, bool>>? basePredicate = null;
34+
var predicate = basePredicate.ExtendWithAccessPredicate(new StreetcodeAccessManager(), request.UserRole, t => t.Streetcodes);
35+
3336
PaginationResponse<DAL.Entities.AdditionalContent.Tag> paginationResponse = _repositoryWrapper
3437
.TagRepository
3538
.GetAllPaginated(
36-
request.page,
37-
request.pageSize,
38-
descendingSortKeySelector: tag => tag.Title);
39+
request.Page,
40+
request.PageSize,
41+
descendingSortKeySelector: tag => tag.Title,
42+
predicate: predicate);
3943

4044
if (paginationResponse is null)
4145
{

0 commit comments

Comments
 (0)