Skip to content

Commit

Permalink
Add AdlerEngine URL to BackendConfig and implement CreateWorldResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
philgei committed Oct 24, 2023
1 parent 8892d87 commit f524cc6
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
3 changes: 2 additions & 1 deletion AdLerBackend.API/Controllers/Worlds/WorldsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public async Task<ActionResult<GetWorldOverviewResponse>> GetWorldsForUser([From
/// <returns></returns>
[HttpPost]
[DisableRequestSizeLimit]
public async Task<bool> CreateWorld(IFormFile backupFile, IFormFile atfFile, [FromHeader] string token)
public async Task<CreateWorldResponse> CreateWorld(IFormFile backupFile, IFormFile atfFile,
[FromHeader] string token)
{
// Log the Request to the console
Console.WriteLine("Uploading started at " + DateTime.Now);
Expand Down
3 changes: 2 additions & 1 deletion AdLerBackend.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"applicationUrl": "https://localhost:3001;http://localhost:3000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_ADLER_MOODLEURL": "http://localhost:8085"
"ASPNETCORE_ADLER_MOODLEURL": "http://localhost:8085",
"ASPNETCORE_ADLER_ADLERENGINEURL": "http://localhost:3001"
}
},
"AdLerBackendProduction": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public void AddAndValidateBackendConfig_WhenCalledWithValidConfig_ShouldNotThrow
{"ASPNETCORE_DBUSER", "test_user"},
{"ASPNETCORE_DBNAME", "test_db_name"},
{"ASPNETCORE_DBHOST", "localhost"},
{"ASPNETCORE_DBPORT", "5432"}
{"ASPNETCORE_DBPORT", "5432"},
{"ASPNETCORE_ADLER_ADLERENGINEURL", "https://adlerengine.example.com"}
};
var configuration = new ConfigurationBuilder().AddInMemoryCollection(configData).Build();

Expand All @@ -41,6 +42,7 @@ public void AddAndValidateBackendConfig_WhenCalledWithValidConfig_ShouldNotThrow
Assert.That(myConfig.DbName, Is.EqualTo("test_db_name"));
Assert.That(myConfig.DbHost, Is.EqualTo("localhost"));
Assert.That(myConfig.DbPort, Is.EqualTo("5432"));
Assert.That(myConfig.AdLerEngineUrl, Is.EqualTo("https://adlerengine.example.com"));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using AdLerBackend.Application.Common.Interfaces;
using AdLerBackend.Application.Common.Responses.LMSAdapter;
using AdLerBackend.Application.Common.Responses.World;
using AdLerBackend.Application.Configuration;
using AdLerBackend.Application.LMS.GetUserData;
using AdLerBackend.Application.World.WorldManagement.UploadWorld;
using AdLerBackend.Domain.Entities;
using AdLerBackend.Infrastructure.Services;
using AutoBogus;
using MediatR;
using Microsoft.Extensions.Options;
using NSubstitute;

#pragma warning disable CS8618
Expand All @@ -18,6 +20,7 @@ namespace AdLerBackend.Application.UnitTests.World.WorldManagement.UploadWorld;

