-
Notifications
You must be signed in to change notification settings - Fork 76
Лаб. 4 6411 Асцатрян Лилия #273
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
Closed
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
91e244b
prepared the class structure
LiliaASt e0c627d
seed data
LiliaASt 15dc064
created tests
LiliaASt 25bcdab
building and testing
LiliaASt 1a81435
Update the README
LiliaASt a763d93
Add Controllers
LiliaASt 70457b2
Add Services
LiliaASt 6f30813
Add DTOs for request/response models
LiliaASt 8a17790
Add Interfaces
LiliaASt 2b7a2e1
add solution structure and project configuration
LiliaASt 9d0f13a
add tests
LiliaASt ef02683
updated the README
LiliaASt 497cf87
Merge branch 'main' into lab2
LiliaASt 0e1a1e3
update all files
LiliaASt c5123cf
Merge branch 'lab2' of https://github.com/LiliaASt/enterprise-develop…
LiliaASt ebf55ef
update Application.Contracts
LiliaASt 5c14242
update Application
LiliaASt 721d3d8
update Domain
LiliaASt 09f2eea
add Infrastructure.EfCore
LiliaASt 45f5f83
update API
LiliaASt ae3b088
add AppHost
LiliaASt 74b33c5
update README
LiliaASt 30549d8
add Generator.Grpc.Host
LiliaASt 33bf89f
update API
LiliaASt b68489e
update AppHost
LiliaASt c5bbb25
update README
LiliaASt e2996d1
update Controllers
LiliaASt 4c82f62
use primary constructor
LiliaASt 8ebc3d5
use IOptions
LiliaASt 5b2cbc2
Update Program.cs
LiliaASt 9c4ad75
update Api Program.cs
LiliaASt 7605d92
update name Api
LiliaASt ff34d68
update CarRentalService.sln
LiliaASt f492f38
update api
LiliaASt 15805c1
update Api
LiliaASt 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,28 @@ | ||
| name: .NET Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["main", "lab2"] | ||
| pull_request: | ||
| branches: ["main", "lab2"] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: 8.0.x | ||
|
|
||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
|
|
||
| - name: Build | ||
| run: dotnet build --no-restore --configuration Release | ||
|
|
||
| - name: Test | ||
| run: dotnet test --no-build --verbosity normal --configuration Release |
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,31 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| <NoWarn>$(NoWarn);1591</NoWarn> | ||
| <DocumentationFile>CarRentalService.Api.xml</DocumentationFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10" /> | ||
| <PackageReference Include="MongoDB.Driver" Version="2.30.0" /> | ||
| <PackageReference Include="MongoDB.EntityFrameworkCore" Version="8.1.0" /> | ||
| <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||
| <PackageReference Include="Aspire.MongoDB.Driver" Version="9.0.0" /> | ||
| <PackageReference Include="Grpc.AspNetCore" Version="2.71.0" /> | ||
| <PackageReference Include="Grpc.Net.Client" Version="2.71.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\CarRentalService.Application\CarRentalService.Application.csproj" /> | ||
| <ProjectReference Include="..\CarRentalService.Infrastructure.EfCore\CarRentalService.Infrastructure.EfCore.csproj" /> | ||
| <ProjectReference Include="..\CarRentalService.ServiceDefaults\CarRentalService.ServiceDefaults.csproj" /> | ||
| <ProjectReference Include="..\CarRentalService.Application.Contracts\CarRentalService.Application.Contracts.csproj" /> | ||
| <ProjectReference Include="..\CarRentalService.Domain\CarRentalService.Domain.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
29 changes: 29 additions & 0 deletions
29
CarRentalService.Api/Configuration/RentalGeneratorOptions.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,29 @@ | ||
| namespace CarRentalService.Api.Configuration; | ||
|
|
||
| /// <summary> | ||
| /// Configuration options for the rental generator service | ||
| /// </summary> | ||
| public class RentalGeneratorOptions | ||
| { | ||
| public const string SectionName = "RentalGenerator"; | ||
|
|
||
| /// <summary> | ||
| /// Default number of rental contracts to generate | ||
| /// </summary> | ||
| public int Count { get; set; } = 100; | ||
|
|
||
| /// <summary> | ||
| /// Batch size for streaming rental contracts | ||
| /// </summary> | ||
| public int BatchSize { get; set; } = 10; | ||
|
|
||
| /// <summary> | ||
| /// Retry delay in seconds for reconnection attempts | ||
| /// </summary> | ||
| public int RetryDelay { get; set; } = 5; | ||
|
|
||
| /// <summary> | ||
| /// gRPC service address for the rental generator | ||
| /// </summary> | ||
| public string? GrpcAddress { 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,93 @@ | ||
| using CarRentalService.Application.Contracts; | ||
| using CarRentalService.Application.Contracts.Analytics; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace CarRentalService.Api.Controllers; | ||
|
|
||
| /// <summary> | ||
| /// Controller for analytics and business intelligence endpoints | ||
| /// </summary> | ||
| /// <param name="analyticsService">Analytics service dependency</param> | ||
| [ApiController] | ||
| [Route("api/[controller]")] | ||
| [Produces("application/json")] | ||
| public class AnalyticsController(IAnalyticsService analyticsService) : ControllerBase | ||
| { | ||
| /// <summary> | ||
| /// Retrieves customers who rented cars of a specific model name | ||
| /// </summary> | ||
| /// <param name="modelName">Car model name to filter by</param> | ||
| /// <returns>List of customer names</returns> | ||
| [HttpGet("clients-by-model-name")] | ||
| [ProducesResponseType(typeof(List<string>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<string>>> GetClientsByModelName([FromQuery] string modelName) | ||
| { | ||
| var result = await analyticsService.ReadCustomersByModelName(modelName); | ||
| return Ok(result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves customers who rented cars of a specific model ID | ||
| /// </summary> | ||
| /// <param name="modelId">Car model ID to filter by</param> | ||
| /// <returns>List of customer names</returns> | ||
| [HttpGet("clients-by-model-id/{modelId:int}")] | ||
| [ProducesResponseType(typeof(List<string>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<string>>> GetClientsByModelId(int modelId) | ||
| { | ||
| var result = await analyticsService.ReadCustomersByModelId(modelId); | ||
| return Ok(result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves cars currently in rent at a specific time | ||
| /// </summary> | ||
| /// <param name="atTime">Time to check for active rentals (default: current time)</param> | ||
| /// <returns>List of currently rented cars</returns> | ||
| [HttpGet("cars-in-rent")] | ||
| [ProducesResponseType(typeof(List<CarRentalResponse>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<CarRentalResponse>>> GetCarsInRent([FromQuery] DateTime? atTime = null) | ||
| { | ||
| var checkTime = atTime ?? DateTime.Now; | ||
| var result = await analyticsService.ReadCarsInRent(checkTime); | ||
| return Ok(result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves top N most frequently rented cars | ||
| /// </summary> | ||
| /// <param name="count">Number of top cars to return (default: 5)</param> | ||
| /// <returns>List of top rented cars with statistics</returns> | ||
| [HttpGet("top-rented-cars")] | ||
| [ProducesResponseType(typeof(List<TopCarResponse>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<TopCarResponse>>> GetTopRentedCars([FromQuery] int count = 5) | ||
| { | ||
| var result = await analyticsService.ReadTopMostRentedCars(count); | ||
| return Ok(result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves rental count for all cars | ||
| /// </summary> | ||
| /// <returns>List of all cars with their rental counts</returns> | ||
| [HttpGet("all-cars-with-rental-count")] | ||
| [ProducesResponseType(typeof(List<CarRentalCountResponse>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<CarRentalCountResponse>>> GetAllCarsWithRentalCount() | ||
| { | ||
| var result = await analyticsService.ReadAllCarsWithRentalCount(); | ||
| return Ok(result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves top N customers by total rental revenue | ||
| /// </summary> | ||
| /// <param name="count">Number of top customers to return (default: 5)</param> | ||
| /// <returns>List of top customers by revenue</returns> | ||
| [HttpGet("top-customers-by-revenue")] | ||
| [ProducesResponseType(typeof(List<TopCustomerResponse>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<TopCustomerResponse>>> GetTopCustomersByRevenue([FromQuery] int count = 5) | ||
| { | ||
| var result = await analyticsService.ReadTopCustomersByTotalAmount(count); | ||
| return Ok(result); | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
CarRentalService.Api/Controllers/CarModelGenerationsController.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,106 @@ | ||
| using CarRentalService.Application.Contracts.CarModelGeneration; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace CarRentalService.Api.Controllers; | ||
|
|
||
| /// <summary> | ||
| /// Controller for managing car model generations | ||
| /// </summary> | ||
| /// <param name="service">Car model generation service dependency</param> | ||
| [ApiController] | ||
| [Route("api/[controller]")] | ||
| [Produces("application/json")] | ||
| public class CarModelGenerationsController(ICarModelGenerationService service) : ControllerBase | ||
| { | ||
| /// <summary> | ||
| /// Retrieves all car model generations | ||
| /// </summary> | ||
| /// <returns>List of all car model generations</returns> | ||
| [HttpGet] | ||
| [ProducesResponseType(typeof(List<CarModelGenerationDto>), StatusCodes.Status200OK)] | ||
| public async Task<ActionResult<List<CarModelGenerationDto>>> GetAll() | ||
| { | ||
| var result = await service.GetAll(); | ||
| return Ok(result); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Retrieves a specific car model generation by ID | ||
| /// </summary> | ||
| /// <param name="id">Car model generation identifier</param> | ||
| /// <returns>Car model generation details</returns> | ||
| [HttpGet("{id:int}")] | ||
| [ProducesResponseType(typeof(CarModelGenerationDto), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)] | ||
| public async Task<ActionResult<CarModelGenerationDto>> GetById(int id) | ||
| { | ||
| var generation = await service.Get(id); | ||
| if (generation == null) | ||
| { | ||
| return NotFound($"CarModelGeneration with ID {id} not found."); | ||
| } | ||
| return Ok(generation); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new car model generation | ||
| /// </summary> | ||
| /// <param name="dto">Car model generation creation data</param> | ||
| /// <returns>Created car model generation</returns> | ||
| [HttpPost] | ||
| [ProducesResponseType(typeof(CarModelGenerationDto), StatusCodes.Status201Created)] | ||
| [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] | ||
| public async Task<ActionResult<CarModelGenerationDto>> Create([FromBody] CarModelGenerationCreateUpdateDto dto) | ||
| { | ||
| try | ||
| { | ||
| var createdGeneration = await service.Create(dto); | ||
| return CreatedAtAction(nameof(GetById), new { id = createdGeneration.Id }, createdGeneration); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| return BadRequest($"Invalid car model generation data: {ex.Message}"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Updates an existing car model generation | ||
| /// </summary> | ||
| /// <param name="id">Car model generation identifier</param> | ||
| /// <param name="dto">Car model generation update data</param> | ||
| /// <returns>No content on success</returns> | ||
| [HttpPut("{id:int}")] | ||
| [ProducesResponseType(StatusCodes.Status204NoContent)] | ||
| [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)] | ||
| [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)] | ||
| public async Task<ActionResult> Update(int id, [FromBody] CarModelGenerationCreateUpdateDto dto) | ||
| { | ||
| try | ||
| { | ||
| await service.Update(dto, id); | ||
| return NoContent(); | ||
| } | ||
| catch (KeyNotFoundException) | ||
| { | ||
| return NotFound($"CarModelGeneration with ID {id} not found."); | ||
| } | ||
| catch (ArgumentException ex) | ||
| { | ||
| return BadRequest(ex.Message); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Deletes a car model generation | ||
| /// </summary> | ||
| /// <param name="id">Car model generation identifier</param> | ||
| /// <returns>No content on success</returns> | ||
| [HttpDelete("{id:int}")] | ||
| [ProducesResponseType(StatusCodes.Status204NoContent)] | ||
| [ProducesResponseType(StatusCodes.Status404NotFound)] | ||
| public async Task<ActionResult> Delete(int id) | ||
| { | ||
| var result = await service.Delete(id); | ||
| return result ? NoContent() : NotFound(); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.