Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ===== .NET / IDE =====
bin/
obj/
.vs/
*.user
*.suo
*.userprefs
.idea/
*.DotSettings.user

# тесты / артефакты
TestResults/
*.log

# ОС
.DS_Store
Thumbs.db

# секреты/локальные конфиги
appsettings.Development.json
appsettings.*.local.json

# docker локальные переопределения
docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="..\CoworkingBooking.BookingService.Application\CoworkingBooking.BookingService.Application.csproj" />
<ProjectReference Include="..\CoworkingBooking.BookingService.Infrastructure\CoworkingBooking.BookingService.Infrastructure.csproj" />
<ProjectReference Include="..\CoworkingBooking.CoreLib\CoworkingBooking.CoreLib.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
83 changes: 83 additions & 0 deletions CoworkingBooking.BookingService.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using BookingService.Application.Bookings;
using BookingService.Application.Rooms;
using BookingService.Application.Rules;
using BookingService.Infrastructure.Persistence;
using BookingService.Infrastructure.Services;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<BookingDbContext>(opt =>
opt.UseNpgsql(builder.Configuration.GetConnectionString("Postgres")));

builder.Services.AddScoped<IRoomService, RoomService>();
builder.Services.AddScoped<IRuleService, RuleService>();
builder.Services.AddScoped<IBookingService, BookingServiceImpl>();

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();

// Rooms
app.MapGet("/api/booking/v1/rooms", async (int page, int pageSize, IRoomService svc, CancellationToken ct) =>
Results.Ok(await svc.GetAsync(page <= 0 ? 1 : page, pageSize <= 0 ? 20 : pageSize, ct)));
app.MapGet("/api/booking/v1/rooms/{id:guid}", async (Guid id, IRoomService svc, CancellationToken ct) =>
{
var r = await svc.GetByIdAsync(id, ct);
return r is null ? Results.NotFound() : Results.Ok(r);
});
app.MapPost("/api/booking/v1/rooms", async (RoomCreateDto dto, IRoomService svc, CancellationToken ct) =>
Results.Created($"/api/booking/v1/rooms", await svc.CreateAsync(dto, ct)));
app.MapPut("/api/booking/v1/rooms/{id:guid}", async (Guid id, RoomUpdateDto dto, IRoomService svc, CancellationToken ct) =>
{
var res = await svc.UpdateAsync(id, dto, ct);
return res.IsSuccess ? Results.NoContent() : Results.NotFound();
});
app.MapDelete("/api/booking/v1/rooms/{id:guid}", async (Guid id, IRoomService svc, CancellationToken ct) =>
{
var res = await svc.DeleteAsync(id, ct);
return res.IsSuccess ? Results.NoContent() : Results.NotFound();
});

// Rules
app.MapGet("/api/booking/v1/rooms/{roomId:guid}/rules", async (Guid roomId, IRuleService svc, CancellationToken ct) =>
Results.Ok(await svc.GetByRoomAsync(roomId, ct)));
app.MapPost("/api/booking/v1/rules", async (TimeSlotRuleCreateDto dto, IRuleService svc, CancellationToken ct) =>
Results.Created($"/api/booking/v1/rules", await svc.CreateAsync(dto, ct)));
app.MapPut("/api/booking/v1/rules/{id:guid}", async (Guid id, TimeSlotRuleUpdateDto dto, IRuleService svc, CancellationToken ct) =>
{
var res = await svc.UpdateAsync(id, dto, ct);
return res.IsSuccess ? Results.NoContent() : Results.NotFound();
});
app.MapDelete("/api/booking/v1/rules/{id:guid}", async (Guid id, IRuleService svc, CancellationToken ct) =>
{
var res = await svc.DeleteAsync(id, ct);
return res.IsSuccess ? Results.NoContent() : Results.NotFound();
});

