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
108 changes: 108 additions & 0 deletions Client.Wasm/Components/CreditApplicationCard.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
@inject IConfiguration Configuration
@inject HttpClient Client

<CardDeck>
<Card>
<CardHeader>
<Heading Size="HeadingSize.Is5"><Icon Name="IconName.User" /> Кредитная заявка</Heading>
</CardHeader>
<CardBody>
<Row>
<Column ColumnSize="ColumnSize.Is4">
<Text>Идентификатор заявки:</Text>
</Column>
<Column ColumnSize="ColumnSize.Is4">
<NumericEdit TValue="int" @bind-Value="@Id"/>
</Column>
<Column ColumnSize="ColumnSize.Is4">
<Button Clicked="Request" Color="Color.Primary">Запросить <Icon Name="IconName.ArrowRight" /></Button>
</Column>
</Row>
</CardBody>
</Card>

<Card Margin="Margin.Is3.OnY">
<CardHeader>
<Heading Size="HeadingSize.Is5"><Icon Name="IconName.Table" /> Характеристики</Heading>
</CardHeader>
<CardBody>
@if (Application is null)
{
<Alert Color="Color.Light">Нет данных. Укажите идентификатор и запросите заявку.</Alert>
}
else
{
<Table Bordered>
<TableHeader ThemeContrast="ThemeContrast.Light">
<TableRow>
<TableHeaderCell>#</TableHeaderCell>
<TableHeaderCell>Характеристика</TableHeaderCell>
<TableHeaderCell>Значение</TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
@Row(1, "Идентификатор в системе", Get("id"))
@Row(2, "Тип кредита", Get("creditType"))
@Row(3, "Запрашиваемая сумма", GetAmount("requestedAmount"))
@Row(4, "Срок в месяцах", Get("termMonths"))
@Row(5, "Процентная ставка (%)", GetRate("interestRate"))
@Row(6, "Дата подачи", Get("applicationDate"))
@Row(7, "Необходимость страховки", GetBool("requiresInsurance"))
@Row(8, "Статус заявки", Get("status"))
@Row(9, "Дата решения", Get("decisionDate"))
@Row(10, "Одобренная сумма", GetAmount("approvedAmount"))
</TableBody>
</Table>
}
</CardBody>
</Card>
</CardDeck>

@code {
private JsonObject? Application { get; set; }
private int Id { get; set; }

private async Task Request()
{
var baseAddress = Configuration["BaseAddress"] ?? throw new KeyNotFoundException("Конфигурация клиента не содержит параметра BaseAddress");
Application = await Client.GetFromJsonAsync<JsonObject>($"{baseAddress}?id={Id}", new JsonSerializerOptions { });
StateHasChanged();
}

private RenderFragment Row(int idx, string name, string? value) => builder =>
{
builder.OpenComponent<TableRow>(0);
builder.AddAttribute(1, "ChildContent", (RenderFragment)(rowBuilder =>
{
rowBuilder.OpenComponent<TableRowCell>(0);
rowBuilder.AddAttribute(1, "ChildContent", (RenderFragment)(c => c.AddContent(0, idx)));
rowBuilder.CloseComponent();

rowBuilder.OpenComponent<TableRowCell>(2);
rowBuilder.AddAttribute(3, "ChildContent", (RenderFragment)(c => c.AddContent(0, name)));
rowBuilder.CloseComponent();

rowBuilder.OpenComponent<TableRowCell>(4);
rowBuilder.AddAttribute(5, "ChildContent", (RenderFragment)(c => c.AddContent(0, value ?? "—")));
rowBuilder.CloseComponent();
}));
builder.CloseComponent();
};

private string? Get(string key) => Application?[key]?.ToString();
private string? GetBool(string key)
{
var s = Application?[key]?.ToString();
return s is null ? null : (bool.TryParse(s, out var b) ? (b ? "Да" : "Нет") : s);
}
private string? GetAmount(string key)
{
var s = Application?[key]?.ToString();
return s is null ? null : (decimal.TryParse(s, out var d) ? d.ToString("F2") : s);
}
private string? GetRate(string key)
{
var s = Application?[key]?.ToString();
return s is null ? null : (double.TryParse(s, out var d) ? d.ToString("F2") : s);
}
}
74 changes: 0 additions & 74 deletions Client.Wasm/Components/DataCard.razor

