add optional ticket group binding to account
This commit is contained in:
parent
4d1f6edc2e
commit
120963f3cc
@ -1,6 +1,4 @@
|
||||
using cuqmbr.TravelGuide.Application.Common.Authorization;
|
||||
using cuqmbr.TravelGuide.Application.Common.Services;
|
||||
using cuqmbr.TravelGuide.Domain.Enums;
|
||||
using MediatR.Behaviors.Authorization;
|
||||
|
||||
namespace cuqmbr.TravelGuide.Application.Payments.LiqPay
|
||||
@ -9,24 +7,8 @@ namespace cuqmbr.TravelGuide.Application.Payments.LiqPay
|
||||
public class GetPaymentLinkCommandAuthorizer :
|
||||
AbstractRequestAuthorizer<GetPaymentLinkCommand>
|
||||
{
|
||||
private readonly SessionUserService _sessionUserService;
|
||||
|
||||
public GetPaymentLinkCommandAuthorizer(SessionUserService sessionUserService)
|
||||
{
|
||||
_sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
public override void BuildPolicy(GetPaymentLinkCommand request)
|
||||
{
|
||||
UseRequirement(new MustBeAuthenticatedRequirement
|
||||
{
|
||||
IsAuthenticated= _sessionUserService.IsAuthenticated
|
||||
});
|
||||
|
||||
UseRequirement(new MustBeInRolesRequirement
|
||||
{
|
||||
RequiredRoles = [IdentityRole.Administrator],
|
||||
UserRoles = _sessionUserService.Roles
|
||||
});
|
||||
UseRequirement(new AllowAllRequirement());
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class GetPaymentLinkCommandHandler :
|
||||
|
||||
private readonly SessionTimeZoneService _sessionTimeZoneService;
|
||||
private readonly SessionCultureService _sessionCultureService;
|
||||
private readonly SessionUserService _sessionUserService;
|
||||
|
||||
public GetPaymentLinkCommandHandler(
|
||||
UnitOfWork unitOfWork,
|
||||
@ -33,7 +34,8 @@ public class GetPaymentLinkCommandHandler :
|
||||
IStringLocalizer localizer,
|
||||
EmailSenderService emailSender,
|
||||
SessionTimeZoneService SessionTimeZoneService,
|
||||
SessionCultureService sessionCultureService)
|
||||
SessionCultureService sessionCultureService,
|
||||
SessionUserService sessionUserService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_currencyConverterService = currencyConverterService;
|
||||
@ -42,6 +44,7 @@ public class GetPaymentLinkCommandHandler :
|
||||
_emailSender = emailSender;
|
||||
_sessionTimeZoneService = SessionTimeZoneService;
|
||||
_sessionCultureService = sessionCultureService;
|
||||
_sessionUserService = sessionUserService;
|
||||
}
|
||||
|
||||
public async Task<PaymentLinkDto> Handle(
|
||||
@ -409,6 +412,10 @@ public class GetPaymentLinkCommandHandler :
|
||||
.Items;
|
||||
|
||||
|
||||
var account = await _unitOfWork.AccountRepository.GetOneAsync(
|
||||
e => e.Guid == _sessionUserService.Guid, cancellationToken);
|
||||
|
||||
|
||||
var travelTime =
|
||||
ticketsDetails.OrderBy(td => td.order).Last().arrivalTime -
|
||||
ticketsDetails.OrderBy(td => td.order).First().departureTime;
|
||||
@ -451,8 +458,8 @@ public class GetPaymentLinkCommandHandler :
|
||||
Currency = detail.currency,
|
||||
VehicleEnrollmentId = ve.Id
|
||||
};
|
||||
})
|
||||
.ToArray()
|
||||
}).ToArray(),
|
||||
AccountId = account?.Id
|
||||
};
|
||||
|
||||
entity = await _unitOfWork.TicketGroupRepository.AddOneAsync(
|
||||
|
@ -148,7 +148,7 @@ public class AddTicketGroupCommandHandler :
|
||||
var vehicleEnrollments = (await _unitOfWork.VehicleEnrollmentRepository
|
||||
.GetPageAsync(
|
||||
e => vehicleEnrollmentGuids.Contains(e.Guid),
|
||||
e => e.Vehicle,
|
||||
e => e.Vehicle.Company,
|
||||
1, vehicleEnrollmentGuids.Count(), cancellationToken))
|
||||
.Items;
|
||||
|
||||
@ -416,7 +416,6 @@ public class AddTicketGroupCommandHandler :
|
||||
1, vehicleEnrollmentGuids.Count(), cancellationToken))
|
||||
.Items;
|
||||
|
||||
|
||||
var routeAddressGuids =
|
||||
request.Tickets.Select(t => t.DepartureRouteAddressGuid).Concat(
|
||||
request.Tickets.Select(t => t.ArrivalRouteAddressGuid));
|
||||
|
@ -85,6 +85,14 @@ public class GetTicketGroupQueryHandler :
|
||||
1, vehicleIds.Count(), cancellationToken))
|
||||
.Items;
|
||||
|
||||
var account = await _unitOfWork.AccountRepository.GetOneAsync(
|
||||
a => a.Id == ticketGroup.AccountId, cancellationToken);
|
||||
|
||||
if (ticketGroup.AccountId != null)
|
||||
{
|
||||
ticketGroup.Account = account;
|
||||
}
|
||||
|
||||
foreach (var ve in vehicleEnrollments)
|
||||
{
|
||||
ve.Vehicle = vehicles.Single(v => v.Id == ve.VehicleId);
|
||||
|
@ -32,6 +32,8 @@ public record GetTicketGroupsPageQuery : IRequest<PaginatedList<TicketGroupDto>>
|
||||
|
||||
public TimeSpan? TravelTimeLessThanOrEqualTo { get; set; }
|
||||
|
||||
public Guid? AccountGuid { get; set; }
|
||||
|
||||
// TODO: Add filtering parametetrs listed below. It is hard to
|
||||
// be done because of pagination.
|
||||
|
||||
|
@ -76,6 +76,9 @@ public class GetTicketGroupsPageQueryHandler :
|
||||
: true) &&
|
||||
(request.TravelTimeLessThanOrEqualTo != null
|
||||
? e.TravelTime <= request.TravelTimeLessThanOrEqualTo
|
||||
: true) &&
|
||||
(request.AccountGuid != null
|
||||
? e.Account.Guid == request.AccountGuid
|
||||
: true),
|
||||
e => e.Tickets,
|
||||
request.PageNumber, request.PageSize, cancellationToken);
|
||||
@ -123,6 +126,22 @@ public class GetTicketGroupsPageQueryHandler :
|
||||
1, vehicleIds.Count(), cancellationToken))
|
||||
.Items;
|
||||
|
||||
var accountIds =
|
||||
ticketGroups.Select(tg => tg.AccountId);
|
||||
var accounts = (await _unitOfWork.AccountRepository
|
||||
.GetPageAsync(
|
||||
a => accountIds.Contains(a.Id),
|
||||
1, accountIds.Count(), cancellationToken))
|
||||
.Items;
|
||||
|
||||
foreach (var tg in ticketGroups)
|
||||
{
|
||||
if (tg.AccountId != null)
|
||||
{
|
||||
tg.Account = accounts.Single(a => a.Id == tg.AccountId);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var ve in vehicleEnrollments)
|
||||
{
|
||||
ve.Vehicle = vehicles.Single(v => v.Id == ve.VehicleId);
|
||||
@ -137,8 +156,8 @@ public class GetTicketGroupsPageQueryHandler :
|
||||
}
|
||||
|
||||
|
||||
// TODO: Replace with AutoMapper resolvers
|
||||
// Convert currency and apply session time zone
|
||||
// TODO: Replace with AutoMapper resolvers.
|
||||
// Convert currency and apply session time zone.
|
||||
|
||||
var convertTasks = new List<Task>();
|
||||
var processedRouteAddressDetailIds = new HashSet<long>();
|
||||
|
21
src/Application/TicketGroups/TicketGroupAccountDto.cs
Normal file
21
src/Application/TicketGroups/TicketGroupAccountDto.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using cuqmbr.TravelGuide.Application.Common.Mappings;
|
||||
using cuqmbr.TravelGuide.Domain.Entities;
|
||||
|
||||
namespace cuqmbr.TravelGuide.Application.TicketGroups;
|
||||
|
||||
public sealed class TicketGroupAccountDto : IMapFrom<Account>
|
||||
{
|
||||
public Guid Uuid { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public void Mapping(MappingProfile profile)
|
||||
{
|
||||
profile.CreateMap<Account, TicketGroupAccountDto>()
|
||||
.ForMember(
|
||||
d => d.Uuid,
|
||||
opt => opt.MapFrom(s => s.Guid));
|
||||
}
|
||||
}
|
@ -39,6 +39,7 @@ public sealed class TicketGroupDto : IMapFrom<TicketGroup>
|
||||
|
||||
public decimal Cost { get; set; }
|
||||
|
||||
public TicketGroupAccountDto? Account { get; set; }
|
||||
|
||||
public ICollection<TicketGroupVehicleEnrollmentDto> Enrollments { get; set; }
|
||||
|
||||
|
@ -19,4 +19,6 @@ public sealed class GetTicketGroupsPageFilterViewModel
|
||||
public TimeSpan? TravelTimeGreaterThanOrEqualTo { get; set; }
|
||||
|
||||
public TimeSpan? TravelTimeLessThanOrEqualTo { get; set; }
|
||||
|
||||
public Guid? AccountUuid { get; set; }
|
||||
}
|
||||
|
@ -18,4 +18,6 @@ public sealed class Account : EntityBase
|
||||
public Employee? Employee { get; set; }
|
||||
|
||||
public Company? Company { get; set; }
|
||||
|
||||
public ICollection<TicketGroup> TicketGroups { get; set; }
|
||||
}
|
||||
|
@ -24,4 +24,9 @@ public sealed class TicketGroup : EntityBase
|
||||
|
||||
|
||||
public ICollection<Ticket> Tickets { get; set; }
|
||||
|
||||
|
||||
public long? AccountId { get; set; }
|
||||
|
||||
public Account? Account { get; set; }
|
||||
}
|
||||
|
@ -119,7 +119,8 @@ public class TicketGroupsController : ControllerBase
|
||||
TravelTimeGreaterThanOrEqualTo =
|
||||
filterQuery.TravelTimeGreaterThanOrEqualTo,
|
||||
TravelTimeLessThanOrEqualTo =
|
||||
filterQuery.TravelTimeLessThanOrEqualTo
|
||||
filterQuery.TravelTimeLessThanOrEqualTo,
|
||||
AccountGuid = filterQuery.AccountUuid
|
||||
},
|
||||
cancellationToken);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class CompanyConfiguration : BaseConfiguration<Company>
|
||||
"fk_" +
|
||||
$"{builder.Metadata.GetTableName()}_" +
|
||||
$"{builder.Property(c => c.AccountId).Metadata.GetColumnName()}")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.OnDelete(DeleteBehavior.ClientNoAction);
|
||||
|
||||
builder
|
||||
.HasIndex(c => c.AccountId)
|
||||
|
@ -69,7 +69,7 @@ public class EmployeeConfiguration : BaseConfiguration<Employee>
|
||||
"fk_" +
|
||||
$"{builder.Metadata.GetTableName()}_" +
|
||||
$"{builder.Property(e => e.CompanyId).Metadata.GetColumnName()}")
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
.OnDelete(DeleteBehavior.ClientNoAction);
|
||||
|
||||
builder
|
||||
.HasIndex(e => e.CompanyId)
|
||||
|
@ -89,5 +89,29 @@ public class TicketGroupConfiguration : BaseConfiguration<TicketGroup>
|
||||
.HasColumnName("travel_time")
|
||||
.HasColumnType("interval")
|
||||
.IsRequired(true);
|
||||
|
||||
|
||||
builder
|
||||
.Property(tg => tg.AccountId)
|
||||
.HasColumnName("account_id")
|
||||
.HasColumnType("bigint")
|
||||
.IsRequired(false);
|
||||
|
||||
builder
|
||||
.HasOne(tg => tg.Account)
|
||||
.WithMany(a => a.TicketGroups)
|
||||
.HasForeignKey(tg => tg.AccountId)
|
||||
.HasConstraintName(
|
||||
"fk_" +
|
||||
$"{builder.Metadata.GetTableName()}_" +
|
||||
$"{builder.Property(c => c.AccountId).Metadata.GetColumnName()}")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder
|
||||
.HasIndex(c => c.AccountId)
|
||||
.HasDatabaseName(
|
||||
"ix_" +
|
||||
$"{builder.Metadata.GetTableName()}_" +
|
||||
$"{builder.Property(c => c.AccountId).Metadata.GetColumnName()}");
|
||||
}
|
||||
}
|
||||
|
1359
src/Persistence/PostgreSql/Migrations/20250530101737_Add_navigation_from_Ticket_Group_to_Account.Designer.cs
generated
Normal file
1359
src/Persistence/PostgreSql/Migrations/20250530101737_Add_navigation_from_Ticket_Group_to_Account.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,114 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Persistence.PostgreSql.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Add_navigation_from_Ticket_Group_to_Account : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_companies_account_id",
|
||||
schema: "application",
|
||||
table: "companies");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_employees_company_id",
|
||||
schema: "application",
|
||||
table: "employees");
|
||||
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "account_id",
|
||||
schema: "application",
|
||||
table: "ticket_groups",
|
||||
type: "bigint",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_ticket_groups_account_id",
|
||||
schema: "application",
|
||||
table: "ticket_groups",
|
||||
column: "account_id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_companies_account_id",
|
||||
schema: "application",
|
||||
table: "companies",
|
||||
column: "account_id",
|
||||
principalSchema: "application",
|
||||
principalTable: "accounts",
|
||||
principalColumn: "id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_employees_company_id",
|
||||
schema: "application",
|
||||
table: "employees",
|
||||
column: "company_id",
|
||||
principalSchema: "application",
|
||||
principalTable: "companies",
|
||||
principalColumn: "id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_ticket_groups_account_id",
|
||||
schema: "application",
|
||||
table: "ticket_groups",
|
||||
column: "account_id",
|
||||
principalSchema: "application",
|
||||
principalTable: "accounts",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_companies_account_id",
|
||||
schema: "application",
|
||||
table: "companies");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_employees_company_id",
|
||||
schema: "application",
|
||||
table: "employees");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_ticket_groups_account_id",
|
||||
schema: "application",
|
||||
table: "ticket_groups");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_ticket_groups_account_id",
|
||||
schema: "application",
|
||||
table: "ticket_groups");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "account_id",
|
||||
schema: "application",
|
||||
table: "ticket_groups");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_companies_account_id",
|
||||
schema: "application",
|
||||
table: "companies",
|
||||
column: "account_id",
|
||||
principalSchema: "application",
|
||||
principalTable: "accounts",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_employees_company_id",
|
||||
schema: "application",
|
||||
table: "employees",
|
||||
column: "company_id",
|
||||
principalSchema: "application",
|
||||
principalTable: "companies",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
@ -729,6 +729,10 @@ namespace Persistence.PostgreSql.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseSequence(b.Property<long>("Id"), "ticket_groups_id_sequence");
|
||||
|
||||
b.Property<long?>("AccountId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("account_id");
|
||||
|
||||
b.Property<Guid>("Guid")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("uuid");
|
||||
@ -780,6 +784,9 @@ namespace Persistence.PostgreSql.Migrations
|
||||
b.HasAlternateKey("Guid")
|
||||
.HasName("altk_ticket_groups_uuid");
|
||||
|
||||
b.HasIndex("AccountId")
|
||||
.HasDatabaseName("ix_ticket_groups_account_id");
|
||||
|
||||
b.ToTable("ticket_groups", "application", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_ticket_groups_passanger_sex", "passanger_sex IN ('male', 'female')");
|
||||
@ -1053,7 +1060,7 @@ namespace Persistence.PostgreSql.Migrations
|
||||
b.HasOne("cuqmbr.TravelGuide.Domain.Entities.Account", "Account")
|
||||
.WithOne("Company")
|
||||
.HasForeignKey("cuqmbr.TravelGuide.Domain.Entities.Company", "AccountId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.ClientNoAction)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_companies_account_id");
|
||||
|
||||
@ -1072,7 +1079,7 @@ namespace Persistence.PostgreSql.Migrations
|
||||
b.HasOne("cuqmbr.TravelGuide.Domain.Entities.Company", "Company")
|
||||
.WithMany("Employees")
|
||||
.HasForeignKey("CompanyId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.OnDelete(DeleteBehavior.ClientNoAction)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_employees_company_id");
|
||||
|
||||
@ -1196,6 +1203,17 @@ namespace Persistence.PostgreSql.Migrations
|
||||
b.Navigation("VehicleEnrollment");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("cuqmbr.TravelGuide.Domain.Entities.TicketGroup", b =>
|
||||
{
|
||||
b.HasOne("cuqmbr.TravelGuide.Domain.Entities.Account", "Account")
|
||||
.WithMany("TicketGroups")
|
||||
.HasForeignKey("AccountId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.HasConstraintName("fk_ticket_groups_account_id");
|
||||
|
||||
b.Navigation("Account");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("cuqmbr.TravelGuide.Domain.Entities.Vehicle", b =>
|
||||
{
|
||||
b.HasOne("cuqmbr.TravelGuide.Domain.Entities.Company", "Company")
|
||||
@ -1259,6 +1277,8 @@ namespace Persistence.PostgreSql.Migrations
|
||||
b.Navigation("Employee");
|
||||
|
||||
b.Navigation("RefreshTokens");
|
||||
|
||||
b.Navigation("TicketGroups");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("cuqmbr.TravelGuide.Domain.Entities.Address", b =>
|
||||
|
Loading…
Reference in New Issue
Block a user