Skip to content

Commit

Permalink
MVP import/export endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Jan 14, 2025
1 parent 25b5532 commit 420f89f
Show file tree
Hide file tree
Showing 27 changed files with 4,966 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ src/Gameboard.Api/wwwroot/temp/*

# stuff that gameboard makes as part of being itself
src/Gameboard.Api/wwwroot/export/*
src/Gameboard.Api/wwwroot/import/*
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ private void RegisterDefaultEntityModels(IFixture fixture)
fixture.Register(() => new PracticeModeSettings
{
Id = fixture.Create<string>(),
CertificateHtmlTemplate = null,
DefaultPracticeSessionLengthMinutes = 60,
IntroTextMarkdown = null,
SuggestedSearches = ""
SuggestedSearches = string.Empty
});

fixture.Register<Data.Sponsor>(() => new()
Expand Down
6 changes: 6 additions & 0 deletions src/Gameboard.Api/Common/Services/JsonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IJsonService
string Serialize<T>(T obj) where T : class;
Task SerializeAsync<T>(T obj, Stream stream) where T : class;
T Deserialize<T>(string json) where T : class;
ValueTask<T> DeserializeAsync<T>(Stream stream) where T : class;
}

internal class JsonService : IJsonService
Expand Down Expand Up @@ -61,6 +62,11 @@ public T Deserialize<T>(string json) where T : class
return JsonSerializer.Deserialize<T>(json, Options);
}

public ValueTask<T> DeserializeAsync<T>(Stream stream) where T : class
{
return JsonSerializer.DeserializeAsync<T>(stream);
}

public string Serialize<T>(T obj) where T : class
{
return JsonSerializer.Serialize<T>(obj, Options);
Expand Down
15 changes: 10 additions & 5 deletions src/Gameboard.Api/Common/Services/ZipService.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;

namespace Gameboard.Api.Common.Services;

public interface IZipService
{
public ZipArchive Zip(string outputPath, string[] filePaths, string relativeRoot = null);
public ZipArchive ZipDirectory(string outputPath, string directoryPath);
public Task<ZipArchive> ZipDirectory(string outputPath, string directoryPath);
}

internal sealed class ZipService : IZipService
{
public ZipArchive ZipDirectory(string outputPath, string directoryPath)
public async Task<ZipArchive> ZipDirectory(string outputPath, string directoryPath)
{
using var stream = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite);
var archive = new ZipArchive(stream, ZipArchiveMode.Create);
using var archive = new ZipArchive(stream, ZipArchiveMode.Create);
var fullDirectoryPath = Path.GetFullPath(directoryPath);

foreach (var file in Directory.EnumerateFileSystemEntries(fullDirectoryPath))
foreach (var file in Directory.GetFiles(fullDirectoryPath, "*", SearchOption.AllDirectories))
{
archive.CreateEntryFromFile(file, Path.GetRelativePath(fullDirectoryPath, file));
using var fileStream = File.Open(file, FileMode.Open, FileAccess.Read);
using var fileReader = new StreamReader(fileStream);
var entry = archive.CreateEntry(Path.GetRelativePath(fullDirectoryPath, file));
using var entryStream = entry.Open();
await fileStream.CopyToAsync(entryStream);
}

return archive;
Expand Down
6 changes: 3 additions & 3 deletions src/Gameboard.Api/Data/Entities/FeedbackTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class FeedbackTemplate : IEntity

public required string CreatedByUserId { get; set; }
public Data.User CreatedByUser { get; set; }
public required ICollection<FeedbackSubmission> Submissions { get; set; } = [];
public required ICollection<Data.Game> UseAsFeedbackTemplateForGames { get; set; } = [];
public required ICollection<Data.Game> UseAsFeedbackTemplateForGameChallenges { get; set; } = [];
public ICollection<FeedbackSubmission> Submissions { get; set; } = [];
public ICollection<Data.Game> UseAsFeedbackTemplateForGames { get; set; } = [];
public ICollection<Data.Game> UseAsFeedbackTemplateForGameChallenges { get; set; } = [];
}
1 change: 0 additions & 1 deletion src/Gameboard.Api/Data/Entities/PracticeModeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class PracticeModeSettings : IEntity
{
public string Id { get; set; }
public int? AttemptLimit { get; set; }
public string CertificateHtmlTemplate { get; set; }
public int DefaultPracticeSessionLengthMinutes { get; set; }
public string IntroTextMarkdown { get; set; }
public int? MaxConcurrentPracticeSessions { get; set; }
Expand Down
Loading

0 comments on commit 420f89f

Please sign in to comment.