Skip to content

Commit

Permalink
Merge pull request #9 from MahdiyarGHD/develop
Browse files Browse the repository at this point in the history
Refactor to new version of the core
  • Loading branch information
Ali-YousefiTelori authored Nov 3, 2023
2 parents 3813bf7 + e9a2e30 commit f952390
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 377 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using EasyMicroservices.QuestionsMicroservice.Database.Entities;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;

namespace EasyMicroservices.QuestionsMicroservice.Database.Contexts
{
public class QuestionContext : RelationalCoreContext
{
IDatabaseBuilder _builder;
public QuestionContext(IDatabaseBuilder builder)
IEntityFrameworkCoreDatabaseBuilder _builder;

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / format

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / os-tests

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / os-tests

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / os-tests

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / os-tests

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / os-tests

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null

Check warning on line 10 in src/CSharp/EasyMicroservices.QuestionsMicroservice.Database/Database/Contexts/QuestionContext.cs

View workflow job for this annotation

GitHub Actions / os-tests

Field 'QuestionContext._builder' is never assigned to, and will always have its default value null
public QuestionContext(IEntityFrameworkCoreDatabaseBuilder builder) : base(builder)
{
_builder = builder;
}

public DbSet<QuestionEntity> Questions { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

<ItemGroup>
<PackageReference Include="EasyMicroservices.Configuration" Version="0.0.0.2" />
<PackageReference Include="EasyMicroservices.Cores.Relational.EntityFrameworkCore" Version="0.0.0.21" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.44" />
<PackageReference Include="EasyMicroservices.Cores.Relational.EntityFrameworkCore" Version="0.0.0.44" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.ContentsMicroservice.Clients" Version="0.0.0.10" />
<PackageReference Include="EasyMicroservices.Cores.Database" Version="0.0.0.33" />
<PackageReference Include="EasyMicroservices.ContentsMicroservice.Clients" Version="0.0.0.16" />
<PackageReference Include="EasyMicroservices.Cores.Database" Version="0.0.0.44" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EasyMicroservices.QuestionsMicroservice.Database;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using EasyMicroservices.QuestionsMicroservice.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
Expand All @@ -9,16 +10,18 @@

namespace EasyMicroservices.QuestionsMicroservice
{
public class DatabaseBuilder : IDatabaseBuilder
public class DatabaseBuilder : IEntityFrameworkCoreDatabaseBuilder
{
readonly IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
IConfiguration _configuration;
public DatabaseBuilder(IConfiguration configuration)
{
_configuration = configuration;
}

public void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseInMemoryDatabase("QuestionDatabase");
//optionsBuilder.UseSqlServer(config.GetConnectionString("local"));
//optionsBuilder.UseSqlServer(_configuration.GetConnectionString("local"));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.Clients" Version="0.0.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.10" />
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.Clients" Version="0.0.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.13" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Contents.GeneratedServices;
using EasyMicroservices.Cores.AspCoreApi;
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces;
using EasyMicroservices.Cores.Contracts.Requests;
using EasyMicroservices.Cores.Database.Interfaces;
using EasyMicroservices.QuestionsMicroservice.Contracts.Common;
Expand All @@ -14,20 +15,22 @@ public class AnswerController : SimpleQueryServiceController<AnswerEntity, Creat
{
private readonly IContractLogic<QuestionEntity, CreateQuestionRequestContract, UpdateQuestionRequestContract, QuestionContract, long> _questionlogic;
private readonly IContractLogic<AnswerEntity, CreateAnswerRequestContract, UpdateAnswerRequestContract, AnswerContract, long> _contractlogic;
private readonly IConfiguration _config;
public string _contentRoot;
private readonly ContentClient _contentClient;
private string _contentRoot;
private readonly IConfiguration _config;

public AnswerController(IContractLogic<QuestionEntity, CreateQuestionRequestContract, UpdateQuestionRequestContract, QuestionContract, long> questionlogic, IContractLogic<AnswerEntity, CreateAnswerRequestContract, UpdateAnswerRequestContract, AnswerContract, long> contractLogic, IConfiguration config) : base(contractLogic)
readonly IUnitOfWork unitOfWork;
public AnswerController(IUnitOfWork _unitOfWork, IConfiguration config) : base(_unitOfWork)
{
_contractlogic = contractLogic;
_questionlogic = questionlogic;
unitOfWork = _unitOfWork;
_questionlogic = _unitOfWork.GetContractLogic<QuestionEntity, CreateQuestionRequestContract, UpdateQuestionRequestContract, QuestionContract, long>();
_contractlogic = _unitOfWork.GetContractLogic<AnswerEntity, CreateAnswerRequestContract, UpdateAnswerRequestContract, AnswerContract, long>();

_config = config;

_contentRoot = _config.GetValue<string>("RootAddresses:Content");
_contentClient = new(_contentRoot, new HttpClient());
}

public override async Task<MessageContract<long>> Add(CreateAnswerRequestContract request, CancellationToken cancellationToken = default)
{
var checkQuestionId = await _questionlogic.GetById(new GetIdRequestContract<long>() { Id = request.QuestionId });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Contents.GeneratedServices;
using EasyMicroservices.ContentsMicroservice.Clients.Helpers;
using EasyMicroservices.Cores.AspCoreApi;
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces;
using EasyMicroservices.Cores.Contracts.Requests;
using EasyMicroservices.Cores.Database.Interfaces;
using EasyMicroservices.QuestionsMicroservice.Contracts.Common;
Expand All @@ -22,15 +23,19 @@ public class QuestionController : SimpleQueryServiceController<QuestionEntity, C
public string _contentRoot;
private readonly ContentClient _contentClient;
private readonly IConfiguration _config;
public QuestionController(IContractLogic<QuestionEntity, CreateQuestionRequestContract, UpdateQuestionRequestContract, QuestionContract, long> contractLogic, IContractLogic<AnswerEntity, CreateAnswerRequestContract, UpdateAnswerRequestContract, AnswerContract, long> answerLogic, IConfiguration config) : base(contractLogic)

readonly IUnitOfWork unitOfWork;
public QuestionController(IUnitOfWork _unitOfWork, IConfiguration config) : base(_unitOfWork)
{
_contractlogic = contractLogic;
_answerLogic = answerLogic;
unitOfWork = _unitOfWork;
_contractlogic = _unitOfWork.GetContractLogic<QuestionEntity, CreateQuestionRequestContract, UpdateQuestionRequestContract, QuestionContract, long>();
_answerLogic = _unitOfWork.GetContractLogic<AnswerEntity, CreateAnswerRequestContract, UpdateAnswerRequestContract, AnswerContract, long>();

_config = config;
_contentRoot = _config.GetValue<string>("RootAddresses:Content");
_contentClient = new(_contentRoot, new HttpClient());
}

public override async Task<MessageContract<long>> Add(CreateQuestionRequestContract request, CancellationToken cancellationToken = default)
{
var addQuestionResult = await base.Add(request, cancellationToken);
Expand Down Expand Up @@ -97,7 +102,7 @@ await _contentClient.HardDeleteByIdAsync(new Int64DeleteRequestContract
[HttpPost]
public async Task<ListMessageContract<GetAllQuestionsWithAnswersResponseContract>> GetAllQuestionsWithAnswers(GetAllQuestionsWithAnswersRequestContract request)
{
var questions = await _contractlogic.GetAllByUniqueIdentity(request, query => query.Include(x => x.Answers));
var questions = await _contractlogic.GetAllByUniqueIdentity(request, Cores.DataTypes.GetUniqueIdentityType.All, query => query.Include(x => x.Answers));
if (!questions)
return questions.ToListContract<GetAllQuestionsWithAnswersResponseContract>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.ContentsMicroservice.Clients" Version="0.0.0.10" />
<PackageReference Include="EasyMicroservices.Cores.AspCoreApi" Version="0.0.0.31" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10">
<PackageReference Include="EasyMicroservices.ContentsMicroservice.Clients" Version="0.0.0.16" />
<PackageReference Include="EasyMicroservices.Cores.AspCoreApi" Version="0.0.0.44" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit f952390

Please sign in to comment.