Skip to content
Closed
Show file tree
Hide file tree
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 Dec 23, 2025
e0c627d
seed data
LiliaASt Dec 23, 2025
15dc064
created tests
LiliaASt Dec 23, 2025
25bcdab
building and testing
LiliaASt Dec 23, 2025
1a81435
Update the README
LiliaASt Dec 23, 2025
a763d93
Add Controllers
LiliaASt Dec 23, 2025
70457b2
Add Services
LiliaASt Dec 23, 2025
6f30813
Add DTOs for request/response models
LiliaASt Dec 23, 2025
8a17790
Add Interfaces
LiliaASt Dec 23, 2025
2b7a2e1
add solution structure and project configuration
LiliaASt Dec 23, 2025
9d0f13a
add tests
LiliaASt Dec 23, 2025
ef02683
updated the README
LiliaASt Dec 23, 2025
497cf87
Merge branch 'main' into lab2
LiliaASt Dec 25, 2025
0e1a1e3
update all files
LiliaASt Dec 25, 2025
c5123cf
Merge branch 'lab2' of https://github.com/LiliaASt/enterprise-develop…
LiliaASt Dec 25, 2025
ebf55ef
update Application.Contracts
LiliaASt Jan 11, 2026
5c14242
update Application
LiliaASt Jan 11, 2026
721d3d8
update Domain
LiliaASt Jan 11, 2026
09f2eea
add Infrastructure.EfCore
LiliaASt Jan 11, 2026
45f5f83
update API
LiliaASt Jan 11, 2026
ae3b088
add AppHost
LiliaASt Jan 11, 2026
74b33c5
update README
LiliaASt Jan 11, 2026
30549d8
add Generator.Grpc.Host
LiliaASt Jan 12, 2026
33bf89f
update API
LiliaASt Jan 12, 2026
b68489e
update AppHost
LiliaASt Jan 12, 2026
c5bbb25
update README
LiliaASt Jan 12, 2026
e2996d1
update Controllers
LiliaASt Jan 12, 2026
4c82f62
use primary constructor
LiliaASt Jan 12, 2026
8ebc3d5
use IOptions
LiliaASt Jan 12, 2026
5b2cbc2
Update Program.cs
LiliaASt Jan 12, 2026
9c4ad75
update Api Program.cs
LiliaASt Jan 12, 2026
7605d92
update name Api
LiliaASt Jan 12, 2026
ff34d68
update CarRentalService.sln
LiliaASt Jan 12, 2026
f492f38
update api
LiliaASt Jan 12, 2026
15805c1
update Api
LiliaASt Jan 12, 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
28 changes: 28 additions & 0 deletions .github/workflows/dotnet-tests.yml
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
31 changes: 31 additions & 0 deletions CarRentalService.Api/CarRentalService.Api.csproj
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 CarRentalService.Api/Configuration/RentalGeneratorOptions.cs
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; }
}
93 changes: 93 additions & 0 deletions CarRentalService.Api/Controllers/AnalyticsController.cs
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 CarRentalService.Api/Controllers/CarModelGenerationsController.cs
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();
}
}
Loading