diff --git a/Directory.Build.props b/Directory.Build.props index 59e5f9e..d936912 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ Axolotl - 8.0.2 + 8.0.5 radioActive DROID Personal shared utility library git diff --git a/Directory.Packages.props b/Directory.Packages.props index 90ce775..7615d17 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,20 +6,15 @@ - - - - + - - diff --git a/src/aspnet/Axolotl.AspNet.csproj b/src/aspnet/Axolotl.AspNet.csproj index 308f1d3..e7c00b3 100644 --- a/src/aspnet/Axolotl.AspNet.csproj +++ b/src/aspnet/Axolotl.AspNet.csproj @@ -15,9 +15,8 @@ - - + diff --git a/src/aspnet/Feature/GenericFeature.Helpers.cs b/src/aspnet/Feature/GenericFeature.Helpers.cs index e833181..f83e52c 100644 --- a/src/aspnet/Feature/GenericFeature.Helpers.cs +++ b/src/aspnet/Feature/GenericFeature.Helpers.cs @@ -34,7 +34,7 @@ protected static IEndpointRouteBuilder SetupGroup var name = options.Name ?? type.Name.ToLower(); var url = options.Path ?? $"{root}/{name}"; var instance = new TFeature() as TAFeature; - var group = endpoints.MapGroup(url).WithTags(name.Capitalize()); + var group = endpoints.MapGroup(url).WithTags(name); if (instance! == null) throw new Exception("Feature instance not initialized."); instance.Endpoints = group; diff --git a/src/aspnet/Globals.cs b/src/aspnet/Globals.cs deleted file mode 100644 index 890d6fb..0000000 --- a/src/aspnet/Globals.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2022 - 2023 Godwin peter .O (me@godwin.dev) -// -// Licensed under the MIT License; -// you may not use this file except in compliance with the License. -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -global using Nextended.Core.Extensions; \ No newline at end of file diff --git a/src/aspnet/Service/GenericService.Extended.cs b/src/aspnet/Service/GenericService.Extended.cs index 212875e..aba073f 100644 --- a/src/aspnet/Service/GenericService.Extended.cs +++ b/src/aspnet/Service/GenericService.Extended.cs @@ -17,6 +17,7 @@ using Axolotl.Filters; using Axolotl.Interfaces; using Axolotl.Response; +using Mapster; namespace Axolotl.AspNet.Service; @@ -35,7 +36,7 @@ public async Task> PageFilter(ISpecification s var count = await repo.Query(cancellationToken).WithSpecification(specification).CountAsync(cancellationToken); var take = (page - 1) * size; var result = await repo.Query(cancellationToken).WithSpecification(specification).Take(size).Skip(take).ToListAsync(cancellationToken); - var output = result.MapTo>(); + var output = result.Adapt>(); return new PagedResponse(output, page, size, count); } @@ -52,7 +53,7 @@ public async Task> GetAllAsync(IPageFilter? filter, Typ public async Task> GetByIdAsync(TKey id, CancellationToken cancellationToken = default) { var result = await repo.GetByIdAsync(id, cancellationToken); - var output = result.MapTo(); + var output = result.Adapt(); return new Response(output); } @@ -64,38 +65,38 @@ public async Task> GetBySpec(Type spec, TOptio } public async Task> CreateAsync(IResponse value, CancellationToken cancellationToken = default) { - var result = await repo.AddAsync(value.MapTo(), cancellationToken); - var output = result.MapTo(); + var result = await repo.AddAsync(value.Adapt(), cancellationToken); + var output = result.Adapt(); return new Response(output); } public async Task> CreateRangeAsync(IEnumerable values, CancellationToken cancellationToken = default) { - var converted = values.MapTo>().ToList(); + var converted = values.Adapt>().ToList(); var result = await repo.AddRangeAsync(converted, cancellationToken); - var output = result.MapTo>(); + var output = result.Adapt>(); return new PagedResponse(output); } public async Task> UpdateAsync(IResponse value, CancellationToken cancellationToken = default) { - var result = await repo.UpdateAsync(value.MapTo(), cancellationToken); - var output = result.MapTo(); + var result = await repo.UpdateAsync(value.Adapt(), cancellationToken); + var output = result.Adapt(); return new Response(output); } public async Task> UpdateRangeAsync(IEnumerable values, CancellationToken cancellationToken = default) { - var converted = values.MapTo>().ToList(); + var converted = values.Adapt>().ToList(); var result = await repo.UpdateRangeAsync(converted, cancellationToken); - var output = result.MapTo>(); + var output = result.Adapt>(); return new PagedResponse(output); } public async Task> DeleteAsync(TKey id, CancellationToken cancellationToken = default) { var result = await repo.DeleteAsync(id, cancellationToken); - var output = result.MapTo(); + var output = result.Adapt(); return new Response(output, "", result != null); } @@ -109,7 +110,7 @@ public async Task> DeleteRangeAsync(IEnumerable ids, Cancell public async Task> DeleteBySpec(Type spec, TOption option, CancellationToken cancellationToken = default) where TOption : class { var specification = GenerateSpec.Build(spec, option); var result = await repo.DeleteBySpec(specification, cancellationToken); - var output = result.MapTo>(); + var output = result.Adapt>(); return new PagedResponse(output); } diff --git a/src/efcore/Axolotl.EFCore.csproj b/src/efcore/Axolotl.EFCore.csproj index f7babe5..7a9e5e1 100644 --- a/src/efcore/Axolotl.EFCore.csproj +++ b/src/efcore/Axolotl.EFCore.csproj @@ -13,8 +13,8 @@ - + diff --git a/src/efcore/Context/ModelBuilderExtensions.cs b/src/efcore/Context/ModelBuilderExtensions.cs index f832d17..1124c57 100644 --- a/src/efcore/Context/ModelBuilderExtensions.cs +++ b/src/efcore/Context/ModelBuilderExtensions.cs @@ -9,7 +9,6 @@ // limitations under the License. using System.Reflection; -using Axolotl.EFCore.Converters; using Microsoft.EntityFrameworkCore; using Axolotl.EFCore.Interfaces; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -33,36 +32,6 @@ public static void RegisterSoftDeleteFilter(this ModelBuilder modelBuilder) { entityType.AddSoftDeleteQueryFilter(); } - public static void RegisterEnumConverters(this ModelBuilder modelBuilder, Type type) - where TEnum : Enum - { - foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { - var properties = entityType.ClrType.GetProperties() - .Where(p => p.PropertyType == type); - foreach (var property in properties) - modelBuilder - .Entity(entityType.Name) - .Property(property.Name) - .HasConversion(new EnumCollectionJsonValueConverter()) - .Metadata.SetValueComparer(new CollectionValueComparer()); - } - } - - public static void RegisterObjectConverters(this ModelBuilder modelBuilder, Type type) - where TObject : Enum - { - foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { - var properties = entityType.ClrType.GetProperties() - .Where(p => p.PropertyType == type); - foreach (var property in properties) - modelBuilder - .Entity(entityType.Name) - .Property(property.Name) - .HasConversion(new JsonValueConverter()) - .Metadata.SetValueComparer(new CollectionValueComparer()); - } - } - public static void DateTimeOffsetToBinary(this ModelBuilder modelBuilder) { foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { var properties = entityType.ClrType.GetProperties() diff --git a/src/efcore/Converters/CollectionValueComparer.cs b/src/efcore/Converters/CollectionValueComparer.cs deleted file mode 100644 index 8df7f3e..0000000 --- a/src/efcore/Converters/CollectionValueComparer.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022 - 2023 Godwin peter .O (me@godwin.dev) -// -// Licensed under the MIT License; -// you may not use this file except in compliance with the License. -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.EntityFrameworkCore.ChangeTracking; - -namespace Axolotl.EFCore.Converters; - -public class CollectionValueComparer : ValueComparer> { - public CollectionValueComparer() : base((c1, c2) => c1!.SequenceEqual(c2!), - c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v!.GetHashCode())), c => (ICollection)c.ToHashSet()) { - } -} \ No newline at end of file diff --git a/src/efcore/Converters/EnumCollectionJsonValueConverter.cs b/src/efcore/Converters/EnumCollectionJsonValueConverter.cs deleted file mode 100644 index f86eb1a..0000000 --- a/src/efcore/Converters/EnumCollectionJsonValueConverter.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2022 - 2023 Godwin peter .O (me@godwin.dev) -// -// Licensed under the MIT License; -// you may not use this file except in compliance with the License. -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Newtonsoft.Json; - -namespace Axolotl.EFCore.Converters; - -public class EnumCollectionJsonValueConverter : ValueConverter, string> where T : Enum { - public EnumCollectionJsonValueConverter() : base( - v => JsonConvert - .SerializeObject(v.Select(e => e.ToString()).ToList()), - v => JsonConvert - .DeserializeObject>(v)! - .Select(e => (T)Enum.Parse(typeof(T), e)).ToList()) { } -} \ No newline at end of file diff --git a/src/efcore/Converters/JsonValueConverter.cs b/src/efcore/Converters/JsonValueConverter.cs deleted file mode 100644 index 5fb989e..0000000 --- a/src/efcore/Converters/JsonValueConverter.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022 - 2023 Godwin peter .O (me@godwin.dev) -// -// Licensed under the MIT License; -// you may not use this file except in compliance with the License. -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Newtonsoft.Json; - -namespace Axolotl.EFCore.Converters; - -public class JsonValueConverter : ValueConverter { - public JsonValueConverter() : base(v => JsonConvert.SerializeObject(v), - v => JsonConvert.DeserializeObject(v) ?? (T)new object()) { } -} \ No newline at end of file diff --git a/src/standard/Axolotl.csproj b/src/standard/Axolotl.csproj index a2292e2..298c479 100644 --- a/src/standard/Axolotl.csproj +++ b/src/standard/Axolotl.csproj @@ -13,7 +13,6 @@ -