-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace TVR.Bundesliga.API.Contracts.Requests; | ||
|
||
public class CreateV2TicketRequest(string guestName, string? guestEmail, int includedVisits, string createdBy) | ||
{ | ||
public string GuestName { get; set; } = guestName; | ||
|
||
public bool ShouldSendEmail { get; set; } = false; | ||
|
||
public string? GuestEmail { get; set; } = guestEmail; | ||
|
||
public int IncludedVisits { get; set; } = includedVisits; | ||
|
||
public string CreatedBy { get; set; } = createdBy; | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using MediatR; | ||
using TVR.Bundesliga.API.Domain.Models; | ||
|
||
namespace TVR.Bundesliga.API.Core.Commands; | ||
|
||
public record AddV2TicketCommand( | ||
string GuestName, | ||
bool ShouldSendEmail, | ||
string? GuestEmail, | ||
int IncludedVisits, | ||
string CreatedBy) : IRequest<V2Ticket>; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using MediatR; | ||
using MongoDB.Driver; | ||
using QRCoder; | ||
using TVR.Bundesliga.API.Core.Commands; | ||
using TVR.Bundesliga.API.Domain.Models; | ||
|
||
namespace TVR.Bundesliga.API.Core.UseCases; | ||
|
||
public class AddV2TicketUseCase(IMongoClient mongoClient) : IRequestHandler<AddV2TicketCommand, V2Ticket> | ||
{ | ||
public async Task<V2Ticket> Handle(AddV2TicketCommand request, CancellationToken cancellationToken) | ||
{ | ||
var name = request.GuestName; | ||
var includedVisits = request.IncludedVisits; | ||
var shouldSendEmail = request.ShouldSendEmail; | ||
var creator = request.CreatedBy; | ||
var mailAddress = string.Empty; | ||
if (shouldSendEmail) | ||
{ | ||
mailAddress = request.GuestEmail; | ||
} | ||
|
||
var ticketId = Guid.NewGuid(); | ||
var qrcodeGen = new QRCodeGenerator(); | ||
var data = qrcodeGen.CreateQrCode(ticketId.ToString(), QRCodeGenerator.ECCLevel.Q); | ||
var base64String = new Base64QRCode(data); | ||
var qrCodeDetails = new QrCodeDetails(string.Empty, base64String.GetGraphic(20)); | ||
var newTicket = new V2Ticket( | ||
ticketId.ToString(), | ||
name, | ||
mailAddress, | ||
includedVisits, | ||
includedVisits, | ||
0, | ||
shouldSendEmail, | ||
DateTimeOffset.UtcNow, | ||
creator, | ||
qrCodeDetails, | ||
[]); | ||
|
||
var dbName = Environment.GetEnvironmentVariable("MONGO_DB_DATABASE_NAME"); | ||
if (dbName is null) | ||
{ | ||
throw new ArgumentNullException(); | ||
} | ||
|
||
var database = mongoClient.GetDatabase(dbName); | ||
var collection = database.GetCollection<V2Ticket>("Tickets"); | ||
await collection.InsertOneAsync(newTicket, null, cancellationToken); | ||
|
||
return newTicket; | ||
} | ||
} |