Skip to content

Commit

Permalink
feat(qrcode): basic support for static redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenrikur committed Jul 26, 2024
1 parent 6d8a0e0 commit e79f079
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Eurofurence.App.Server.Services.Abstractions.QrCode
{
public interface IQrCodeService
{
string GetTarget(string id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Eurofurence.App.Server.Services.Abstractions.QrCode
{
public class QrCodeConfiguration
{
public Dictionary<string, string> Targets { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Eurofurence.App.Server.Services.Abstractions.Maps;
using Eurofurence.App.Server.Services.Abstractions.MinIO;
using Eurofurence.App.Server.Services.Abstractions.PushNotifications;
using Eurofurence.App.Server.Services.Abstractions.QrCode;
using Eurofurence.App.Server.Services.Abstractions.Telegram;
using Eurofurence.App.Server.Services.Abstractions.Validation;
using Eurofurence.App.Server.Services.Announcements;
Expand Down Expand Up @@ -121,6 +122,7 @@ private void RegisterServices(ContainerBuilder builder)
builder.RegisterType<PushNotificationChannelStatisticsService>()
.As<IPushNotificationChannelStatisticsService>();
builder.RegisterType<PushNotificiationChannelService>().As<IPushNotificiationChannelService>();
builder.RegisterType<QrCodeService>().As<IQrCodeService>();
builder.RegisterType<StorageServiceFactory>().As<IStorageServiceFactory>();
builder.RegisterType<TableRegistrationService>().As<ITableRegistrationService>();
builder.RegisterType<TelegramMessageBroker>()
Expand Down
21 changes: 21 additions & 0 deletions src/Eurofurence.App.Server.Services/QrCode/QrCodeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Eurofurence.App.Server.Services.Abstractions.QrCode;
using Microsoft.Extensions.Options;

namespace Eurofurence.App.Server.Services.Communication
{
public class QrCodeService : IQrCodeService
{
private readonly QrCodeConfiguration _qrCodeConfiguration;

public QrCodeService(
IOptionsMonitor<QrCodeConfiguration> qrCodeConfiguration
)
{
_qrCodeConfiguration = qrCodeConfiguration.CurrentValue;
}
public string GetTarget(string id)
{
return _qrCodeConfiguration.Targets[id];
}
}
}
32 changes: 32 additions & 0 deletions src/Eurofurence.App.Server.Web/Controllers/QrCodeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Eurofurence.App.Server.Services.Abstractions.QrCode;
using Microsoft.AspNetCore.Mvc;
using System;

namespace Eurofurence.App.Server.Web.Controllers
{
[Route("qr")]
public class QrCodeController : BaseController
{
private readonly IQrCodeService _qrCodeService;

public QrCodeController(
IQrCodeService qrCodeService
)
{
_qrCodeService = qrCodeService;
}

[HttpGet("{targetId}")]
public ActionResult GetTargetRedirect(string targetId)
{
try
{
return new RedirectResult(_qrCodeService.GetTarget(targetId));
}
catch (Exception)
{
return NotFound();
}
}
}
}
3 changes: 3 additions & 0 deletions src/Eurofurence.App.Server.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using Microsoft.AspNetCore.Authentication;
using Minio;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using Eurofurence.App.Server.Services.Abstractions.QrCode;

namespace Eurofurence.App.Server.Web
{
Expand Down Expand Up @@ -152,6 +153,8 @@ public void ConfigureServices(IServiceCollection services)

});

services.Configure<QrCodeConfiguration>(Configuration.GetSection("QrCode"));

services.Configure<IdentityOptions>(Configuration.GetSection("Identity"));
services.Configure<AuthorizationOptions>(Configuration.GetSection("Authorization"));
services.ConfigureOptions<ConfigureOAuth2IntrospectionOptions>();
Expand Down
8 changes: 8 additions & 0 deletions src/Eurofurence.App.Server.Web/appsettings.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,13 @@
"secretKey": "minioVerySecretKey",
"secure": false,
"bucket": "ef-mobile-app-local"
},
"QrCode": {
"Targets": {
"getWindowsApp": "",
"getAndroidApp": "",
"getiPhoneApp": "",
"aatablereg": ""
}
}
}
Empty file.

0 comments on commit e79f079

Please sign in to comment.