Add project files.
This commit is contained in:
		
							
								
								
									
										18
									
								
								Core.Blueprint.DAL.Mongo/Contracts/IBlueprintService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Core.Blueprint.DAL.Mongo/Contracts/IBlueprintService.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| using Core.Blueprint.DAL.Mongo.Entities.Collections; | ||||
| using Core.Blueprint.DAL.Mongo.Entities.Requests; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.Mongo.Contracts | ||||
| { | ||||
|     public interface IBlueprintService | ||||
|     { | ||||
|         ValueTask<BlueprintCollection> CreateBlueprint(BlueprintRequest newBlueprint, CancellationToken cancellationToken); | ||||
|  | ||||
|         ValueTask<BlueprintCollection> GetBlueprintById(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         ValueTask<IEnumerable<BlueprintCollection>> GetAllBlueprints(CancellationToken cancellationToken); | ||||
|  | ||||
|         ValueTask<BlueprintCollection> UpdateBlueprint(string _id, BlueprintCollection entity, CancellationToken cancellationToken); | ||||
|  | ||||
|         ValueTask<BlueprintCollection> DeleteBlueprint(string _id, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										22
									
								
								Core.Blueprint.DAL.Mongo/Core.Blueprint.DAL.Mongo.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Core.Blueprint.DAL.Mongo/Core.Blueprint.DAL.Mongo.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net8.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Azure.Identity" Version="1.13.1" /> | ||||
|     <PackageReference Include="Core.Blueprint.Mongo" Version="0.3.0-alpha0047" /> | ||||
|     <PackageReference Include="Core.Blueprint.Redis" Version="0.3.0-alpha0032" /> | ||||
|     <PackageReference Include="Mapster" Version="7.4.1-pre01" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||||
|     <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" /> | ||||
|     <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" /> | ||||
|     <PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" /> | ||||
|     <PackageReference Include="MongoDB.Driver" Version="3.1.0" /> | ||||
|     <PackageReference Include="Serilog" Version="4.2.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
| @@ -0,0 +1,11 @@ | ||||
| using Core.Blueprint.Mongo; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.Mongo.Entities.Collections | ||||
| { | ||||
|     [CollectionAttributeName("Blueprints")] | ||||
|     public class BlueprintCollection : Document | ||||
|     { | ||||
|         public string Name { get; set; } = null!; | ||||
|         public string? Description { get; set; } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,9 @@ | ||||
| namespace Core.Blueprint.DAL.Mongo.Entities.Requests | ||||
| { | ||||
|     public class BlueprintRequest | ||||
|     { | ||||
|         public string Name { get; set; } = null!; | ||||
|  | ||||
|         public string? Description { get; set; } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										80
									
								
								Core.Blueprint.DAL.Mongo/Service/BlueprintService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								Core.Blueprint.DAL.Mongo/Service/BlueprintService.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| using Core.Blueprint.DAL.Mongo.Contracts; | ||||
| using Core.Blueprint.DAL.Mongo.Entities.Collections; | ||||
| using Core.Blueprint.DAL.Mongo.Entities.Requests; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Blueprint.Redis; | ||||
| using Core.Blueprint.Redis.Helpers; | ||||
| using Mapster; | ||||
| using Microsoft.Extensions.Options; | ||||
|  | ||||
| namespace Core.Blueprint.DAL.Mongo.Service | ||||
| { | ||||
|     public class BlueprintService : IBlueprintService | ||||
|     { | ||||
|         private readonly CollectionRepository<BlueprintCollection> repository; | ||||
|         private readonly CacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public BlueprintService(CollectionRepository<BlueprintCollection> repository, | ||||
|         IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings.Value; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|         } | ||||
|  | ||||
|         public async ValueTask<BlueprintCollection> CreateBlueprint(BlueprintRequest newBlueprint, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var blueprintCollection = newBlueprint.Adapt<BlueprintCollection>(); | ||||
|  | ||||
|             await this.repository.InsertOneAsync(blueprintCollection); | ||||
|  | ||||
|             return blueprintCollection; | ||||
|         } | ||||
|  | ||||
|         public async ValueTask<BlueprintCollection> GetBlueprintById(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetBlueprintById", _id); | ||||
|             var cachedData = await cacheProvider.GetAsync<BlueprintCollection>(cacheKey); | ||||
|  | ||||
|             if (cachedData is not null) { return cachedData; } | ||||
|  | ||||
|             var blueprint = await this.repository.FindByIdAsync(_id); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, blueprint); | ||||
|  | ||||
|             return blueprint; | ||||
|         } | ||||
|  | ||||
|         public async ValueTask<IEnumerable<BlueprintCollection>> GetAllBlueprints(CancellationToken cancellationToken) | ||||
|         { | ||||
|  | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllBlueprints"); | ||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<BlueprintCollection>>(cacheKey) ?? []; | ||||
|  | ||||
|             if (cachedData.Any()) return cachedData; | ||||
|  | ||||
|             var blueprints = await this.repository.AsQueryable(); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, blueprints); | ||||
|  | ||||
|             return blueprints; | ||||
|         } | ||||
|  | ||||
|         public async ValueTask<BlueprintCollection> UpdateBlueprint(string _id, BlueprintCollection entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             await this.repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         public async ValueTask<BlueprintCollection> DeleteBlueprint(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var entity = await this.repository.DeleteOneAsync(doc => doc._Id == _id); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin