Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Client.Wasm/Components/StudentCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</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>№53 "Кредитная заявка"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Уваровым Никитой 6513</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://github.com/Rifinn-crypto/cloud-development">Ссылка на форк</Link></UnorderedListItem>
</UnorderedList>
</CardBody>
</Card>
2 changes: 1 addition & 1 deletion Client.Wasm/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
}
},
"AllowedHosts": "*",
"BaseAddress": ""
"BaseAddress": "https://localhost:7184/api/Credit"
}
28 changes: 26 additions & 2 deletions CloudDevelopment.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4
# Visual Studio Version 18
VisualStudioVersion = 18.3.11512.155 d18.3
Comment on lines +3 to +4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мог бы и 10 дотнет с 13 аспаером использовать, раз ты 2026 вижуал студией пользуешься

MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client.Wasm", "Client.Wasm\Client.Wasm.csproj", "{AE7EEA74-2FE0-136F-D797-854FD87E022A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApp.AppHost", "CreditApp.AppHost\CreditApp.AppHost.csproj", "{5432516B-65B7-417A-9D7C-D87F95B880D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApp.ServiceDefaults", "CreditApp.ServiceDefaults\CreditApp.ServiceDefaults.csproj", "{2A1134C7-1080-475D-2A48-9F65479D8C91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApp.Api", "CreditApp.Api\CreditApp.Api.csproj", "{E7D4CA8B-53EA-9676-D96D-BE2F0CB11054}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApp.Domain", "CreditApp.Domain\CreditApp.Domain.csproj", "{B3DC2A03-88A2-468A-BE14-95A1F4DEA883}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +23,22 @@ Global
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.Build.0 = Release|Any CPU
{5432516B-65B7-417A-9D7C-D87F95B880D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5432516B-65B7-417A-9D7C-D87F95B880D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5432516B-65B7-417A-9D7C-D87F95B880D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5432516B-65B7-417A-9D7C-D87F95B880D5}.Release|Any CPU.Build.0 = Release|Any CPU
{2A1134C7-1080-475D-2A48-9F65479D8C91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A1134C7-1080-475D-2A48-9F65479D8C91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A1134C7-1080-475D-2A48-9F65479D8C91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A1134C7-1080-475D-2A48-9F65479D8C91}.Release|Any CPU.Build.0 = Release|Any CPU
{E7D4CA8B-53EA-9676-D96D-BE2F0CB11054}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7D4CA8B-53EA-9676-D96D-BE2F0CB11054}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7D4CA8B-53EA-9676-D96D-BE2F0CB11054}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7D4CA8B-53EA-9676-D96D-BE2F0CB11054}.Release|Any CPU.Build.0 = Release|Any CPU
{B3DC2A03-88A2-468A-BE14-95A1F4DEA883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3DC2A03-88A2-468A-BE14-95A1F4DEA883}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3DC2A03-88A2-468A-BE14-95A1F4DEA883}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3DC2A03-88A2-468A-BE14-95A1F4DEA883}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
108 changes: 108 additions & 0 deletions CreditApp.Api/Controllers/CreditController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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 : ControllerBase
{
private readonly ICreditService _creditService;
private readonly ILogger<CreditController> _logger;

public CreditController(
ICreditService creditService,
ILogger<CreditController> logger)
{
_creditService = creditService;
_logger = logger;
}
Comment on lines +14 to +23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Использовать праймари конструктор

А знаешь, где еще такая же проблема? В #15


/// <summary>
/// Получить кредитную заявку по идентификатору
/// </summary>
[HttpGet("{id:int}")]
[ProducesResponseType(typeof(CreditApplication), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<CreditApplication>> GetCreditApplication(
int id,
CancellationToken cancellationToken)
{
_logger.LogInformation("Getting credit application with Id: {CreditId}", id);

if (id <= 0)
{
_logger.LogWarning("Invalid credit application Id: {CreditId}", id);
return BadRequest("Id must be positive number");
}

try
{
var creditApplication = await _creditService.GetAsync(id, cancellationToken);

_logger.LogInformation(
"Successfully retrieved credit application {CreditId}",
id);

return Ok(creditApplication);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting credit application {CreditId}", id);
return StatusCode(500, "Internal server error");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот код в атрибутах не описан

}
}

/// <summary>
/// Сгенерировать кредитную заявку с указанным seed
/// </summary>
[HttpGet]
[ProducesResponseType(typeof(CreditApplication), StatusCodes.Status200OK)]
public async Task<ActionResult<CreditApplication>> GenerateCredit(
[FromQuery] int? seed,
CancellationToken cancellationToken)
{
_logger.LogInformation("Generating credit application with seed: {Seed}", seed);

var id = new Random().Next(1, 10000);

CreditApplication creditApplication;

if (seed.HasValue)
{
creditApplication = await _creditService.GetAsync(id, seed.Value, cancellationToken);
_logger.LogInformation("Generated credit application with seed {Seed}: {CreditId}", seed, id);
}
else
{
creditApplication = await _creditService.GetAsync(id, cancellationToken);
_logger.LogInformation("Generated random credit application: {CreditId}", id);
}

return Ok(creditApplication);
}

/// <summary>
/// Удалить заявку из кэша
/// </summary>
[HttpDelete("{id:int}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<IActionResult> RemoveCreditApplication(
int id,
CancellationToken cancellationToken)
{
if (id <= 0)
{
return BadRequest("Id must be positive number");
}

await _creditService.RemoveAsync(id, cancellationToken);
return NoContent();
}
}
Comment on lines +61 to +108
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не надо вносить функциональность, которая в софте не требуется

23 changes: 23 additions & 0 deletions CreditApp.Api/CreditApp.Api.csproj
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>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="13.1.1" />
<PackageReference Include="Bogus" Version="35.6.5" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="10.0.3" />
Comment on lines +12 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тебе не нужны эти библиотеки, ты уже пользуешься аспаеровской либой

<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>
6 changes: 6 additions & 0 deletions CreditApp.Api/CreditApp.Api.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@CreditApp.Api_HostAddress = http://localhost:5144

GET {{CreditApp.Api_HostAddress}}/weatherforecast/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Классный маршрут, жаль в твоих контроллерах его нет

Accept: application/json

###
39 changes: 39 additions & 0 deletions CreditApp.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using CreditApp.Api.Services;

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.AddSingleton<ICreditGenerator, CreditGenerator>();
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();
41 changes: 41 additions & 0 deletions CreditApp.Api/Properties/launchSettings.json
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"
}
}
}
}
53 changes: 53 additions & 0 deletions CreditApp.Api/Services/CreditGenerator.cs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выпилить отсюда лишний функционал

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Bogus;
using CreditApp.Domain.Data;

namespace CreditApp.Api.Services;

/// <summary>
/// Генератор тестовых данных для кредитных заявок с использованием библиотеки Bogus.
/// </summary>
public class CreditGenerator : ICreditGenerator
{
private const double CbRate = 16.0;
private readonly string[] _statuses = { "Новая", "В обработке", "Одобрена", "Отклонена" };
private readonly string[] _types = { "Потребительский", "Ипотека", "Автокредит" };

/// <summary>
/// Генерирует кредитную заявку со случайным seed.
/// </summary>
public CreditApplication Generate(int id)
{
return Generate(id, new Random().Next(1, 10000));
}

/// <summary>
/// Генерирует кредитную заявку с указанным seed для воспроизводимости результатов.
/// </summary>
public CreditApplication Generate(int id, int seed)
{
var faker = new Faker<CreditApplication>()
.RuleFor(x => x.Id, id)
.RuleFor(x => x.CreditType, f => f.PickRandom(_types))
.RuleFor(x => x.RequestedAmount, f => Math.Round(f.Random.Decimal(10000, 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(10000, x.RequestedAmount), 2)
: null);

Comment on lines +28 to +48
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вынести в статику, чтобы не создавать каждый запрос

faker.UseSeed(seed);

return faker.Generate();
}
}
Loading