// Bookings
app.MapPost("/api/booking/v1/bookings", async (BookingCreateDto dto, IBookingService svc, CancellationToken ct) =>
{
var created = await svc.CreateAsync(dto, ct);
return Results.Created($"/api/booking/v1/bookings/{created.Id}", created);
});
app.MapGet("/api/booking/v1/bookings/{id:guid}", async (Guid id, IBookingService svc, CancellationToken ct) =>
{
var b = await svc.GetAsync(id, ct);
return b is null ? Results.NotFound() : Results.Ok(b);
});
app.MapPatch("/api/booking/v1/bookings/{id:guid}", async (Guid id, BookingUpdateDto dto, IBookingService svc, CancellationToken ct) =>
{
var res = await svc.UpdateAsync(id, dto, ct);
return res.IsSuccess ? Results.NoContent() : Results.NotFound();
});
app.MapPost("/api/booking/v1/bookings/{id:guid}/cancel", async (Guid id, IBookingService svc, CancellationToken ct) =>
{
var res = await svc.CancelAsync(id, ct);
return res.IsSuccess ? Results.NoContent() : Results.NotFound();
});

app.Run();
38 changes: 38 additions & 0 deletions CoworkingBooking.BookingService.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:30606",
"sslPort": 44341
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5058",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7288;http://localhost:5058",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
11 changes: 11 additions & 0 deletions CoworkingBooking.BookingService.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ConnectionStrings": {
"Postgres": "Host=localhost;Port=5432;Database=bookingdb;Username=booking;Password=bookingpwd"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace BookingService.Application.Bookings;

public enum BookingStatus { Pending = 0, Confirmed = 1, Cancelled = 2 }

public record BookingParticipantDto(Guid Id, string Name, string Email);
public record BookingCreateParticipantDto(string Name, string Email);

public record BookingDto(
Guid Id,
Guid RoomId,
Guid UserId,
DateTime StartUtc,
DateTime EndUtc,
decimal PriceTotal,
BookingStatus Status,
IReadOnlyList<BookingParticipantDto> Participants);

public record BookingCreateDto(Guid RoomId, Guid UserId, DateTime StartUtc, DateTime EndUtc, decimal? PriceHint, List<BookingCreateParticipantDto>? Participants);
public record BookingUpdateDto(DateTime? StartUtc, DateTime? EndUtc);
6 changes: 6 additions & 0 deletions CoworkingBooking.BookingService.Application/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CoworkingBooking.BookingService.Application;

public class Class1
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\CoworkingBooking.CoreLib\CoworkingBooking.CoreLib.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="FluentValidation" Version="11.9.0" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions CoworkingBooking.BookingService.Application/Rooms/RoomDtos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BookingService.Application.Rooms;

public record RoomDto(Guid Id, string Name, int Capacity, decimal BasePricePerHour, bool IsActive);
public record RoomCreateDto(string Name, int Capacity, decimal BasePricePerHour, bool IsActive);
public record RoomUpdateDto(string Name, int Capacity, decimal BasePricePerHour, bool IsActive);
5 changes: 5 additions & 0 deletions CoworkingBooking.BookingService.Application/Rules/RuleDtos.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BookingService.Application.Rules;

public record TimeSlotRuleDto(Guid Id, Guid RoomId, int Weekday, string StartTime, string EndTime, int MinDurationMin, int MaxDurationMin);
public record TimeSlotRuleCreateDto(Guid RoomId, int Weekday, string StartTime, string EndTime, int MinDurationMin, int MaxDurationMin);
public record TimeSlotRuleUpdateDto(int Weekday, string StartTime, string EndTime, int MinDurationMin, int MaxDurationMin);
6 changes: 6 additions & 0 deletions CoworkingBooking.BookingService.Infrastructure/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CoworkingBooking.BookingService.Infrastructure;

public class Class1
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\CoworkingBooking.BookingService.Application\CoworkingBooking.BookingService.Application.csproj" />
<ProjectReference Include="..\CoworkingBooking.CoreLib\CoworkingBooking.CoreLib.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Loading