Skip to content

Commit adce5b5

Browse files
authored
Merge pull request #39 from DurkaTechnologies/develop
Release 1.0 built successfully
2 parents 69952c2 + 9c3a332 commit adce5b5

90 files changed

Lines changed: 17342 additions & 785 deletions

File tree

Some content is hidden

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

Application/Features/Communities/Commands/CreateCommunityCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public partial class CreateCommunityCommand : IRequest<Result<int>>
1313
public string Name { get; set; }
1414

1515
public int? DistrictId { get; set; }
16+
public string ApplicationUserId{ get; set; }
1617

1718
public class CreateCommunityCommandHandler : IRequestHandler<CreateCommunityCommand, Result<int>>
1819
{

Application/Features/Communities/Commands/UpdateCommunityCommand.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class UpdateCommunityCommand : IRequest<Result<int>>
1616

1717
public int? DistrictId { get; set; }
1818

19+
public string ApplicationUserId { get; set; }
20+
1921
public class UpdateCommunityCommandHandler : IRequestHandler<UpdateCommunityCommand, Result<int>>
2022
{
2123
private readonly IUnitOfWork unitOfWork;
@@ -39,13 +41,26 @@ public async Task<Result<int>> Handle(UpdateCommunityCommand command, Cancellati
3941
}
4042
else
4143
{
42-
community.Name = command.Name ?? community.Name;
44+
community.Name = command.Name.NullIfEmpty() ?? community.Name;
4345
community.DistrictId = command.DistrictId ?? community.DistrictId;
46+
community.ApplicationUserId = command.ApplicationUserId;
4447
await communityRepository.UpdateAsync(mapper.Map<Community>(command));
4548
await unitOfWork.Commit(cancellationToken);
4649
return Result<int>.Success(command.Id);
4750
}
4851
}
4952
}
5053
}
54+
55+
public static class StringExtensions
56+
{
57+
public static string NullIfEmpty(this string s)
58+
{
59+
return string.IsNullOrEmpty(s) ? null : s;
60+
}
61+
public static string NullIfWhiteSpace(this string s)
62+
{
63+
return string.IsNullOrWhiteSpace(s) ? null : s;
64+
}
65+
}
5166
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Application.Common.Models;
2+
using Application.Features.Communities.Queries.GetById;
3+
using Application.Interfaces.Repositories;
4+
using AutoMapper;
5+
using MediatR;
6+
using System.Collections.Generic;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Application.Features.Communities.Queries.GetAllCached
11+
{
12+
public class GeUserCommunitiesQuery : IRequest<Result<List<GetCommunityByIdResponse>>>
13+
{
14+
public string UserId { get; set; }
15+
16+
public class GeUserCommunitiesQueryHandler : IRequestHandler<GeUserCommunitiesQuery, Result<List<GetCommunityByIdResponse>>>
17+
{
18+
private readonly ICommunityRepository communityRepository;
19+
private readonly IMapper mapper;
20+
21+
public GeUserCommunitiesQueryHandler(ICommunityRepository communityRepository, IMapper mapper)
22+
{
23+
this.communityRepository = communityRepository;
24+
this.mapper = mapper;
25+
}
26+
27+
public async Task<Result<List<GetCommunityByIdResponse>>> Handle(GeUserCommunitiesQuery request, CancellationToken cancellationToken)
28+
{
29+
var communities = await communityRepository.GetListByUserIdAsync(request.UserId);
30+
var mappedCommunities = mapper.Map<List<GetCommunityByIdResponse>>(communities);
31+
return Result<List<GetCommunityByIdResponse>>.Success(mappedCommunities);
32+
}
33+
}
34+
}
35+
}

Application/Features/Communities/Queries/GetAllCached/GetAllCommunitiesCachedQuery.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public GetAllCommunitiesCachedQueryHandler(ICommunityCacheRepository communityCa
2929
public async Task<Result<List<GetAllCommunitiesCachedResponse>>> Handle(GetAllCommunitiesCachedQuery request, CancellationToken cancellationToken)
3030
{
3131
var communities = await communityCache.GetCachedListAsync();
32-
var mappedCommunities = mapper.Map<List<GetAllCommunitiesCachedResponse>>(communities);
33-
return Result<List<GetAllCommunitiesCachedResponse>>.Success(mappedCommunities);
32+
33+
// var mappedCommunities = mapper.Map<List<GetAllCommunitiesCachedResponse>>(communities);
34+
// mappedCommunities = await communityCache.FillUserName(mappedCommunities);
35+
return Result<List<GetAllCommunitiesCachedResponse>>.Success(communities);
3436
}
3537
}
3638
}

Application/Features/Communities/Queries/GetAllCached/GetAllCommunitiesCachedResponse.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public class GetAllCommunitiesCachedResponse
66

77
public string Name { get; set; }
88

