Skip to content

Commit

Permalink
Merge pull request #764 from neozhu/rename_picklist
Browse files Browse the repository at this point in the history
Rename picklistset
  • Loading branch information
neozhu authored Sep 29, 2024
2 parents c898967 + 68d05f8 commit 8839d3c
Show file tree
Hide file tree
Showing 93 changed files with 5,683 additions and 2,730 deletions.
2 changes: 1 addition & 1 deletion src/Application/Common/Interfaces/IApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IApplicationDbContext
DbSet<Logger> Loggers { get; set; }
DbSet<AuditTrail> AuditTrails { get; set; }
DbSet<Document> Documents { get; set; }
DbSet<KeyValue> KeyValues { get; set; }
DbSet<PicklistSet> PicklistSets { get; set; }
DbSet<Product> Products { get; set; }
DbSet<Tenant> Tenants { get; set; }
DbSet<Contact> Contacts { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Common/Interfaces/IPicklistService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using CleanArchitecture.Blazor.Application.Features.KeyValues.DTOs;
using CleanArchitecture.Blazor.Application.Features.PicklistSets.DTOs;

namespace CleanArchitecture.Blazor.Application.Common.Interfaces;

public interface IPicklistService
{
List<KeyValueDto> DataSource { get; }
List<PicklistSetDto> DataSource { get; }
event Func<Task>? OnChange;
void Initialize();
void Refresh();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CleanArchitecture.Blazor.Application.Features.KeyValues.Caching;
namespace CleanArchitecture.Blazor.Application.Features.PicklistSets.Caching;

public static class KeyValueCacheKey
public static class PicklistSetCacheKey
{
public const string GetAllCacheKey = "all-keyvalues";
public const string PicklistCacheKey = "all-picklistcachekey";
public const string GetAllCacheKey = "all-PicklistSet";
public const string PicklistCacheKey = "all-PicklistSetcachekey";
private static readonly TimeSpan RefreshInterval = TimeSpan.FromHours(1);
private static readonly object _tokenLock = new();
private static CancellationTokenSource _tokenSource = new(RefreshInterval);
Expand All @@ -18,7 +18,7 @@ public static class KeyValueCacheKey

public static string GetCacheKey(string name)
{
return $"{name}-keyvalues";
return $"{name}-PicklistSet";
}

public static CancellationTokenSource GetOrCreateTokenSource()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CleanArchitecture.Blazor.Application.Features.KeyValues.Caching;
using CleanArchitecture.Blazor.Application.Features.KeyValues.DTOs;
using CleanArchitecture.Blazor.Application.Features.PicklistSets.Caching;
using CleanArchitecture.Blazor.Application.Features.PicklistSets.DTOs;

namespace CleanArchitecture.Blazor.Application.Features.KeyValues.Commands.AddEdit;
namespace CleanArchitecture.Blazor.Application.Features.PicklistSets.Commands.AddEdit;

public class AddEditKeyValueCommand : ICacheInvalidatorRequest<Result<int>>
public class AddEditPicklistSetCommand : ICacheInvalidatorRequest<Result<int>>
{
[Description("Id")] public int Id { get; set; }

Expand All @@ -19,25 +19,25 @@ public class AddEditKeyValueCommand : ICacheInvalidatorRequest<Result<int>>
[Description("Description")] public string? Description { get; set; }

public TrackingState TrackingState { get; set; } = TrackingState.Unchanged;
public string CacheKey => KeyValueCacheKey.GetAllCacheKey;
public CancellationTokenSource? SharedExpiryTokenSource => KeyValueCacheKey.GetOrCreateTokenSource();
public string CacheKey => PicklistSetCacheKey.GetAllCacheKey;
public CancellationTokenSource? SharedExpiryTokenSource => PicklistSetCacheKey.GetOrCreateTokenSource();

private class Mapping : Profile
{
public Mapping()
{
CreateMap<KeyValueDto, AddEditKeyValueCommand>(MemberList.None);
CreateMap<AddEditKeyValueCommand, KeyValue>(MemberList.None);
CreateMap<PicklistSetDto, AddEditPicklistSetCommand>(MemberList.None);
CreateMap<AddEditPicklistSetCommand, PicklistSet>(MemberList.None);
}
}
}

public class AddEditKeyValueCommandHandler : IRequestHandler<AddEditKeyValueCommand, Result<int>>
public class AddEditPicklistSetCommandHandler : IRequestHandler<AddEditPicklistSetCommand, Result<int>>
{
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;

public AddEditKeyValueCommandHandler(
public AddEditPicklistSetCommandHandler(
IApplicationDbContext context,
IMapper mapper
)
Expand All @@ -46,22 +46,22 @@ IMapper mapper
_mapper = mapper;
}

public async Task<Result<int>> Handle(AddEditKeyValueCommand request, CancellationToken cancellationToken)
public async Task<Result<int>> Handle(AddEditPicklistSetCommand request, CancellationToken cancellationToken)
{
if (request.Id > 0)
{
var keyValue = await _context.KeyValues.FindAsync(new object[] { request.Id }, cancellationToken);
var keyValue = await _context.PicklistSets.FindAsync(new object[] { request.Id }, cancellationToken);
_ = keyValue ?? throw new NotFoundException($"KeyValue Pair {request.Id} Not Found.");
keyValue = _mapper.Map(request, keyValue);
keyValue.AddDomainEvent(new UpdatedEvent<KeyValue>(keyValue));
keyValue.AddDomainEvent(new UpdatedEvent<PicklistSet>(keyValue));
await _context.SaveChangesAsync(cancellationToken);
return await Result<int>.SuccessAsync(keyValue.Id);
}
else
{
var keyValue = _mapper.Map<KeyValue>(request);
keyValue.AddDomainEvent(new UpdatedEvent<KeyValue>(keyValue));
_context.KeyValues.Add(keyValue);
var keyValue = _mapper.Map<PicklistSet>(request);
keyValue.AddDomainEvent(new UpdatedEvent<PicklistSet>(keyValue));
_context.PicklistSets.Add(keyValue);
await _context.SaveChangesAsync(cancellationToken);
return await Result<int>.SuccessAsync(keyValue.Id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace CleanArchitecture.Blazor.Application.Features.KeyValues.Commands.AddEdit;
namespace CleanArchitecture.Blazor.Application.Features.PicklistSets.Commands.AddEdit;

public class AddEditKeyValueCommandValidator : AbstractValidator<AddEditKeyValueCommand>
public class AddEditPicklistSetCommandValidator : AbstractValidator<AddEditPicklistSetCommand>
{
public AddEditKeyValueCommandValidator()
public AddEditPicklistSetCommandValidator()
{
RuleFor(v => v.Name).NotNull();
RuleFor(v => v.Text).MaximumLength(50).NotEmpty();
Expand Down
Loading

0 comments on commit 8839d3c

Please sign in to comment.