Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
0a769f7
feat: добавил ServiceDefaults
Donistr Feb 22, 2026
69e6dba
feat: добавил сервис Generator
Donistr Feb 22, 2026
9b66e86
fix: добавил файлы, которые забыл закоммитить
Donistr Feb 22, 2026
4eaaee0
feat: добавил AppHost
Donistr Feb 22, 2026
52dc141
fix: поправил в клиенте карточку студента и сделал чтобы url получени…
Donistr Feb 22, 2026
70c225b
style: запустил code cleanup во всём проекте
Donistr Feb 22, 2026
ae35609
refactor: вынес faker в private static readonly поле
Donistr Feb 22, 2026
8724252
style: сделал revert коммита с клинапом
Donistr Feb 25, 2026
6cab0cf
fix: убрал serilog, чтобы пофиксить структурное логирование
Donistr Feb 25, 2026
c6f84a5
refactor: убрал метод CreateCahcheOptions
Donistr Feb 25, 2026
4c1f771
refactor: улучшил логирование сгенерированного объекта ResidentialBui…
Donistr Feb 25, 2026
51fac4e
fix: поправил cors
Donistr Feb 25, 2026
38f2929
refactor: убрал объявление бесполезной переменной generator
Donistr Feb 25, 2026
fbc4abf
reafactor: исправил порядок импортов
Donistr Feb 26, 2026
7712171
refactor: добавил в контроллер атрибуты с возвращаемыми типами
Donistr Feb 26, 2026
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
2 changes: 1 addition & 1 deletion Client.Wasm/Components/DataCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
private async Task RequestNewData()
{
var baseAddress = Configuration["BaseAddress"] ?? throw new KeyNotFoundException("Конфигурация клиента не содержит параметра BaseAddress");
Value = await Client.GetFromJsonAsync<JsonObject>($"{baseAddress}?id={Id}", new JsonSerializerOptions { });
Value = await Client.GetFromJsonAsync<JsonObject>($"{baseAddress}/{Id}", new JsonSerializerOptions { });
StateHasChanged();
}
}
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>№38 "Объект жилого строительства"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Елагиным Денисом 6513</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://github.com/Donistr/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": "http://localhost:5204/api/residential-building"
}
18 changes: 18 additions & 0 deletions CloudDevelopment.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ VisualStudioVersion = 17.14.36811.4
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}") = "ResidentialBuilding.Generator", "ResidentialBuilding.Generator\ResidentialBuilding.Generator.csproj", "{4C3748F7-BE7B-4C97-A656-D0D467E4BC5D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResidentialBuilding.AppHost", "ResidentialBuilding.AppHost\ResidentialBuilding.AppHost.csproj", "{248C1F9B-F012-4C7C-A458-4E2D0F918A70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResidentialBuilding.ServiceDefaults", "ResidentialBuilding.ServiceDefaults\ResidentialBuilding.ServiceDefaults.csproj", "{3AEE6EF1-603F-411D-89C2-5CE78EBCAEBA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +21,18 @@ 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
{4C3748F7-BE7B-4C97-A656-D0D467E4BC5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C3748F7-BE7B-4C97-A656-D0D467E4BC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C3748F7-BE7B-4C97-A656-D0D467E4BC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C3748F7-BE7B-4C97-A656-D0D467E4BC5D}.Release|Any CPU.Build.0 = Release|Any CPU
{248C1F9B-F012-4C7C-A458-4E2D0F918A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{248C1F9B-F012-4C7C-A458-4E2D0F918A70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{248C1F9B-F012-4C7C-A458-4E2D0F918A70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{248C1F9B-F012-4C7C-A458-4E2D0F918A70}.Release|Any CPU.Build.0 = Release|Any CPU
{3AEE6EF1-603F-411D-89C2-5CE78EBCAEBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AEE6EF1-603F-411D-89C2-5CE78EBCAEBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AEE6EF1-603F-411D-89C2-5CE78EBCAEBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AEE6EF1-603F-411D-89C2-5CE78EBCAEBA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 14 additions & 0 deletions ResidentialBuilding.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("residential-building-cache")
.WithRedisInsight(containerName: "residential-building-insight");

var generator = builder.AddProject<Projects.ResidentialBuilding_Generator>("generator")
.WithReference(cache, "residential-building-cache")
.WaitFor(cache);

builder.AddProject<Projects.Client_Wasm>("client")
.WithReference(generator)
.WaitFor(generator);

builder.Build().Run();
29 changes: 29 additions & 0 deletions ResidentialBuilding.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17129;http://localhost:15221",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21101",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22255"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15221",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19083",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20274"
}
}
}
}
23 changes: 23 additions & 0 deletions ResidentialBuilding.AppHost/ResidentialBuilding.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.5.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>ed7e1e47-dc98-4419-8424-85412466aa9b</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="9.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ResidentialBuilding.Generator\ResidentialBuilding.Generator.csproj" />
<ProjectReference Include="..\Client.Wasm\Client.Wasm.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions ResidentialBuilding.AppHost/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 ResidentialBuilding.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Generator.DTO;
using Generator.Service;
using Microsoft.AspNetCore.Mvc;

namespace Generator.Controller;

/// <summary>
/// Контроллер для объектов жилого строительства.
/// </summary>
[Route("api/residential-building")]
[ApiController]
public class ResidentialBuildingController(ILogger<ResidentialBuildingController> logger, IResidentialBuildingService residentialBuildingService) : ControllerBase
{
/// <summary>
/// Получение объекта жилого строительства по id.
/// </summary>
/// <param name="id">Идентификатор объекта жилого строительства.</param>
/// <returns>DTO объекта жилого строительства.</returns>
/// <response code="200">Успешное получение объекта.</response>
/// <response code="400">Некорректный id.</response>
[HttpGet("{id:int}")]
[ProducesResponseType<ResidentialBuildingDto>(StatusCodes.Status200OK)]
[ProducesResponseType<string>(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ResidentialBuildingDto>> GetResidentialBuilding(int id)
{
if (id <= 0)
{
return BadRequest("id must be >= 0");
}

logger.LogInformation("Getting residential building with Id={id}.", id);
var result = await residentialBuildingService.GetByIdAsync(id);
logger.LogInformation("Residential building with Id={id} successfully received.", id);

return Ok(result);
}
}
57 changes: 57 additions & 0 deletions ResidentialBuilding.Generator/DTO/ResidentialBuildingDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Generator.DTO;

/// <summary>
/// DTO объекта жилого строительства
/// </summary>
public class ResidentialBuildingDto
{
/// <summary>
/// Идентификатор в системе
/// </summary>
public int Id { get; set; }

/// <summary>
/// Адрес
/// </summary>
public string Address { get; set; } = string.Empty;

/// <summary>
/// Тип недвижимости
/// </summary>
public string PropertyType { get; set; } = string.Empty;

/// <summary>
/// Год постройки
/// </summary>
public int BuildYear { get; set; }

/// <summary>
/// Общая площадь
/// </summary>
public double TotalArea { get; set; }

/// <summary>
/// Жилая площадь
/// </summary>
public double LivingArea { get; set; }

/// <summary>
/// Этаж
/// </summary>
public int? Floor { get; set; }

/// <summary>
/// Этажность
/// </summary>
public int TotalFloors { get; set; }

/// <summary>
/// Кадастровый номер
/// </summary>
public string CadastralNumber { get; set; } = string.Empty;

/// <summary>
/// Кадастровая стоимость
/// </summary>
public decimal CadastralValue { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Bogus;
using Generator.DTO;

namespace Generator.Generator;

/// <summary>
/// Генератор объектов жилого строительства на основе Bogus
/// </summary>
public class ResidentialBuildingGenerator(ILogger<ResidentialBuildingGenerator> logger)
{
private const int MinBuildYear = 1900;

private const double MinTotalArea = 10.0;

private const double MaxTotalArea = 1000.0;

private const double MinLivingAreaPartOfTotalArea = 0.5;

private const double MaxLivingAreaPartOfTotalArea = 0.85;

private const int MinTotalFloors = 1;

private const int MaxTotalFloors = 100;

private const double MinPricePerM2 = 35;

private const double MaxPricePerM2 = 200;

private static readonly string[] _propertyTypes =
[
"Квартира",
"ИЖС",
"Апартаменты",
"Офис"
];

private static readonly Faker<ResidentialBuildingDto> _faker = new Faker<ResidentialBuildingDto>("ru")
.RuleFor(x => x.Address, f => f.Address.FullAddress())
.RuleFor(x => x.PropertyType, f => f.PickRandom(_propertyTypes))
.RuleFor(x => x.BuildYear, f => f.Random.Int(MinBuildYear, DateTime.Today.Year))
.RuleFor(x => x.TotalArea, f => Math.Round(f.Random.Double(MinTotalArea, MaxTotalArea), 2))
.RuleFor(x => x.LivingArea, (f, dto) =>
{
var livingAreaPartOfTotalArea =
f.Random.Double(MinLivingAreaPartOfTotalArea, MaxLivingAreaPartOfTotalArea);
return Math.Round(livingAreaPartOfTotalArea * dto.TotalArea, 2);
})
.RuleFor(x => x.TotalFloors, f => f.Random.Int(MinTotalFloors, MaxTotalFloors))
.RuleFor(x => x.Floor, (f, dto) =>
{
if (dto.PropertyType is "ИЖС")
{
return null;
}

return f.Random.Int(1, dto.TotalFloors);
})
.RuleFor(x => x.CadastralNumber, f =>
$"{f.Random.Int(1, 99):D2}:" +
$"{f.Random.Int(1, 99):D2}:" +
$"{f.Random.Int(1, 9999999):D7}:" +
$"{f.Random.Int(1, 9999):D4}")
.RuleFor(x => x.CadastralValue, (f, dto) =>
{
var pricePerM2 = f.Random.Double(MinPricePerM2, MaxPricePerM2);
var price = dto.TotalArea * pricePerM2;
return (decimal)Math.Round(price, 2);
});

/// <summary>
/// Генерирует объект жилого строительства для заданного идентификатора
/// </summary>
/// <param name="id">Идентификатор объекта жилого строительства</param>
/// <returns>Сгенерированный объект жилого строительства</returns>
public ResidentialBuildingDto Generate(int id)
{
logger.LogInformation("Generating Residential Building for Id={id}", id);

var generatedObject = _faker.Generate();
generatedObject.Id = id;

logger.LogInformation(
"Residential building generated: {@Building}",
new
{
generatedObject.Id,
generatedObject.Address,
generatedObject.PropertyType,
generatedObject.BuildYear,
generatedObject.TotalArea,
generatedObject.LivingArea,
generatedObject.Floor,
generatedObject.TotalFloors,
generatedObject.CadastralNumber,
generatedObject.CadastralValue
});

return generatedObject;
}
}
32 changes: 32 additions & 0 deletions ResidentialBuilding.Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Generator.Generator;
using Generator.Service;
using ResidentialBuilding.ServiceDefaults;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.AddRedisDistributedCache("residential-building-cache");

builder.Services.AddCors(options =>
{
options.AddPolicy("AllowLocalDev", policy =>
{
policy
.AllowAnyOrigin()
.WithHeaders("Content-Type")
.WithMethods("GET");
});
});

builder.Services.AddSingleton<ResidentialBuildingGenerator>();
builder.Services.AddSingleton<IResidentialBuildingService, ResidentialBuildingService>();

builder.Services.AddControllers();

var app = builder.Build();

app.UseCors("AllowLocalDev");

app.MapControllers();

app.Run();
Loading