This file was deleted.

9 changes: 4 additions & 5 deletions Client.Wasm/Components/StudentCard.razor
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Card>
<Card>
<CardHeader>
<Heading Size="HeadingSize.Is5"><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>
Copy link

Choose a reason for hiding this comment

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

Потерялась ссылка на форк

<UnorderedListItem>Номер <Strong>№1 "Кэширование"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№21 "Кредитная заявка"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Гусаровой Маргаритой 6512</Strong> </UnorderedListItem>
</UnorderedList>
</CardBody>
</Card>
4 changes: 2 additions & 2 deletions Client.Wasm/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/"
@page "/"

<DataCard/>
<CreditApplicationCard/>
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": "http://localhost:5179/api/creditapplication"
}
27 changes: 25 additions & 2 deletions CloudDevelopment.sln
Copy link

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
@@ -1,10 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4
VisualStudioVersion = 17.13.35931.197
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}") = "ProjectApp.Api", "ProjectApp.Api\ProjectApp.Api.csproj", "{E7D4CA8B-53EA-9676-D96D-BE2F0CB11054}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectApp.Domain", "ProjectApp.Domain\ProjectApp.Domain.csproj", "{CC5A9873-4CC3-4B71-83AF-E4FD09F7B1AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectApp.ServiceDefaults", "ProjectApp.ServiceDefaults\ProjectApp.ServiceDefaults.csproj", "{B2C3D4E5-F6A7-8901-BCDE-F12345678901}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectApp.AppHost", "ProjectApp.AppHost\ProjectApp.AppHost.csproj", "{2A5FB573-9376-4FEB-9289-A8387F435C13}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +22,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
{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
{CC5A9873-4CC3-4B71-83AF-E4FD09F7B1AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC5A9873-4CC3-4B71-83AF-E4FD09F7B1AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC5A9873-4CC3-4B71-83AF-E4FD09F7B1AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC5A9873-4CC3-4B71-83AF-E4FD09F7B1AD}.Release|Any CPU.Build.0 = Release|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.Build.0 = Release|Any CPU
{2A5FB573-9376-4FEB-9289-A8387F435C13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A5FB573-9376-4FEB-9289-A8387F435C13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A5FB573-9376-4FEB-9289-A8387F435C13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A5FB573-9376-4FEB-9289-A8387F435C13}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
21 changes: 21 additions & 0 deletions ProjectApp.Api/Controllers/CreditApplicationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using ProjectApp.Api.Services.CreditApplicationGeneratorService;
using ProjectApp.Domain.Entities;

namespace ProjectApp.Api.Controllers;

[Route("api/[controller]")]
[ApiController]
public class CreditApplicationController(ICreditApplicationGeneratorService generatorService, ILogger<CreditApplicationController> logger) : ControllerBase
Copy link

Choose a reason for hiding this comment

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

Добавить атрибут ProducesResponseType

{
/// <summary>
/// Получить кредитную заявку по ID, если не найдена в кэше — сгенерировать новую
/// </summary>
[HttpGet]
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 generatorService.GetByIdAsync(id, cancellationToken);
return Ok(application);
}
}
59 changes: 59 additions & 0 deletions ProjectApp.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using ProjectApp.Api.Services.CreditApplicationGeneratorService;
using ProjectApp.ServiceDefaults;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.AddRedisDistributedCache("cache");

builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins("http://localhost:5127")
.WithMethods("GET")
.WithHeaders("Content-Type");
});
});

builder.Services.AddSingleton<CreditApplicationGenerator>();
builder.Services.AddScoped<ICreditApplicationGeneratorService, CreditApplicationGeneratorService>();

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Microsoft.OpenApi.OpenApiInfo
{
Title = "Credit Application 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.UseHttpsRedirection();
app.UseCors();
app.MapControllers();
app.MapDefaultEndpoints();

app.Run();
23 changes: 23 additions & 0 deletions ProjectApp.Api/ProjectApp.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>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.5.2" />
<PackageReference Include="Bogus" Version="35.6.5" />
<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>
Loading
Loading