Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Nest Library. Change Elastic Dependencies. #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .vs/ElasticSearchProductAPI/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,910 changes: 941 additions & 969 deletions .vs/ElasticSearchProductAPI/config/applicationhost.config

Large diffs are not rendered by default.

Binary file modified .vs/ElasticSearchProductAPI/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/ElasticSearchProductAPI/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/elasticsearchproductapi.projects.v7.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions Src/ElasticSearchProduct.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<PropertyGroup>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
<ActiveDebugProfile>Docker</ActiveDebugProfile>
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
17 changes: 11 additions & 6 deletions Src/ElasticSearchProduct.API/Extension/ElasticDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Elasticsearch.Net;

using Elastic.Clients.Elasticsearch;
using Elastic.Transport;
using ElasticSearchProduct.API.Repositories.Concrete;
using ElasticSearchProduct.API.Repositories.Interfaces;
using ElasticSearchProduct.API.Services.Concrete;
using ElasticSearchProduct.API.Services.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Nest;


namespace ElasticSearchProduct.API.Extension
{
Expand All @@ -17,10 +19,13 @@ public static class ElasticDependencies
/// <param name="configuration"></param>
public static void AddElasticSearchDependency(this IServiceCollection services,IConfiguration configuration)
{
var pool = new SingleNodeConnectionPool(new Uri(configuration.GetSection("Elastic")["Url"]!));
var settings = new ConnectionSettings(pool);
var client = new ElasticClient(settings);


var userName = (configuration.GetSection("Elastic")["Username"]!);
var passWord = (configuration.GetSection("Elastic")["Password"]!);
var settings = new ElasticsearchClientSettings(new Uri(configuration.GetSection("Elastic")["Url"]!))
.Authentication(new BasicAuthentication(userName, passWord));
var client = new ElasticsearchClient(settings);

services.AddSingleton(client);
}
}
Expand Down
1 change: 0 additions & 1 deletion Src/ElasticSearchProduct.API/Mapping/GeneralMapping.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using AutoMapper;
using ElasticSearchProduct.API.Dto;
using ElasticSearchProduct.API.Models;
using Nest;

namespace ElasticSearchProduct.API.Mapping
{
Expand Down
2 changes: 0 additions & 2 deletions Src/ElasticSearchProduct.API/Models/Product.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using ElasticSearchProduct.API.Dto;
using Nest;

namespace ElasticSearchProduct.API.Models
{
public class Product
{
[PropertyName("_id")]
public string Id { get; set; } = null!;
public string Name { get; set; } = null!;
public string StockCode { get; set; } = null!;
Expand Down
4 changes: 2 additions & 2 deletions Src/ElasticSearchProduct.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Elasticsearch.Net;

using ElasticSearchProduct.API.Extension;
using Nest;


var builder = WebApplication.CreateBuilder(args);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using ElasticSearchProduct.API.Dto;
using Elastic.Clients.Elasticsearch;
using ElasticSearchProduct.API.Dto;
using ElasticSearchProduct.API.Models;
using ElasticSearchProduct.API.Repositories.Interfaces;
using Nest;
using System.Collections.Immutable;

namespace ElasticSearchProduct.API.Repositories.Concrete
{
public class ProductRepository : IProductRepository
{
private readonly ElasticClient _elasticClient;
private readonly ElasticsearchClient _elasticClient;
private const string indexName = "products";
public ProductRepository(ElasticClient elasticClient)
public ProductRepository(ElasticsearchClient elasticClient)
{
_elasticClient = elasticClient;
}
Expand All @@ -28,33 +28,33 @@ public async Task<Product> SaveAsync(Product newProduct)
newProduct.Created = DateTime.Now;
var response = await _elasticClient.IndexAsync(newProduct, x => x.Index(indexName).Id(Guid.NewGuid().ToString()));

if (!response.IsValid) return null;
if (!response.IsSuccess()) return null;
newProduct.Id = response.Id;
return newProduct;
}

public async Task<Product?> GetByIdAsync(string @id)
{
var response = await _elasticClient.GetAsync<Product>(id, x => x.Index(indexName));
if (!response.IsValid) return null;
if (!response.IsSuccess()) return null;
response.Source.Id = response.Id;
return response.Source;
}

public async Task<bool> UpdateAsync(ProductUpdateDTO productUpdateDTO)
{
var response = await _elasticClient.UpdateAsync
<Product,ProductUpdateDTO>(productUpdateDTO.Id, x => x.Index(indexName).Doc(productUpdateDTO));
<Product,ProductUpdateDTO>(indexName, productUpdateDTO.Id,x=>x.Doc(productUpdateDTO));

return response.IsValid;
return response.IsSuccess();
}

public async Task<bool> DeleteAsync(string Id)
{
var response = await _elasticClient.DeleteAsync
<Product>(Id, x => x.Index(indexName));

return response.IsValid;
return response.IsSuccess();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using ElasticSearchProduct.API.Models;
using ElasticSearchProduct.API.Repositories.Interfaces;
using ElasticSearchProduct.API.Services.Interfaces;
using Nest;
using System.Collections.Immutable;
using System.Net;

Expand Down
5 changes: 5 additions & 0 deletions Src/ElasticSearchProduct.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"Elastic": {
"Url": "http://localhost:9200",
"Username": "elastic",
"Password": "changeme"
},
"AllowedHosts": "*"
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Elastic": {
"Url": "http://localhost:9200",
"Url": "http://elk-stack-elasticsearch-1:9200",
"Username": "elastic",
"Password": "changeme"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"Elastic": {
"Url": "http://elk-stack-elasticsearch-1:9200",
"Username": "elastic",
"Password": "changeme"
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
Fast
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
a120912bef5b1da358ec6217c392f49636129252613998f7d93f5706fdfd18fd
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
ElasticSearchProduct.API
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
lvKPPpBrRMQpgvmtC80mGo1sZfrfGAutuGSfyn5SIXw=
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"target": "Package",
"version": "[12.0.1, )"
},
"Elastic.Clients.Elasticsearch": {
"target": "Package",
"version": "[8.1.3, )"
},
"Microsoft.AspNetCore.OpenApi": {
"target": "Package",
"version": "[7.0.9, )"
Expand All @@ -53,10 +57,6 @@
"target": "Package",
"version": "[1.18.1, )"
},
"NEST": {
"target": "Package",
"version": "[7.17.5, )"
},
"Swashbuckle.AspNetCore": {
"target": "Package",
"version": "[6.5.0, )"
Expand Down
Loading