-
Notifications
You must be signed in to change notification settings - Fork 24
Сукач Данил Лаб. 1 Группа 6511 #6
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
Open
DanilSukach
wants to merge
3
commits into
itsecd:main
Choose a base branch
from
DanilSukach:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using CreditApp.Application.Interfaces; | ||
| using CreditApp.Domain.Entities; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace CreditApp.Api.Controllers; | ||
|
|
||
| /// <summary> | ||
| /// Контроллер для работы с кредитными заявками через HTTP API. | ||
| /// Реализует конечную точку получения заявки по идентификатору. | ||
| /// <param name="creditService">Сервис для получения данных кредитных заявок.</param> | ||
| /// <param name="logger">Логгер для записи событий и ошибок.</param> | ||
| /// </summary> | ||
| [Route("api/[controller]")] | ||
| [ApiController] | ||
| public class CreditController( | ||
| ICreditService creditService, | ||
| ILogger<CreditController> logger | ||
| ) : ControllerBase | ||
| { | ||
| /// <summary> | ||
| /// Получает кредитную заявку по идентификатору. | ||
| /// </summary> | ||
| /// <param name="id">Идентификатор запрашиваемой заявки (передаётся в строке запроса).</param> | ||
| /// <param name="ct">Токен отмены для асинхронной операции.</param> | ||
| /// <returns>HTTP 200 с объектом заявки при успешном получении.</returns> | ||
| [HttpGet] | ||
| [ProducesResponseType<CreditApplication>(StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||
| public async Task<ActionResult<CreditApplication>> Get([FromQuery] int id, CancellationToken ct) | ||
| { | ||
| logger.LogInformation("Request for credit {CreditId} started", id); | ||
|
|
||
| var result = await creditService.GetAsync(id, ct); | ||
|
|
||
| logger.LogInformation("Request for credit {CreditId} completed", id); | ||
|
|
||
| return Ok(result); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| <NoWarn>$(NoWarn);1591</NoWarn> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.StackExchange.Redis" Version="13.1.1" /> | ||
| <PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="13.1.1" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.3" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\CreditApp.Application\CreditApp.Application.csproj" /> | ||
| <ProjectReference Include="..\CreditApp.Domain\CreditApp.Domain.csproj" /> | ||
| <ProjectReference Include="..\CreditApp.Infrastructure\CreditApp.Infrastructure.csproj" /> | ||
| <ProjectReference Include="..\CreditApp\CreditApp.ServiceDefaults\CreditApp.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using CreditApp.Application.Interfaces; | ||
| using CreditApp.ServiceDefaults; | ||
| using CreditApp.Application.Options; | ||
| using CreditApp.Application.Services; | ||
| using CreditApp.Infrastructure.Generators; | ||
| using System.Reflection; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
| builder.AddRedisDistributedCache("credit-cache"); | ||
|
|
||
| builder.Services.AddSingleton<ICreditApplicationGenerator, CreditApplicationGenerator>(); | ||
|
|
||
| builder.Services.Configure<CacheOptions>( | ||
| builder.Configuration.GetSection(CacheOptions.SectionName)); | ||
|
|
||
| builder.Services.AddScoped<ICreditService, CreditService>(); | ||
|
|
||
| builder.Services.AddControllers(); | ||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services.AddSwaggerGen(options => | ||
| { | ||
| var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | ||
| var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); | ||
| options.IncludeXmlComments(xmlPath); | ||
| }); | ||
|
|
||
| var allowedOrigins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get<string[]>() ?? []; | ||
|
|
||
| builder.Services.AddCors(options => | ||
| { | ||
| options.AddPolicy("DefaultCors", policy => | ||
| { | ||
| policy.AllowAnyHeader().AllowAnyMethod(); | ||
|
|
||
| if (builder.Environment.IsDevelopment()) | ||
| policy.AllowAnyOrigin(); | ||
| else | ||
| policy.WithOrigins(allowedOrigins); | ||
| }); | ||
| }); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
| app.UseSwaggerUI(c => | ||
| { | ||
| c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1"); | ||
| c.RoutePrefix = string.Empty; | ||
| }); | ||
| } | ||
|
|
||
| app.UseCors("DefaultCors"); | ||
|
|
||
| app.MapDefaultEndpoints(); | ||
| app.MapControllers(); | ||
|
|
||
| app.Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "iisSettings": { | ||
| "windowsAuthentication": false, | ||
| "anonymousAuthentication": true, | ||
| "iisExpress": { | ||
| "applicationUrl": "http://localhost:53917", | ||
| "sslPort": 44347 | ||
| } | ||
| }, | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:5022", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:7084;http://localhost:5022", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "IIS Express": { | ||
| "commandName": "IISExpress", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*", | ||
| "ConnectionStrings": { | ||
| "redis": "localhost:6379" | ||
| } | ||
| , | ||
| "CreditGenerator": { | ||
| "CentralBankRate": 16.0 | ||
| }, | ||
| "Cache": { | ||
| "AbsoluteExpirationMinutes": 10 | ||
| }, | ||
| "Cors": { | ||
| "AllowedOrigins": [ "https://localhost:7282" ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\CreditApp.Domain\CreditApp.Domain.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
17 changes: 17 additions & 0 deletions
17
CreditApp.Application/Interfaces/ICreditApplicationGenerator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using CreditApp.Domain.Entities; | ||
|
|
||
| namespace CreditApp.Application.Interfaces; | ||
|
|
||
| /// <summary> | ||
| /// Генерирует объекты заявок на кредит для тестирования, заполнения демонстрационных данных или инициализации. | ||
| /// Реализации должны создавать и возвращать готовый к использованию экземпляр <see cref="CreditApplication"/>. | ||
| /// </summary> | ||
| public interface ICreditApplicationGenerator | ||
| { | ||
| /// <summary> | ||
| /// Асинхронно генерирует заявку на кредит с указанным идентификатором. | ||
| /// </summary> | ||
| /// <param name="id">Идентификатор создаваемой заявки.</param> | ||
| /// <returns>Сгенерированный экземпляр <see cref="CreditApplication"/>.</returns> | ||
| public Task<CreditApplication> GenerateAsync(int id); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using CreditApp.Domain.Entities; | ||
|
|
||
| namespace CreditApp.Application.Interfaces; | ||
|
|
||
| /// <summary> | ||
| /// Сервис для работы с объектами кредитных заявок. | ||
| /// Предоставляет операции получения и управления заявками в приложении. | ||
| /// </summary> | ||
| public interface ICreditService | ||
| { | ||
| /// <summary> | ||
| /// Асинхронно получает заявку на кредит по её идентификатору. | ||
| /// </summary> | ||
| /// <param name="id">Идентификатор заявки.</param> | ||
| /// <param name="ct">Токен отмены для асинхронной операции.</param> | ||
| /// <returns>Экземпляр <see cref="CreditApplication"/>, соответствующий запрошенному идентификатору.</returns> | ||
| public Task<CreditApplication> GetAsync(int id, CancellationToken ct); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace CreditApp.Application.Options; | ||
|
|
||
| public class CacheOptions | ||
| { | ||
| public const string SectionName = "Cache"; | ||
|
|
||
| public int AbsoluteExpirationMinutes { get; set; } = 10; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Референс на проект есть, но код из него нигде не используется