Code Monkey home page Code Monkey logo

tg-interview's Introduction

TGInterview

The backend of the frontend project uses the TGInterview.ApiRequestService project located under the Library folder to send requests to the related microservices. Json serialize and deserialize operations are done here. In the project (UI Backend) that wants to use ApiRequestService, first of all, DI registration in Singleton type must be done. Then the HttpClient needs to be added. These operations are:

builder.Services.AddSingleton<IApiRequestService, ApiRequestService>();
builder.Services.AddHttpClient("ProductServiceApi", options =>
{
    options.BaseAddress = new Uri(builder.Configuration.GetValue<string>("ProductServiceApiUrl"));
});

Usage of ApiRequestService:

After the Constructor DI operation is done, the ApiGetRequest method is called to make a GET request. The related method expects which model to return as a GenericType as a result of the GET request. The method expects two parameters. These:

  1. Client name
  2. Endpoint Url without BaseUrl
private readonly IApiRequestService _apiRequestService;

public IndexModel(IApiRequestService apiRequestService)
{
    _apiRequestService = apiRequestService;
}

public async Task<JsonResult> OnGetAllProducts()
{
    var res = await _apiRequestService.ApiGetRequest<ApiResponse<List<ProductGetAllDto>>>("ProductServiceApi", "api/product");

    return new JsonResult(res);
}

Used Technologies

  • FluentValidation
  • MediatR
  • AutoMapper
  • EntityFramework Core
  • Swashbuckle

Service Ports

Service Name HTTPS Port HTTP Port
WebUI 7120 5120
Product Service 7020 5020

Defining The ProductDbConnection Connection Clause In User-Secret

  1. First, go to the API project on the command line.
  TGInterview > ProductService > Presentation > TGInterview.ProductService.Api
  1. Creating user-secrets
  dotnet user-secrets init
  1. Setted user-secrets
  dotnet user-secrets set ProductSqlConnection "Data Source=<IP Number or locahost>,<PORT_NUMBER>;Initial Catalog=<DB_NAME>;User Id=<DB_USERNAME>;Password=<DB_PASSWORD>;Integrated Security=False"

Product Service Migration

Before the product service can run, the database must be created. For this process, we need to create a migration. Since seed data is defined in EntityFramework configurations, the database will be created full. You can follow the steps below to create a migration:

  1. First, go to the API project on the command line.
  TGInterview > ProductService > Presentation > TGInterview.ProductService.Api
  1. The migration creation command is written and the custom context file (ProductDbContext) is defined with the --context parameter.
  dotnet ef migrations add <Migration Name> --context ProductDbContext
  1. The created migration file is processed to the database.
  dotnet ef database update

tg-interview's People

Contributors

enesaltun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.