-
Notifications
You must be signed in to change notification settings - Fork 24
Прибылов Александр Лаб. 1 Группа 6511 #8
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
AlexPrib
wants to merge
3
commits into
itsecd:main
Choose a base branch
from
AlexPrib: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.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.5.2" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.2" /> | ||
| <PackageReference Include="Aspire.Hosting.Redis" Version="9.5.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Client.Wasm\Client.Wasm.csproj" /> | ||
| <ProjectReference Include="..\GenerationService\GenerationService.csproj" /> | ||
| </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,13 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var cache = builder.AddRedis("cache"); | ||
|
|
||
| var generationService = builder.AddProject<Projects.GenerationService>("generation-service") | ||
| .WithReference(cache) | ||
| .WaitFor(cache); | ||
|
|
||
| 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,17 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17136;http://localhost:15136", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21197", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:20131" | ||
| } | ||
| } | ||
| } | ||
| } |
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
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": "http://localhost:5134/course" | ||
| } | ||
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,18 @@ | ||
| <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="9.5.2" /> | ||
| <PackageReference Include="Bogus" Version="35.6.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj" /> | ||
| </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,57 @@ | ||
| namespace GenerationService.Models; | ||
|
|
||
| /// <summary> | ||
| /// Модель, описывающая учебный курс и его основные метаданные | ||
| /// </summary> | ||
| public class Course | ||
| { | ||
| /// <summary> | ||
| /// Уникальный идентификатор курса | ||
| /// </summary> | ||
| public int Id { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Название курса | ||
| /// </summary> | ||
| public string Name { get; init; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Полное имя преподавателя курса | ||
| /// </summary> | ||
| public string TeacherFullName { get; init; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Дата начала курса | ||
| /// </summary> | ||
| public DateOnly StartDate { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Дата окончания курса | ||
| /// </summary> | ||
| public DateOnly EndDate { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Максимально допустимое количество студентов, которые могут быть зачислены на курс | ||
| /// </summary> | ||
| public int MaxStudents { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Текущее количество записанных студентов | ||
| /// </summary> | ||
| public int CurrentStudents { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Выдаётся ли по окончании курса сертификат | ||
| /// </summary> | ||
| public bool HasCertificate { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Стоимость курса | ||
| /// </summary> | ||
| public decimal Cost { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Рейтинг курса | ||
| /// </summary> | ||
| public int Rating { get; init; } | ||
| } |
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,58 @@ | ||
| using ServiceDefaults; | ||
| using GenerationService.Models; | ||
| using GenerationService.Services; | ||
| using Microsoft.Extensions.Caching.Distributed; | ||
| using System.Text.Json; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
|
|
||
| builder.AddRedisDistributedCache("cache"); | ||
|
|
||
| builder.Services.AddCors(options => | ||
| options.AddDefaultPolicy(policy => | ||
| policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.UseCors(); | ||
| app.MapDefaultEndpoints(); | ||
|
|
||
| app.MapGet("/course", async (int id, IDistributedCache cache, ILogger<Program> logger) => | ||
| { | ||
| if (id <= 0) | ||
| return Results.BadRequest("Received invalid ID. ID must be a positive number"); | ||
|
|
||
| var cacheKey = $"course:{id}"; | ||
|
|
||
| var cached = await cache.GetStringAsync(cacheKey); | ||
| if (cached is not null) | ||
| { | ||
| var cachedCourse = JsonSerializer.Deserialize<Course>(cached); | ||
| if (cachedCourse is not null) | ||
| { | ||
| logger.LogInformation("Cache hit for course with id {CourseId}", id); | ||
| return Results.Ok(cachedCourse); | ||
| } | ||
| } | ||
|
|
||
| logger.LogInformation("Cache miss for course with id {CourseId}, generating new data", id); | ||
| var course = CourseGenerator.Generate(id); | ||
|
|
||
| await cache.SetStringAsync( | ||
| cacheKey, | ||
| JsonSerializer.Serialize(course), | ||
| new DistributedCacheEntryOptions | ||
| { | ||
| AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) | ||
| }); | ||
|
|
||
| logger.LogInformation( | ||
| "Generated and cached course {CourseName} with id {CourseId}", | ||
| course.Name, id); | ||
|
|
||
| return Results.Ok(course); | ||
| }); | ||
|
|
||
| app.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 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "http://localhost:5134", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": false, | ||
| "applicationUrl": "https://localhost:7134;http://localhost:5134", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
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.
У этого файла нет проекта