-
Notifications
You must be signed in to change notification settings - Fork 24
Уваров Никита Лаб. 1 Группа 6513 #16
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
Rifinn-crypto
wants to merge
19
commits into
itsecd:main
Choose a base branch
from
Rifinn-crypto: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.
+614
−7
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9e2d2ae
создал необходимые проекты для архитектуры
Rifinn-crypto 0b417eb
Реализация Application
Rifinn-crypto 5fdc84a
Создал Generator
Rifinn-crypto 50fa1f5
Кеширование
Rifinn-crypto 494e372
Попытка выжить в этом жестоком мире
Rifinn-crypto 871d798
Исправления
Rifinn-crypto c8e701b
:)
Rifinn-crypto 5c5cb8e
Перелопатив весь код обнаружил, что надо было исправить всего одну пе…
Rifinn-crypto b0a7b6c
.
Rifinn-crypto 9f3a8f0
.
Rifinn-crypto 9d3bc73
.....
Rifinn-crypto 826be7d
.............
Rifinn-crypto a79906c
.....
Rifinn-crypto ef0152d
Update StudentCard.razor
Rifinn-crypto dee8451
Исправления в коде
Rifinn-crypto 4ec7b8f
Исправления с интеграцией redis, а так же дроп ненужных библиотек
Rifinn-crypto 2e1a15f
Удалил .http
Rifinn-crypto d0bc46f
Добавил недостающие саммари
Rifinn-crypto 2ec7c2c
+1
Rifinn-crypto 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 |
|---|---|---|
|
|
@@ -6,5 +6,5 @@ | |
| } | ||
| }, | ||
| "AllowedHosts": "*", | ||
| "BaseAddress": "" | ||
| "BaseAddress": "https://localhost:7184/api/Credit/" | ||
| } | ||
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,36 @@ | ||
| using CreditApp.Api.Services; | ||
| using CreditApp.Domain.Data; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace CreditApp.Api.Controllers; | ||
|
|
||
| /// <summary> | ||
| /// Контроллер для работы с кредитными заявками | ||
| /// </summary> | ||
| [ApiController] | ||
| [Route("api/[controller]")] | ||
| public class CreditController( | ||
| ICreditService creditService, | ||
| ILogger<CreditController> logger) | ||
| : ControllerBase | ||
| { | ||
| /// <summary> | ||
| /// Получить кредитную заявку по идентификатору | ||
| /// </summary> | ||
| [HttpGet] | ||
| [ProducesResponseType(typeof(CreditApplication), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
| public async Task<ActionResult<CreditApplication>> Get( | ||
| int id, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| if (id <= 0) | ||
| return BadRequest("Id must be positive number"); | ||
|
|
||
| logger.LogInformation("Request credit application {CreditId}", id); | ||
|
|
||
| var result = await creditService.GetAsync(id, cancellationToken); | ||
|
|
||
| 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,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="13.1.1" /> | ||
| <PackageReference Include="Bogus" Version="35.6.5" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Client.Wasm\Client.Wasm.csproj" /> | ||
| <ProjectReference Include="..\CreditApp.Domain\CreditApp.Domain.csproj" /> | ||
| <ProjectReference Include="..\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,39 @@ | ||
| using CreditApp.Api.Services; | ||
| using CreditApp.ServiceDefaults; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
| builder.AddRedisDistributedCache("redis"); | ||
|
|
||
| builder.Services.AddControllers(); | ||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services.AddSwaggerGen(); | ||
|
|
||
| builder.Services.AddCors(options => | ||
| { | ||
| options.AddPolicy("wasm", policy => | ||
| { | ||
| policy.AllowAnyOrigin() | ||
| .WithMethods("GET") | ||
| .WithHeaders("Content-Type"); | ||
| }); | ||
| }); | ||
|
|
||
| builder.Services.AddScoped<ICreditService, CreditService>(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
| app.UseSwaggerUI(); | ||
| } | ||
|
|
||
| app.MapDefaultEndpoints(); | ||
| app.UseHttpsRedirection(); | ||
| app.UseCors("wasm"); | ||
| app.UseAuthorization(); | ||
| 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,41 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "iisSettings": { | ||
| "windowsAuthentication": false, | ||
| "anonymousAuthentication": true, | ||
| "iisExpress": { | ||
| "applicationUrl": "http://localhost:50546", | ||
| "sslPort": 44330 | ||
| } | ||
| }, | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "applicationUrl": "http://localhost:5144", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "applicationUrl": "https://localhost:7184;http://localhost:5144", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "IIS Express": { | ||
| "commandName": "IISExpress", | ||
| "launchBrowser": true, | ||
| "launchUrl": "swagger", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
alxmcs marked this conversation as resolved.
Show resolved
Hide resolved
|
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,62 @@ | ||
| using Bogus; | ||
| using CreditApp.Domain.Data; | ||
|
|
||
| namespace CreditApp.Api.Services; | ||
|
|
||
| /// <summary> | ||
| /// Генератор тестовых данных для кредитных заявок. | ||
| /// </summary> | ||
| public static class CreditGenerator | ||
| { | ||
| private const double CbRate = 16.0; | ||
|
|
||
| private static readonly string[] _statuses = | ||
| { | ||
| "Новая", | ||
| "В обработке", | ||
| "Одобрена", | ||
| "Отклонена" | ||
| }; | ||
|
|
||
| private static readonly string[] _types = | ||
| { | ||
| "Потребительский", | ||
| "Ипотека", | ||
| "Автокредит" | ||
| }; | ||
|
|
||
| private static readonly Faker<CreditApplication> _faker = | ||
| new Faker<CreditApplication>() | ||
| .RuleFor(x => x.Id, f => f.IndexFaker) | ||
| .RuleFor(x => x.CreditType, f => f.PickRandom(_types)) | ||
| .RuleFor(x => x.RequestedAmount, | ||
| f => Math.Round(f.Random.Decimal(10_000, 5_000_000), 2)) | ||
| .RuleFor(x => x.TermMonths, | ||
| f => f.Random.Int(6, 360)) | ||
| .RuleFor(x => x.InterestRate, | ||
| f => Math.Round(f.Random.Double(CbRate, CbRate + 5), 2)) | ||
| .RuleFor(x => x.ApplicationDate, | ||
| f => DateOnly.FromDateTime(f.Date.Past(2))) | ||
| .RuleFor(x => x.HasInsurance, | ||
| f => f.Random.Bool()) | ||
| .RuleFor(x => x.Status, | ||
| f => f.PickRandom(_statuses)) | ||
| .RuleFor(x => x.DecisionDate, (f, x) => | ||
| x.Status is "Одобрена" or "Отклонена" | ||
| ? DateOnly.FromDateTime( | ||
| f.Date.Between( | ||
| x.ApplicationDate.ToDateTime(TimeOnly.MinValue), | ||
| DateTime.Now)) | ||
| : null) | ||
| .RuleFor(x => x.ApprovedAmount, (f, x) => | ||
| x.Status == "Одобрена" | ||
| ? Math.Round(f.Random.Decimal(10_000, x.RequestedAmount), 2) | ||
| : null); | ||
|
|
||
| public static CreditApplication Generate(int id) | ||
| { | ||
| var result = _faker.Generate(); | ||
| result.Id = id; | ||
| return 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,58 @@ | ||
| using System.Text.Json; | ||
| using CreditApp.Domain.Data; | ||
| using Microsoft.Extensions.Caching.Distributed; | ||
|
|
||
| namespace CreditApp.Api.Services; | ||
|
|
||
| /// <summary> | ||
| /// Сервис для работы с кредитными заявками. | ||
| /// </summary> | ||
| public class CreditService( | ||
| IDistributedCache cache, | ||
| ILogger<CreditService> logger) | ||
| : ICreditService | ||
| { | ||
| private const string CachePrefix = "credit:"; | ||
|
|
||
| public async Task<CreditApplication> GetAsync( | ||
| int id, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var key = $"{CachePrefix}{id}"; | ||
|
|
||
| var cached = await cache.GetStringAsync(key, cancellationToken); | ||
|
|
||
| if (cached is not null) | ||
| { | ||
| logger.LogInformation( | ||
| "Cache HIT for credit application {CreditId}", | ||
| id); | ||
|
|
||
| return JsonSerializer.Deserialize<CreditApplication>(cached)!; | ||
| } | ||
|
|
||
| logger.LogInformation( | ||
| "Cache MISS for credit application {CreditId}", | ||
| id); | ||
|
|
||
| var result = CreditGenerator.Generate(id); | ||
|
|
||
| var serialized = JsonSerializer.Serialize(result); | ||
|
|
||
| var options = new DistributedCacheEntryOptions | ||
| { | ||
| AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) | ||
| }; | ||
|
|
||
| await cache.SetStringAsync(key, serialized, options, cancellationToken); | ||
|
|
||
| logger.LogInformation( | ||
| "Generated credit application {CreditId}. Type: {Type}, Amount: {Amount}, Status: {Status}", | ||
| result.Id, | ||
| result.CreditType, | ||
| result.RequestedAmount, | ||
| result.Status); | ||
|
|
||
| return result; | ||
| } | ||
| } |
alxmcs marked this conversation as resolved.
Show resolved
Hide resolved
|
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,16 @@ | ||
| using CreditApp.Domain.Data; | ||
|
|
||
| namespace CreditApp.Api.Services; | ||
|
|
||
| /// <summary> | ||
| /// Интерфейс сервиса для работы с кредитными заявками | ||
| /// </summary> | ||
| public interface ICreditService | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нет саммари |
||
| { | ||
| /// <summary> | ||
| /// Получить кредитную заявку по идентификатору | ||
| /// </summary> | ||
| public Task<CreditApplication> GetAsync( | ||
| int id, | ||
| CancellationToken cancellationToken = default); | ||
| } | ||
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,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
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 Google.Protobuf.WellKnownTypes; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var redis = builder.AddRedis("redis") | ||
| .WithRedisCommander(); | ||
|
|
||
| var api = builder.AddProject<Projects.CreditApp_Api>("api") | ||
| .WithReference(redis) | ||
| .WaitFor(redis); | ||
|
|
||
| builder.AddProject<Projects.Client_Wasm>("client") | ||
| .WithReference(api) | ||
| .WaitFor(api); | ||
|
|
||
| builder.Build().Run(); | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.