-
Notifications
You must be signed in to change notification settings - Fork 24
Челаев Петр Лаб. 1 Группа 6512 #14
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
PripyatskyPrometheus
wants to merge
11
commits into
itsecd:main
Choose a base branch
from
PripyatskyPrometheus: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.
+621
−5
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
974822e
Создал структуру проекта и забабахал модель
PripyatskyPrometheus 3a5a4ea
Delete SoftwareProject.ApiService directory
PripyatskyPrometheus b803d52
Delete SoftwareProject.Web directory
PripyatskyPrometheus 5f6b884
Добавил генератор и контроллер.
PripyatskyPrometheus 9761727
Устранение конфликтов
PripyatskyPrometheus 4524147
Неболшая калибровка
PripyatskyPrometheus 7467676
Добавил описание
PripyatskyPrometheus 12dd63b
Добавил работу клиента, которую прошляпил до этого:)
PripyatskyPrometheus 0922e68
Исправил замечания
PripyatskyPrometheus b6814d1
Побился над кодировкой
PripyatskyPrometheus f30d735
Исправил версии
PripyatskyPrometheus 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:7190/api/projects" | ||
| } | ||
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,16 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var cache = builder.AddRedis("cache").WithRedisCommander(); | ||
|
|
||
| var generationService = builder.AddProject<Projects.ProgramProject_GenerationService>("generation-service") | ||
| .WithExternalHttpEndpoints() | ||
| .WithReference(cache) | ||
| .WaitFor(cache); | ||
|
|
||
|
|
||
| // Добавил клиента | ||
| var client = builder.AddProject<Projects.Client_Wasm>("client-wasm") | ||
| .WithExternalHttpEndpoints() | ||
| .WaitFor(generationService); | ||
|
|
||
| builder.Build().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,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.5.2" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>f95b6f17-c3f7-4ae5-a722-409a54dda80d</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Client.Wasm\Client.Wasm.csproj" /> | ||
| <ProjectReference Include="..\ProgramProject.GenerationService\ProgramProject.GenerationService.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.2" /> | ||
| <PackageReference Include="Aspire.Hosting.Redis" Version="9.5.2" /> | ||
| </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,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17028;http://localhost:15016", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21209", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22094" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15016", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19079", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20183" | ||
| } | ||
| } | ||
| } | ||
| } |
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", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
ProgramProject.GenerationService/Controllers/ProjectsController.cs
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,33 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using ProgramProject.GenerationService.Models; | ||
| using ProgramProject.GenerationService.Services; | ||
|
|
||
| namespace ProgramProject.GenerationService.Controllers; | ||
|
|
||
| [Route("api/[controller]")] | ||
| [ApiController] | ||
| public class ProjectsController(IProjectService projectService, ILogger<ProjectsController> logger) : ControllerBase | ||
| { | ||
| [HttpGet("{id}")] | ||
| public async Task<ActionResult<ProgramProjectModel>> GetProject(int id) | ||
| { | ||
| try | ||
| { | ||
| logger.LogInformation("Запрос проекта с ID {ProjectId}", id); | ||
| var project = await projectService.GetProjectByIdAsync(id); | ||
| return Ok(project); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError(ex, "Ошибка при обработке запроса проекта ID {ProjectId}", id); | ||
| return StatusCode(500, "Внутренняя ошибка сервера"); | ||
| } | ||
| } | ||
|
|
||
| [HttpGet] | ||
| public async Task<ActionResult<ProgramProjectModel>> GetProjectByIdQuery( | ||
| [FromQuery] int id) | ||
| { | ||
| return await GetProject(id); | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
ProgramProject.GenerationService/Generator/ProgramProjectFaker.cs
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,71 @@ | ||
| using Bogus; | ||
| using ProgramProject.GenerationService.Models; | ||
|
|
||
| namespace ProgramProject.GenerationService.Generator; | ||
|
|
||
| public class ProgramProjectFaker | ||
| { | ||
| private readonly Faker<ProgramProjectModel> _faker; | ||
|
|
||
| public ProgramProjectFaker() | ||
| { | ||
| _faker = new Faker<ProgramProjectModel>("ru") | ||
| .RuleFor(p => p.Id, f => f.IndexVariable++) | ||
|
|
||
| // Название проекта: комбинация из Commerce, Hacker, Finance, Lorem | ||
| .RuleFor(p => p.Name, f => | ||
| f.PickRandom( | ||
| f.Commerce.ProductName() + " " + f.Hacker.Abbreviation(), | ||
| "Project " + f.Hacker.Noun(), | ||
| f.Finance.AccountName() + " System", | ||
| f.Lorem.Word() + "-" + f.Lorem.Word() | ||
| )) | ||
|
|
||
| // Заказчик — компания | ||
| .RuleFor(p => p.Customer, f => f.Company.CompanyName()) | ||
|
|
||
| // Менеджер проекта — полное имя | ||
| .RuleFor(p => p.Manager, f => f.Name.FullName()) | ||
|
|
||
| // Дата начала | ||
| .RuleFor(p => p.StartDate, f => | ||
| { | ||
| var start = f.Date.Past(5); | ||
| return DateOnly.FromDateTime(start); | ||
| }) | ||
|
|
||
| // Плановая дата завершения: позже даты начала | ||
| .RuleFor(p => p.PlannedEndDate, (f, p) => | ||
| { | ||
| var planned = f.Date.Soon(180, p.StartDate.ToDateTime(TimeOnly.MinValue)); | ||
| return DateOnly.FromDateTime(planned); | ||
| }) | ||
|
|
||
| // Бюджет: от 10k до 1M | ||
| .RuleFor(p => p.Budget, f => f.Finance.Amount(10000, 1000000, 2)) | ||
|
|
||
|
|
||
| // Процент выполнения: от 0 до 100 | ||
| .RuleFor(p => p.CompletionPercentage, f => f.Random.Int(0, 100)) | ||
|
|
||
| // Фактические затраты: пропорциональны бюджету (50-120%) | ||
| .RuleFor(p => p.ActualCost, (f, p) => | ||
| f.Finance.Amount(p.Budget * 0.5m, p.Budget * 1.2m, 2)) | ||
|
|
||
| // Фактическая дата завершения: заполняется только если процент = 100 | ||
| .RuleFor(p => p.ActualEndDate, (f, p) => | ||
| { | ||
| if (p.CompletionPercentage == 100) | ||
| { | ||
| var actual = f.Date.Recent(30); | ||
| return DateOnly.FromDateTime(actual); | ||
| } | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| public ProgramProjectModel Generate() | ||
| { | ||
| return _faker.Generate(); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
ProgramProject.GenerationService/Models/ProgramProjectModel.cs
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,48 @@ | ||
| namespace ProgramProject.GenerationService.Models; | ||
|
|
||
| /// <summary> | ||
| /// Модель программного проекта | ||
| /// </summary> | ||
| public class ProgramProjectModel | ||
| { | ||
| /// <summary> | ||
| /// Идетификатор в системе | ||
| /// </summary> | ||
| public int Id { get; set; } | ||
| /// <summary> | ||
| /// Название проекта | ||
| /// </summary> | ||
| public string Name { get; set; } = string.Empty; | ||
| /// <summary> | ||
| /// Заказчик проекта | ||
| /// </summary> | ||
| public string Customer { get; set; } = string.Empty; | ||
| /// <summary> | ||
| /// Мененджер проекта | ||
| /// </summary> | ||
| public string Manager { get; set; } = string.Empty; | ||
| /// <summary> | ||
| /// Дата начала | ||
| /// </summary> | ||
| public DateOnly StartDate { get; set; } | ||
| /// <summary> | ||
| /// Плановая дата завершения | ||
| /// </summary> | ||
| public DateOnly PlannedEndDate { get; set; } | ||
| /// <summary> | ||
| /// Фактическая дата завершения | ||
| /// </summary> | ||
| public DateOnly? ActualEndDate { get; set; } | ||
| /// <summary> | ||
| /// Бюджет | ||
| /// </summary> | ||
| public decimal Budget { get; set; } | ||
| /// <summary> | ||
| /// Фактические затраты | ||
| /// </summary> | ||
| public decimal ActualCost { get; set; } | ||
| /// <summary> | ||
| /// Процент выполнения | ||
| /// </summary> | ||
| public int CompletionPercentage { get; set; } | ||
| } |
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,54 @@ | ||
| using ProgramProject.GenerationService.Generator; | ||
| using ProgramProject.GenerationService.Services; | ||
| using ProgramProject.ServiceDefaults; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
| builder.AddServiceDefaults(); | ||
|
|
||
| builder.AddRedisDistributedCache("cache"); | ||
|
|
||
| builder.Services.AddCors(options => | ||
| { | ||
| options.AddPolicy("AllowClient", policy => | ||
| { | ||
| policy.SetIsOriginAllowed(origin => | ||
| { | ||
| try | ||
| { | ||
| var uri = new Uri(origin); | ||
| return uri.Host == "localhost"; | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } | ||
| }) | ||
| .WithMethods("GET") // Только GET запросы | ||
| .AllowAnyHeader() | ||
| .AllowCredentials(); | ||
| }); | ||
| }); | ||
|
|
||
| builder.Services.AddSingleton<ProgramProjectFaker>(); | ||
| builder.Services.AddScoped<IProjectService, ProjectService>(); | ||
|
|
||
| builder.Services.AddControllers(); | ||
| builder.Services.AddEndpointsApiExplorer(); | ||
| builder.Services.AddSwaggerGen(); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.MapDefaultEndpoints(); | ||
| app.UseCors("AllowClient"); | ||
|
|
||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
| app.UseSwaggerUI(); | ||
| } | ||
|
|
||
| app.UseHttpsRedirection(); | ||
| app.UseAuthorization(); | ||
| app.MapControllers(); | ||
|
|
||
| app.Run(); |
19 changes: 19 additions & 0 deletions
19
ProgramProject.GenerationService/ProgramProject.GenerationService.csproj
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,19 @@ | ||
| <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="..\ProgramProject.ServiceDefaults\ProgramProject.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Логику работы с кэшем и с объектами вынести в отдельные службы, по необходимости добавить обработку исключений