9-
public GetAllDistrictsCachedResponse District { get; set; }
9+
public string ApplicationUserId { get; set; }
10+
11+
public string ApplicationUserName { get; set; }
12+
13+
public GetAllDistrictsCachedResponse District { get; set; }
1014
}
1115
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Application.Common.Models;
2+
using Application.Features.Communities.Queries.GetById;
3+
using Application.Interfaces.Repositories;
4+
using AutoMapper;
5+
using MediatR;
6+
using System.Collections.Generic;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Application.Features.Communities.Queries.GetAllCached
11+
{
12+
public class GetFreeCommunitiesQuery : IRequest<Result<List<GetCommunityByIdResponse>>>
13+
{
14+
public GetFreeCommunitiesQuery()
15+
{
16+
}
17+
}
18+
19+
public class GetFreeCommunitiesQueryHandler : IRequestHandler<GetFreeCommunitiesQuery, Result<List<GetCommunityByIdResponse>>>
20+
{
21+
private readonly ICommunityRepository communityRepository;
22+
private readonly IMapper mapper;
23+
24+
public GetFreeCommunitiesQueryHandler(ICommunityRepository communityRepository, IMapper mapper)
25+
{
26+
this.communityRepository = communityRepository;
27+
this.mapper = mapper;
28+
}
29+
30+
public async Task<Result<List<GetCommunityByIdResponse>>> Handle(GetFreeCommunitiesQuery request, CancellationToken cancellationToken)
31+
{
32+
var communities = await communityRepository.GetFreeListAsync();
33+
var mappedCommunities = mapper.Map<List<GetCommunityByIdResponse>>(communities);
34+
return Result<List<GetCommunityByIdResponse>>.Success(mappedCommunities);
35+
}
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Application.Common.Models;
2+
using Application.Interfaces.Repositories;
3+
using AutoMapper;
4+
using MediatR;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Application.Features.Communities.Queries.GetById
9+
{
10+
public class GetCommunityByIdNotCacheQuery : IRequest<Result<GetCommunityByIdResponse>>
11+
{
12+
public int Id { get; set; }
13+
14+
public class GeCommunityByIdQueryHandler : IRequestHandler<GetCommunityByIdNotCacheQuery, Result<GetCommunityByIdResponse>>
15+
{
16+
private readonly ICommunityRepository repository;
17+
private readonly IMapper mapper;
18+
19+
public GeCommunityByIdQueryHandler(ICommunityRepository repository, IMapper mapper)
20+
{
21+
this.repository = repository;
22+
this.mapper = mapper;
23+
}
24+
25+
public async Task<Result<GetCommunityByIdResponse>> Handle(GetCommunityByIdNotCacheQuery query, CancellationToken cancellationToken)
26+
{
27+
var community = await repository.GetByIdAsync(query.Id);
28+
var mappedCommunity = mapper.Map<GetCommunityByIdResponse>(community);
29+
return Result<GetCommunityByIdResponse>.Success(mappedCommunity);
30+
}
31+
}
32+
}
33+
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Application.Features.Communities.Queries.GetById
1+
using Application.Features.Communities.Queries.GetAllCached;
2+
3+
namespace Application.Features.Communities.Queries.GetById
24
{
35
public class GetCommunityByIdResponse
46
{
@@ -7,5 +9,9 @@ public class GetCommunityByIdResponse
79
public string Name { get; set; }
810

911
public int? DistrictId { get; set; }
12+
13+
public GetAllDistrictsCachedResponse District { get; set; }
14+
15+
public string ApplicationUserId { get; set; }
1016
}
1117
}

Application/Features/Districts/Commands/DeleteDistrictCommand.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ public DeleteDistrictCommandHandler(IDistrictRepository districtRepository, IUni
2323

2424
public async Task<Result<int>> Handle(DeleteDistrictCommand command, CancellationToken cancellationToken)
2525
{
26-
var district = await districtRepository.GetByIdAsync(command.Id);
27-
await districtRepository.DeleteAsync(district);
28-
await unitOfWork.Commit(cancellationToken);
29-
return Result<int>.Success(district.Id);
26+
var district = await districtRepository.GetIncludeByIdAsync(command.Id);
27+
if (district.Communities.Count == 0)
28+
{
29+
await districtRepository.DeleteAsync(district);
30+
await unitOfWork.Commit(cancellationToken);
31+
return Result<int>.Success(district.Id);
32+
}
33+
return Result<int>.Failure();
34+
3035
}
3136
}
3237
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Application.Common.Models;
2+
using Application.Features.Communities.Queries.GetAllCached;
3+
using Application.Features.Logs.Queries;
4+
using Application.Interfaces.Repositories;
5+
using AutoMapper;
6+
using MediatR;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Text;
11+
using System.Threading;
12+
using System.Threading.Tasks;
13+
14+
namespace Application.Features.Districts.Queries
15+
{
16+
public class GetAllDistrictsQuery : IRequest<Result<List<GetAllDistrictsCachedResponse>>>
17+
{
18+
public GetAllDistrictsQuery()
19+
{
20+
21+
}
22+
}
23+
24+
public class GetAllDistrictsQueryHandler : IRequestHandler<GetAllDistrictsQuery, Result<List<GetAllDistrictsCachedResponse>>>
25+
{
26+
private readonly IDistrictRepository repository;
27+
private readonly IMapper mapper;
28+
29+
public GetAllDistrictsQueryHandler(IDistrictRepository repository, IMapper mapper)
30+
{
31+
this.repository = repository;
32+
this.mapper = mapper;
33+
}
34+
35+
public async Task<Result<List<GetAllDistrictsCachedResponse>>> Handle(GetAllDistrictsQuery request, CancellationToken cancellationToken)
36+
{
37+
var districts = mapper.Map<List<GetAllDistrictsCachedResponse>>(await repository.GetListAsync());
38+
return Result<List<GetAllDistrictsCachedResponse>>.Success(districts);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)