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
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
36 changes: 36 additions & 0 deletions CreditApp.Api/Controllers/CreditController.cs
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);
}
}
21 changes: 21 additions & 0 deletions CreditApp.Api/CreditApp.Api.csproj
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>
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;
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();
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"
}
}
}
}
62 changes: 62 additions & 0 deletions CreditApp.Api/Services/CreditGenerator.cs
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;
}
}
58 changes: 58 additions & 0 deletions CreditApp.Api/Services/CreditService.cs
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;
}
}
16 changes: 16 additions & 0 deletions CreditApp.Api/Services/ICreditService.cs
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Нет саммари

{
/// <summary>
/// Получить кредитную заявку по идентификатору
/// </summary>
public Task<CreditApplication> GetAsync(
int id,
CancellationToken cancellationToken = default);
}
8 changes: 8 additions & 0 deletions CreditApp.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions CreditApp.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
17 changes: 17 additions & 0 deletions CreditApp.AppHost/AppHost.cs
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();

Loading