Skip to content

Commit

Permalink
made api less complex, changed to MongoDB instead of PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
saschaheinl committed Oct 10, 2024
1 parent aaa1c8b commit d71e49b
Show file tree
Hide file tree
Showing 48 changed files with 763 additions and 673 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/deploy-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ jobs:
--region europe-west1 \
--allow-unauthenticated \
--set-env-vars ASPNETCORE_ENVIRONMENT=${{ secrets.ASPNETCORE_ENVIRONMENT }},\
POSTGRESQL_CONNECTION_STRING="Server=/cloudsql/${{ secrets.CLOUD_SQL_CONNECTION_NAME }};Database=${{ secrets.DB_NAME }};User Id=${{ secrets.DB_USER }};Password=${{ secrets.DB_PASSWORD }};",\
GOOGLE_PROJECT_NAME=${{ secrets.GOOGLE_PROJECT_NAME }} \
--add-cloudsql-instances ${{ secrets.CLOUD_SQL_CONNECTION_NAME }}
MONGO_DB_CONNECTION_STRING="${{ secrets.MONGO_DB_CONNECTION_STRING }}",\
GOOGLE_PROJECT_NAME=${{ secrets.GOOGLE_PROJECT_NAME }}
41 changes: 0 additions & 41 deletions API/TVR.Bundesliga.API.Contracts/Requests/CreateTicketRequest.cs

This file was deleted.

14 changes: 14 additions & 0 deletions API/TVR.Bundesliga.API.Contracts/Requests/CreateV2TicketRequest.cs
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.

Binary file not shown.
6 changes: 0 additions & 6 deletions API/TVR.Bundesliga.API.Core/Commands/AddNewEventCommand.cs

This file was deleted.

6 changes: 0 additions & 6 deletions API/TVR.Bundesliga.API.Core/Commands/AddNewGuestCommand.cs

This file was deleted.

12 changes: 0 additions & 12 deletions API/TVR.Bundesliga.API.Core/Commands/AddNewTicketCommand.cs

This file was deleted.

11 changes: 11 additions & 0 deletions API/TVR.Bundesliga.API.Core/Commands/AddV2TicketCommand.cs
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.

6 changes: 0 additions & 6 deletions API/TVR.Bundesliga.API.Core/Queries/GetAllEventsQuery.cs

This file was deleted.

6 changes: 0 additions & 6 deletions API/TVR.Bundesliga.API.Core/Queries/GetAllGuestsQuery.cs

This file was deleted.

6 changes: 0 additions & 6 deletions API/TVR.Bundesliga.API.Core/Queries/GetEventByIdQuery.cs

This file was deleted.

17 changes: 0 additions & 17 deletions API/TVR.Bundesliga.API.Core/Queries/GetEventsByTimeframeQuery.cs

This file was deleted.

2 changes: 1 addition & 1 deletion API/TVR.Bundesliga.API.Core/Queries/GetTicketByIdQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace TVR.Bundesliga.API.Core.Queries;

public record GetTicketByIdQuery(int TicketId) : IRequest<Ticket?>;
public record GetTicketByIdQuery(string TicketId) : IRequest<V2Ticket>;
6 changes: 0 additions & 6 deletions API/TVR.Bundesliga.API.Core/Queries/SearchGuestQuery.cs

This file was deleted.

37 changes: 0 additions & 37 deletions API/TVR.Bundesliga.API.Core/UseCases/AddNewEventUseCase.cs

This file was deleted.

27 changes: 0 additions & 27 deletions API/TVR.Bundesliga.API.Core/UseCases/AddNewGuestUseCase.cs

This file was deleted.

44 changes: 0 additions & 44 deletions API/TVR.Bundesliga.API.Core/UseCases/AddNewTicketUseCase.cs

This file was deleted.

53 changes: 53 additions & 0 deletions API/TVR.Bundesliga.API.Core/UseCases/AddV2TicketUseCase.cs
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;
}
}
Loading

0 comments on commit d71e49b

Please sign in to comment.