-
Notifications
You must be signed in to change notification settings - Fork 52
Панкеев Глеб Лаб. 2 Группа 6512 #97
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
Pancake2021
wants to merge
16
commits into
itsecd:main
Choose a base branch
from
Pancake2021:lab2
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
16 commits
Select commit
Hold shift + click to select a range
ed206e6
revert: откат лаб.1 — был выбран неверный вариант задания. Переделыва…
Pancake2021 22144d2
feat(domain): добавлена модель кредитной заявки и логика данных
Pancake2021 e63c60a
infra: настройка .NET Aspire: добавлен Redis и LocalStack (SQS) по за…
Pancake2021 e69bfa2
chore: обновление Solution файла и документации под 30 вариант
Pancake2021 957eb65
Initial commit: Variant 30 Credit Application with SQS and Localstack
Pancake2021 cd7d6dc
Merge remote with local changes (Variant 30 Credit Application)
Pancake2021 efd1035
Доработка техдолга по логике сервиса по заданию 1 лабораторной
Pancake2021 9b5b424
ЛР2: добавлен API Gateway на Ocelot и Query Based балансировка
Pancake2021 ef49e0e
Рефактор генерации заявок: опции, валидация инвариантов и тесты
Pancake2021 bbb6195
Починил конфликт портов в AppHost для реплик
Pancake2021 2b8b0a5
Убрал localstack и вернул нормальный Redis-кэш
Pancake2021 571d71b
Убрал дублирующий контур CreditSystem, оставил только ProjectApp
Pancake2021 949ec8b
Добавил summary и тест на стабильный кэш по id
Pancake2021 9229ae8
Подровнял версию пакета Redis-кэша
Pancake2021 7c2a4e8
Привел API и кэш-сервис к замечаниям ревью
Pancake2021 a500e7b
Причесал AppHost/Gateway/Validator по комментариям ревью
Pancake2021 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| <Card> | ||
| <CardHeader> | ||
| <Heading Size="HeadingSize.Is5"><Icon Name="IconName.User" /> Лабораторная работа</Heading> | ||
| <Heading Size="HeadingSize.Is5"><Blazorise.Icons.FontAwesome.Icon Name="IconName.User" /> Лабораторная работа</Heading> | ||
| </CardHeader> | ||
| <CardBody> | ||
| <UnorderedList Unstyled> | ||
| <UnorderedListItem>Номер <Strong>№X "Название лабораторной"</Strong></UnorderedListItem> | ||
| <UnorderedListItem>Вариант <Strong>№Х "Название варианта"</Strong></UnorderedListItem> | ||
| <UnorderedListItem>Выполнена <Strong>Фамилией Именем 65ХХ</Strong> </UnorderedListItem> | ||
| <UnorderedListItem><Link To="https://puginarug.com/">Ссылка на форк</Link></UnorderedListItem> | ||
| <UnorderedListItem>Номер <Strong>№1 "Кэширование"</Strong></UnorderedListItem> | ||
| <UnorderedListItem>Вариант <Strong>№30 "Кредитная заявка"</Strong></UnorderedListItem> | ||
| <UnorderedListItem>Выполнена <Strong>Панкеевым Глебом 6512</Strong> </UnorderedListItem> | ||
| <UnorderedListItem><Link To="https://github.com/Pancake2021/cloud-development/tree/lab1/pankeev-gleb">Ссылка на мой форк</Link></UnorderedListItem> | ||
| </UnorderedList> | ||
| </CardBody> | ||
| </Card> |
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 |
|---|---|---|
|
|
@@ -6,5 +6,5 @@ | |
| } | ||
| }, | ||
| "AllowedHosts": "*", | ||
| "BaseAddress": "" | ||
| "BaseAddress": "http://localhost:7000/api/creditapplication" | ||
| } | ||
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,27 @@ | ||
| using ProjectApp.Api.Services.CreditApplicationService; | ||
| using ProjectApp.Domain.Entities; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace ProjectApp.Api.Controllers; | ||
|
|
||
| [Route("api/[controller]")] | ||
| [ApiController] | ||
| public class CreditApplicationController(ICreditApplicationService creditService, ILogger<CreditApplicationController> logger) : ControllerBase | ||
| { | ||
| /// <summary> | ||
| /// Получить кредитную заявку по ID, если не найдена в кэше — сгенерировать новую | ||
| /// </summary> | ||
| /// <param name="id">ID кредитной заявки</param> | ||
| /// <param name="cancellationToken">Токен отмены операции</param> | ||
| /// <returns>Кредитная заявка</returns> | ||
| [HttpGet] | ||
| [ProducesResponseType(typeof(CreditApplication), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<CreditApplication>> GetById([FromQuery] int id, CancellationToken cancellationToken) | ||
| { | ||
| logger.LogInformation("Received request to retrieve/generate credit application {Id}", id); | ||
|
|
||
| var application = await creditService.GetByIdAsync(id, cancellationToken); | ||
|
|
||
| return Ok(application); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
ProjectApp.Api/Options/CreditApplicationGenerationOptions.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,32 @@ | ||
| namespace ProjectApp.Api.Options; | ||
|
|
||
| /// <summary> | ||
| /// Настройки генерации кредитных заявок. | ||
| /// </summary> | ||
| public class CreditApplicationGenerationOptions | ||
| { | ||
| /// <summary>Имя секции в appsettings.</summary> | ||
| public const string SectionName = "CreditApplicationSettings"; | ||
|
|
||
| /// <summary>Минимальная допустимая ставка (ключевая ставка ЦБ).</summary> | ||
| public double CentralBankKeyRate { get; set; } = 21.0; | ||
| /// <summary>Минимальная запрашиваемая сумма.</summary> | ||
| public decimal MinRequestedAmount { get; set; } = 50_000m; | ||
| /// <summary>Максимальная запрашиваемая сумма.</summary> | ||
| public decimal MaxRequestedAmount { get; set; } = 5_000_000m; | ||
| /// <summary>Минимальный срок кредита.</summary> | ||
| public int MinTermMonths { get; set; } = 6; | ||
| /// <summary>Максимальный срок кредита.</summary> | ||
| public int MaxTermMonths { get; set; } = 360; | ||
| /// <summary>Максимальный возраст даты подачи заявки в годах.</summary> | ||
| public int MaxApplicationAgeYears { get; set; } = 2; | ||
| /// <summary>Справочник доступных типов кредита.</summary> | ||
| public string[] CreditTypes { get; set; } = | ||
| [ | ||
| "Потребительский", | ||
| "Ипотека", | ||
| "Автокредит", | ||
| "Рефинансирование", | ||
| "Кредитная карта" | ||
| ]; | ||
| } |
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,64 @@ | ||
| using ProjectApp.Api.Services.CreditApplicationService; | ||
| using ProjectApp.Api.Options; | ||
| using ProjectApp.ServiceDefaults; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
| builder.Services.AddStackExchangeRedisCache(options => | ||
| { | ||
| options.Configuration = builder.Configuration.GetConnectionString("cache"); | ||
| }); | ||
|
|
||
| builder.Services.AddCors(options => | ||
| { | ||
| options.AddDefaultPolicy(policy => | ||
| { | ||
| policy.AllowAnyOrigin() | ||
| .WithMethods("GET") | ||
| .WithHeaders("Content-Type"); | ||
| }); | ||
| }); | ||
|
|
||
| builder.Services.Configure<CreditApplicationGenerationOptions>( | ||
| builder.Configuration.GetSection(CreditApplicationGenerationOptions.SectionName)); | ||
| builder.Services.AddSingleton<CreditApplicationGenerator>(); | ||
| builder.Services.AddScoped<ICreditApplicationService, CreditApplicationService>(); | ||
|
|
||
| builder.Services.AddControllers(); | ||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services.AddSwaggerGen(options => | ||
| { | ||
| options.SwaggerDoc("v1", new Microsoft.OpenApi.OpenApiInfo | ||
| { | ||
| Title = "Credit Application Generator API" | ||
| }); | ||
|
|
||
| var xmlFilename = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml"; | ||
| var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFilename); | ||
| if (File.Exists(xmlPath)) | ||
| { | ||
| options.IncludeXmlComments(xmlPath); | ||
| } | ||
|
|
||
| var domainXmlPath = Path.Combine(AppContext.BaseDirectory, "ProjectApp.Domain.xml"); | ||
| if (File.Exists(domainXmlPath)) | ||
| { | ||
| options.IncludeXmlComments(domainXmlPath); | ||
| } | ||
| }); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
| app.UseSwaggerUI(); | ||
| } | ||
|
|
||
| app.UseCors(); | ||
| app.UseHttpsRedirection(); | ||
| app.MapControllers(); | ||
| app.MapDefaultEndpoints(); | ||
|
|
||
| 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,23 @@ | ||
| <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="Bogus" Version="35.6.5" /> | ||
| <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.10" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.24" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.4" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ProjectApp.Domain\ProjectApp.Domain.csproj" /> | ||
| <ProjectReference Include="..\ProjectApp.ServiceDefaults\ProjectApp.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,41 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "iisSettings": { | ||
| "windowsAuthentication": false, | ||
| "anonymousAuthentication": true, | ||
| "iisExpress": { | ||
| "applicationUrl": "http://localhost:46825", | ||
| "sslPort": 44333 | ||
| } | ||
| }, | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "applicationUrl": "http://localhost:5179", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "applicationUrl": "https://localhost:7170;http://localhost:5179", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "IIS Express": { | ||
| "commandName": "IISExpress", | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
ProjectApp.Api/Services/CreditApplicationService/CreditApplicationGenerator.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,82 @@ | ||
| using Bogus; | ||
| using Microsoft.Extensions.Options; | ||
| using ProjectApp.Api.Options; | ||
| using ProjectApp.Domain.Entities; | ||
|
|
||
| namespace ProjectApp.Api.Services.CreditApplicationService; | ||
|
|
||
| /// <summary> | ||
| /// Генератор кредитных заявок на основе Bogus. | ||
| /// </summary> | ||
| public class CreditApplicationGenerator | ||
| { | ||
| private static readonly string[] NonTerminalStatuses = ["Новая", "В обработке"]; | ||
| private static readonly string[] TerminalStatuses = ["Одобрена", "Отклонена"]; | ||
|
|
||
| private readonly Faker<CreditApplication> _faker; | ||
| private readonly CreditApplicationGenerationOptions _options; | ||
|
|
||
| public CreditApplicationGenerator(IOptions<CreditApplicationGenerationOptions> options) | ||
| { | ||
| _options = options.Value; | ||
|
|
||
| var minApplicationDate = DateTime.Today.AddYears(-_options.MaxApplicationAgeYears); | ||
| var maxApplicationDate = DateTime.Today.AddDays(-1); | ||
|
|
||
| _faker = new Faker<CreditApplication>("ru") | ||
| .RuleFor(c => c.CreditType, f => f.PickRandom(_options.CreditTypes)) | ||
| .RuleFor(c => c.RequestedAmount, f => Math.Round( | ||
| f.Finance.Amount(_options.MinRequestedAmount, _options.MaxRequestedAmount), 2)) | ||
| .RuleFor(c => c.TermMonths, f => f.Random.Int(_options.MinTermMonths, _options.MaxTermMonths)) | ||
| .RuleFor(c => c.InterestRate, f => | ||
| { | ||
| var generatedRate = f.Random.Double(_options.CentralBankKeyRate, _options.CentralBankKeyRate + 12.0); | ||
| return Math.Round(generatedRate, 2); | ||
| }) | ||
| .RuleFor(c => c.ApplicationDate, f => | ||
| { | ||
| var date = f.Date.Between(minApplicationDate, maxApplicationDate); | ||
| return DateOnly.FromDateTime(date); | ||
| }) | ||
| .RuleFor(c => c.RequiresInsurance, f => f.Random.Bool()) | ||
| .RuleFor(c => c.Status, f => | ||
| { | ||
| var isTerminal = f.Random.Bool(0.7f); | ||
| return isTerminal ? f.PickRandom(TerminalStatuses) : f.PickRandom(NonTerminalStatuses); | ||
| }) | ||
| .RuleFor(c => c.DecisionDate, (f, c) => | ||
| { | ||
| if (c.Status is not ("Одобрена" or "Отклонена")) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var minDate = c.ApplicationDate.ToDateTime(TimeOnly.MinValue).AddDays(1); | ||
| var maxDate = DateTime.Today; | ||
|
|
||
| if (minDate > maxDate) | ||
| { | ||
| return DateOnly.FromDateTime(minDate); | ||
| } | ||
|
|
||
| var endDate = f.Date.Between(minDate, maxDate); | ||
| return DateOnly.FromDateTime(endDate); | ||
| }) | ||
| .RuleFor(c => c.ApprovedAmount, (f, c) => | ||
| { | ||
| if (c.Status != "Одобрена") | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var approved = f.Finance.Amount(_options.MinRequestedAmount, c.RequestedAmount); | ||
| return Math.Round(approved, 2); | ||
| }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Генерирует одну заявку. | ||
| /// </summary> | ||
| /// <returns>Сгенерированная кредитная заявка.</returns> | ||
| public CreditApplication Generate() => _faker.Generate(); | ||
| } |
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.
Добавить атрибут
ProducesResponseType