public class UploadWorldUseCaseTest
{
private IOptions<BackendConfig> _configuration;
private IFileAccess _fileAccess;
private ILMS _ilms;
private ILmsBackupProcessor _lmsBackupProcessor;
Expand All @@ -28,6 +31,8 @@ public class UploadWorldUseCaseTest
[SetUp]
public void Setup()
{
_configuration = Options.Create(new BackendConfig {MoodleUrl = "http://localhost"});

_lmsBackupProcessor = Substitute.For<ILmsBackupProcessor>();
_mediator = Substitute.For<IMediator>();
_fileAccess = Substitute.For<IFileAccess>();
Expand Down Expand Up @@ -60,7 +65,7 @@ public async Task Handle_Valid_TriggersUpload()
// Arrange
var systemUnderTest =
new UploadWorldUseCase(_lmsBackupProcessor, _mediator, _fileAccess, _worldRepository,
new SerializationService(), _ilms);
new SerializationService(), _ilms, _configuration);

_ilms.UploadCourseWorldToLMS(Arg.Any<string>(), Arg.Any<Stream>()).Returns(new LMSCourseCreationResponse
{
Expand Down Expand Up @@ -132,7 +137,7 @@ public async Task Handle_ValidNoH5p_TriggersUpload()
// Arrange
var systemUnderTest =
new UploadWorldUseCase(_lmsBackupProcessor, _mediator, _fileAccess, _worldRepository,
_serialization, _ilms);
_serialization, _ilms, _configuration);

_mediator.Send(Arg.Any<GetLMSUserDataCommand>()).Returns(new LMSUserDataResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AdLerBackend.Application.Common.Responses.World;

public class CreateWorldResponse
{
public string WorldNameInLms { get; set; }
public string WorldLmsUrl { get; set; }
public string World3DUrl { get; set; } = "Coming soon :)";
}
4 changes: 4 additions & 0 deletions AdLerBackend.Application/Configuration/BackendConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public class BackendConfig
[ConfigurationKeyName("ASPNETCORE_ADLER_MOODLEURL")]
public string MoodleUrl { get; set; }

[RequiredIfProduction]
[ConfigurationKeyName("ASPNETCORE_ADLER_ADLERENGINEURL")]
public string AdLerEngineUrl { get; set; }

[RequiredIfProduction]
[ConfigurationKeyName("ASPNETCORE_DBPASSWORD")]
public string DbPassword { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma warning disable CS8618
using AdLerBackend.Application.Common;
using AdLerBackend.Application.Common.Responses.World;

namespace AdLerBackend.Application.World.WorldManagement.UploadWorld;

public record UploadWorldCommand : CommandWithToken<bool>
public record UploadWorldCommand : CommandWithToken<CreateWorldResponse>
{
public Stream BackupFileStream { get; set; }
public Stream ATFFileStream { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
using AdLerBackend.Application.Common.Interfaces;
using AdLerBackend.Application.Common.Responses.LMSAdapter;
using AdLerBackend.Application.Common.Responses.World;
using AdLerBackend.Application.Configuration;
using AdLerBackend.Application.LMS.GetUserData;
using AdLerBackend.Application.World.ValidateATFFile;
using AdLerBackend.Domain.Entities;
using MediatR;
using Microsoft.Extensions.Options;

namespace AdLerBackend.Application.World.WorldManagement.UploadWorld;

public class UploadWorldUseCase : IRequestHandler<UploadWorldCommand, bool>
public class UploadWorldUseCase : IRequestHandler<UploadWorldCommand, CreateWorldResponse>
{
private readonly BackendConfig _configuration;
private readonly IFileAccess _fileAccess;
private readonly ILMS _lms;
private readonly ILmsBackupProcessor _lmsBackupProcessor;
Expand All @@ -19,17 +22,20 @@ public class UploadWorldUseCase : IRequestHandler<UploadWorldCommand, bool>
private readonly IWorldRepository _worldRepository;

public UploadWorldUseCase(ILmsBackupProcessor lmsBackupProcessor, IMediator mediator,
IFileAccess fileAccess, IWorldRepository worldRepository, ISerialization serialization, ILMS lms)
IFileAccess fileAccess, IWorldRepository worldRepository, ISerialization serialization, ILMS lms,
IOptions<BackendConfig> configuration)
{
_lmsBackupProcessor = lmsBackupProcessor;
_mediator = mediator;
_fileAccess = fileAccess;
_worldRepository = worldRepository;
_serialization = serialization;
_lms = lms;

_configuration = configuration.Value;
}

public async Task<bool> Handle(UploadWorldCommand request, CancellationToken cancellationToken)
public async Task<CreateWorldResponse> Handle(UploadWorldCommand request, CancellationToken cancellationToken)
{
// TODO: Skip Validation for development purposes
//await ValidateAtfFile(request, cancellationToken);
Expand Down Expand Up @@ -63,7 +69,12 @@ public async Task<bool> Handle(UploadWorldCommand request, CancellationToken can

await _worldRepository.AddAsync(courseEntity);

return true;
return new CreateWorldResponse
{
World3DUrl = _configuration.AdLerEngineUrl ?? "Adler Engine URL not set",
WorldLmsUrl = _configuration.MoodleUrl + "/course/view.php?id=" + lmsCourseCreationResponse.CourseLmsId,
WorldNameInLms = courseEntity.Name
};
}

private async Task<LMSUserDataResponse> GetUserDataFromLms(UploadWorldCommand request,
Expand Down

0 comments on commit f524cc6

Please sign in to comment.