Skip to content

Commit

Permalink
get rid of functional extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Jun 27, 2024
1 parent cbf135b commit 948d070
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Amazon.DynamoDBv2.DataModel;
using CSharpFunctionalExtensions;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Data.Handlers.Options;
using YuckQi.Domain.Aspects.Abstract;
Expand Down Expand Up @@ -57,7 +56,7 @@ public override async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> ent
return list;
}

protected override Maybe<TIdentifier?> DoCreate(TEntity entity, TScope? scope)
protected override TIdentifier? DoCreate(TEntity entity, TScope? scope)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));
Expand All @@ -68,7 +67,7 @@ public override async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> ent
return result;
}

protected override async Task<Maybe<TIdentifier?>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
protected override async Task<TIdentifier?> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));
Expand All @@ -78,6 +77,6 @@ public override async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> ent

await table.PutItemAsync(scope.ToDocument(document), cancellationToken);

return Maybe<TIdentifier?>.From(entity.Identifier);
return entity.Identifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for Amazon DynamoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CSharpFunctionalExtensions;
using MongoDB.Driver;
using MongoDB.Driver;
using YuckQi.Data.DocumentDb.MongoDb.Extensions;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Data.Handlers.Options;
Expand Down Expand Up @@ -54,7 +53,7 @@ public override async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> ent
return list;
}

protected override Maybe<TIdentifier?> DoCreate(TEntity entity, TScope? scope)
protected override TIdentifier? DoCreate(TEntity entity, TScope? scope)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));
Expand All @@ -68,7 +67,7 @@ public override async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> ent
return document.GetIdentifier<TDocument, TIdentifier>();
}

protected override async Task<Maybe<TIdentifier?>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
protected override async Task<TIdentifier?> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for MongoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
7 changes: 3 additions & 4 deletions src/YuckQi.Data.MemDb/Handlers/CreationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using CSharpFunctionalExtensions;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Data.Handlers.Options;
using YuckQi.Domain.Aspects.Abstract;
Expand All @@ -16,13 +15,13 @@ public CreationHandler(ConcurrentDictionary<TIdentifier, TEntity> entities, Crea
_entities = entities ?? throw new ArgumentNullException(nameof(entities));
}

protected override Maybe<TIdentifier?> DoCreate(TEntity entity, TScope? scope)
protected override TIdentifier? DoCreate(TEntity entity, TScope? scope)
{
if (entity.Identifier == null)
throw new InvalidOperationException();

return _entities.TryAdd(entity.Identifier, entity) ? entity.Identifier : Maybe<TIdentifier?>.None;
return _entities.TryAdd(entity.Identifier, entity) ? entity.Identifier : default;
}

protected override Task<Maybe<TIdentifier?>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken) => Task.FromResult(DoCreate(entity, scope));
protected override Task<TIdentifier?> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken) => Task.FromResult(DoCreate(entity, scope));
}
2 changes: 1 addition & 1 deletion src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for a in-memory "database" (ConcurrentDictionary), ideal for rapid development without external dependencies.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for MySQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for Oracle databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for MSSQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
9 changes: 4 additions & 5 deletions src/YuckQi.Data.Sql.Dapper/Handlers/CreationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Data;
using CSharpFunctionalExtensions;
using Dapper;
using YuckQi.Data.Handlers.Abstract;
using YuckQi.Data.Handlers.Options;
Expand All @@ -22,23 +21,23 @@ public CreationHandler(IMapper? mapper) : base(mapper) { }

public CreationHandler(CreationOptions<TIdentifier>? options, IMapper? mapper) : base(options, mapper) { }

protected override Maybe<TIdentifier?> DoCreate(TEntity entity, TScope? scope)
protected override TIdentifier? DoCreate(TEntity entity, TScope? scope)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));

var record = MapToData<TRecord>(entity) ?? throw new InvalidOperationException();

return Maybe.From(scope.Connection.Insert<TIdentifier?, TRecord>(record, scope));
return scope.Connection.Insert<TIdentifier?, TRecord>(record, scope);
}

protected override async Task<Maybe<TIdentifier?>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
protected override Task<TIdentifier?> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken)
{
if (scope == null)
throw new ArgumentNullException(nameof(scope));

var record = MapToData<TRecord>(entity) ?? throw new InvalidOperationException();

return Maybe.From(await scope.Connection.InsertAsync<TIdentifier?, TRecord>(record, scope));
return scope.Connection.InsertAsync<TIdentifier?, TRecord>(record, scope);
}
}
2 changes: 1 addition & 1 deletion src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Entity Framework.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
15 changes: 7 additions & 8 deletions src/YuckQi.Data/Handlers/Abstract/CreationHandlerBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CSharpFunctionalExtensions;
using YuckQi.Data.Exceptions;
using YuckQi.Data.Exceptions;
using YuckQi.Data.Handlers.Options;
using YuckQi.Domain.Aspects.Abstract;
using YuckQi.Domain.Entities.Abstract;
Expand Down Expand Up @@ -37,10 +36,10 @@ public TEntity Create(TEntity entity, TScope? scope)
revised.RevisionMomentUtc = entity.CreationMomentUtc;

var identifier = DoCreate(entity, scope);
if (identifier.HasNoValue)
if (identifier == null)
throw new CreationException<TEntity>();

entity.Identifier = identifier.Value;
entity.Identifier = identifier;

return entity;
}
Expand All @@ -65,10 +64,10 @@ public async Task<TEntity> Create(TEntity entity, TScope? scope, CancellationTok
revised.RevisionMomentUtc = entity.CreationMomentUtc;

var identifier = await DoCreate(entity, scope, cancellationToken);
if (identifier.HasNoValue)
if (identifier == null)
throw new CreationException<TEntity>();

entity.Identifier = identifier.Value;
entity.Identifier = identifier;

return entity;
}
Expand All @@ -81,7 +80,7 @@ public virtual async Task<IEnumerable<TEntity>> Create(IEnumerable<TEntity> enti
return results;
}

protected abstract Maybe<TIdentifier?> DoCreate(TEntity entity, TScope? scope);
protected abstract TIdentifier? DoCreate(TEntity entity, TScope? scope);

protected abstract Task<Maybe<TIdentifier?>> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken);
protected abstract Task<TIdentifier?> DoCreate(TEntity entity, TScope? scope, CancellationToken cancellationToken);
}
3 changes: 1 addition & 2 deletions src/YuckQi.Data/YuckQi.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.5.0</Version>
<Version>6.5.1</Version>
<Description>A .NET library of lightweight data access handlers which can be used to compose repositories and domain services.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -20,7 +20,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.40.3" />
<PackageReference Include="YuckQi.Domain" Version="6.4.2" />
<PackageReference Include="YuckQi.Extensions.Mapping.Abstractions" Version="6.0.0" />
</ItemGroup>
Expand Down

0 comments on commit 948d070

Please sign in to comment.