a better result
This commit is contained in:
53
src/isnd/Data/Catalog/PackageRegistration.cs
Normal file
53
src/isnd/Data/Catalog/PackageRegistration.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using isnd.Data.Packages;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class PackageRegistration : Permalink
|
||||
{
|
||||
|
||||
public PackageRegistration(string url) : base(url)
|
||||
{
|
||||
Items = new List<CatalogPage>();
|
||||
}
|
||||
|
||||
public PackageRegistration(string bid, string id, string apiBase, IEnumerable<Packages.Package> pkgs) : base(bid + $"/{id}/index.json")
|
||||
{
|
||||
Items = new List<CatalogPage>();
|
||||
long cnid = 0;
|
||||
var pkgsGroups = pkgs.GroupBy(l => l.Id);
|
||||
// Pour tous les groupes par Id
|
||||
foreach (var gsp in pkgsGroups)
|
||||
{
|
||||
var pkgsbi = gsp.ToArray();
|
||||
List<PackageVersion> versions = new List<PackageVersion>();
|
||||
|
||||
foreach(var l in pkgsbi.Select(p => p.Versions))
|
||||
{
|
||||
versions.AddRange(l);
|
||||
foreach (var pv in l)
|
||||
{
|
||||
if (pv.CommitNId> cnid)
|
||||
{
|
||||
cnid = pv.CommitNId;
|
||||
}
|
||||
}
|
||||
}
|
||||
Items.Add(new CatalogPage(bid, gsp.Key, apiBase, versions));
|
||||
}
|
||||
CommitId = cnid.ToString();
|
||||
}
|
||||
|
||||
[JsonProperty("count")]
|
||||
public int Count { get => Items.Count; }
|
||||
|
||||
[JsonProperty("items")]
|
||||
public List<CatalogPage> Items { get; set; }
|
||||
|
||||
public string CommitId { get; set; }
|
||||
public DateTimeOffset CommitTimeStamp { get; internal set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user