-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from kamil-oberaj/KO/reservations
[feat]: Reservations
- Loading branch information
Showing
148 changed files
with
2,975 additions
and
660 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
on: | ||
push: | ||
branches: | ||
- master | ||
- master | ||
pull_request: | ||
branches: | ||
- '**' | ||
- '**' | ||
|
||
jobs: | ||
build: | ||
name: Restore, Build and Test | ||
|
@@ -18,21 +18,21 @@ jobs: | |
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- name: Restore Packages | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build --configuration Release | ||
|
||
- name: Test | ||
run: dotnet test --configuration Release --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" | ||
run: dotnet test --configuration Release --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" --settings coverlet.runsettings | ||
|
||
- name: Combine Coverage Reports | ||
uses: danielpalme/[email protected] | ||
with: | ||
|
@@ -43,7 +43,7 @@ jobs: | |
title: "Code Coverage" | ||
tag: "${{ github.run_number }}_${{ github.run_id }}" | ||
toolpath: "reportgeneratortool" | ||
|
||
- name: Upload Combined Coverage XML | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
|
This file contains 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,7 @@ | ||
namespace StudioManager.API.Contracts.Common; | ||
|
||
public class NamedBaseDto | ||
{ | ||
public Guid Id { get; init; } | ||
public string Name { get; init; } = null!; | ||
} |
2 changes: 1 addition & 1 deletion
2
StudioManager.API.Contracts/EquipmentTypes/EquipmentTypeReadDto.cs
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace StudioManager.API.Contracts.EquipmentTypes; | ||
|
||
public sealed record EquipmentTypeReadDto(Guid Id, string Name); | ||
public sealed record EquipmentTypeReadDto(Guid Id, string Name); |
2 changes: 1 addition & 1 deletion
2
StudioManager.API.Contracts/EquipmentTypes/EquipmentTypeWriteDto.cs
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace StudioManager.API.Contracts.EquipmentTypes; | ||
|
||
public sealed record EquipmentTypeWriteDto(string Name); | ||
public sealed record EquipmentTypeWriteDto(string Name); |
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
namespace StudioManager.API.Contracts.Equipments; | ||
|
||
public sealed record EquipmentWriteDto(string Name, Guid EquipmentTypeId, int Quantity/*, byte[] Image*/); | ||
public sealed record EquipmentWriteDto(string Name, Guid EquipmentTypeId, int Quantity /*, string ImageUrl*/); |
This file contains 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 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 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
10 changes: 10 additions & 0 deletions
10
StudioManager.API.Contracts/Reservations/ReservationReadDto.cs
This file contains 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,10 @@ | ||
using StudioManager.API.Contracts.Common; | ||
|
||
namespace StudioManager.API.Contracts.Reservations; | ||
|
||
public sealed record ReservationReadDto( | ||
Guid Id, | ||
DateOnly StartDate, | ||
DateOnly EndDate, | ||
int Quantity, | ||
NamedBaseDto Equipment); |
3 changes: 3 additions & 0 deletions
3
StudioManager.API.Contracts/Reservations/ReservationWriteDto.cs
This file contains 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,3 @@ | ||
namespace StudioManager.API.Contracts.Reservations; | ||
|
||
public sealed record ReservationWriteDto(DateOnly StartDate, DateOnly EndDate, int Quantity, Guid EquipmentId); |
This file contains 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
43 changes: 43 additions & 0 deletions
43
StudioManager.API/BackgroundServices/FinishedReservationsBackgroundService.cs
This file contains 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,43 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Microsoft.EntityFrameworkCore; | ||
using StudioManager.Application.DbContextExtensions; | ||
using StudioManager.Domain.Filters; | ||
using StudioManager.Infrastructure; | ||
using StudioManager.Infrastructure.Common; | ||
using StudioManager.Notifications.Equipment; | ||
|
||
namespace StudioManager.API.BackgroundServices; | ||
|
||
[ExcludeFromCodeCoverage] | ||
//TODO: Create read lock for this service | ||
public sealed class FinishedReservationsBackgroundService( | ||
IDbContextFactory<StudioManagerDbContext> dbContextFactory) | ||
: BackgroundService | ||
{ | ||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
while (!stoppingToken.IsCancellationRequested) | ||
{ | ||
await Task.Delay(TimeSpan.FromDays(1), stoppingToken); | ||
|
||
await using var dbContext = await dbContextFactory.CreateDbContextAsync(stoppingToken); | ||
{ | ||
await ReturnReservationsAsync(dbContext, stoppingToken); | ||
} | ||
} | ||
} | ||
|
||
private static async Task ReturnReservationsAsync(DbContextBase dbContext, CancellationToken cancellationToken) | ||
{ | ||
var filter = new ReservationFilter { EndDate = DateOnly.FromDateTime(DateTime.Today) }; | ||
|
||
var reservations = await dbContext.GetReservationsAsync(filter, cancellationToken); | ||
|
||
if (reservations.Count == 0) return; | ||
|
||
foreach (var reservation in reservations) | ||
reservation.AddDomainEvent(new EquipmentReturnedEvent(reservation.EquipmentId, 0)); | ||
|
||
await dbContext.SaveChangesAsync(cancellationToken); | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.