|
| 1 | +using TASVideos.WikiEngine; |
| 2 | + |
| 3 | +namespace TASVideos.WikiModules; |
| 4 | + |
| 5 | +[WikiModule(ModuleNames.PublicationsByPlatform)] |
| 6 | +public class PublicationsByPlatform(IGameSystemService platforms, IClassService classes) : WikiViewComponent |
| 7 | +{ |
| 8 | + public IReadOnlyList<(string DisplayName, string Code)> Platforms { get; private set; } = null!; |
| 9 | + |
| 10 | + public IReadOnlyCollection<PublicationClass> PubClasses { get; set; } = null!; |
| 11 | + |
| 12 | + public async Task<IViewComponentResult> InvokeAsync(IList<string> groupings) |
| 13 | + { |
| 14 | + var extant = (await platforms.GetAll()).ToList(); |
| 15 | + List<IReadOnlyList<SystemsResponse>> rows = []; |
| 16 | + void ProcessGroup(string groupStr) |
| 17 | + { |
| 18 | + List<SystemsResponse> row = []; |
| 19 | + foreach (var idStr in groupStr.Split('-')) |
| 20 | + { |
| 21 | + var found = extant.FirstOrDefault(sys => sys.Code.Equals(idStr, StringComparison.OrdinalIgnoreCase)); |
| 22 | + if (found is null) |
| 23 | + { |
| 24 | + // ignore, TODO log? |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + extant.Remove(found); |
| 29 | + row.Add(found); |
| 30 | + } |
| 31 | + |
| 32 | + rows.Add(row); |
| 33 | + } |
| 34 | + |
| 35 | + foreach (var groupStr in groupings) |
| 36 | + { |
| 37 | + ProcessGroup(groupStr); |
| 38 | + } |
| 39 | + |
| 40 | + Platforms = extant.Select(static sys => (sys.DisplayName, sys.Code)) |
| 41 | + .Concat(rows.Select(static row => ( |
| 42 | + DisplayName: string.Join(" / ", row.Select(static sys => sys.DisplayName)), |
| 43 | + Code: string.Join("-", row.Select(static sys => sys.Code)) |
| 44 | + ))) |
| 45 | + .OrderBy(static tuple => tuple.DisplayName) |
| 46 | + .ToArray(); |
| 47 | + PubClasses = await classes.GetAll(); |
| 48 | + return View(); |
| 49 | + } |
| 50 | +} |
0 commit comments