WIP reg page
parent
14206ac477
commit
fececb327e
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class RegistrationPage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The URL to the registration page
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("@id"), JsonRequired]
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of registration leaves in the page
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("count"), JsonRequired]
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// no The array of registration leaves and their associate metadata
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("items")]
|
||||
|
||||
public RegistrationLeaf[] Items { get; set; }
|
||||
/// <summary>
|
||||
/// The highest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("upper"), JsonRequired]
|
||||
public Version Upper { get; set; }
|
||||
/// <summary>
|
||||
/// The lowest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("lower"), JsonRequired]
|
||||
public Version Lower { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL to the registration index
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("parent")]
|
||||
public string Parent { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class RegistrationPageIndex
|
||||
{
|
||||
[JsonProperty("count")]
|
||||
public int Count { get => Items?.Length ?? 0; }
|
||||
|
||||
[JsonProperty("items")]
|
||||
public RegistrationPage[] Items { get; set; }
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Data.Catalog
|
||||
{
|
||||
public class RegistrationPage
|
||||
{
|
||||
/*
|
||||
@id string yes The URL to the registration page
|
||||
count integer yes The number of registration leaves in the page
|
||||
items array of objects no The array of registration leaves and their associate metadata
|
||||
lower string yes The lowest SemVer 2.0.0 version in the page (inclusive)
|
||||
parent string no The URL to the registration index
|
||||
upper string yes The highest SemVer 2.0.0 version in the page (inclusive) */
|
||||
[JsonProperty("@id")]
|
||||
public string Id { get; set; }
|
||||
[JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[JsonProperty("items")]
|
||||
|
||||
public RegistrationLeaf[] Items { get; set; }
|
||||
|
||||
[JsonProperty("upper")]
|
||||
public Version Upper { get; set; }
|
||||
|
||||
[JsonProperty("lower")]
|
||||
public Version Lower { get; set; }
|
||||
|
||||
[JsonProperty("parent")]
|
||||
public string Parent { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -1,15 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using isn.abst;
|
||||
using isnd.Data;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Entities;
|
||||
|
||||
namespace isnd.Helpers
|
||||
{
|
||||
public static class PackageVersionHelpers
|
||||
{
|
||||
|
||||
|
||||
public static bool IsOwner(this ClaimsPrincipal user, PackageVersion v)
|
||||
{
|
||||
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return v.Package.OwnerId == userId;
|
||||
}
|
||||
|
||||
public static RegistrationPage[] CreateRegistrationPages(this IEnumerable<RegistrationLeaf> leaves,
|
||||
string bid)
|
||||
{
|
||||
List<RegistrationPage> pages = new List<RegistrationPage>();
|
||||
var ids = leaves.Select(l => l.Entry.Id).Distinct().ToArray();
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var lbi = leaves.Where(l=>l.Entry.Id == id).OrderBy(l=>
|
||||
new Version(l.Entry.version));
|
||||
var latest = new Version(lbi.Last().Entry.version);
|
||||
pages.Add(new RegistrationPage
|
||||
{
|
||||
Id = bid + id + "/" + latest.Major + "."
|
||||
+ latest.Minor + "."
|
||||
+ latest.Build,
|
||||
Count = lbi.Count(),
|
||||
Lower = new Version(lbi.First().Entry.version),
|
||||
Upper = latest,
|
||||
Items = lbi.ToArray(),
|
||||
Parent = bid + id + "/" + ApiConfig.IndexDotJson,
|
||||
});
|
||||
}
|
||||
return pages.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.Controllers
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class CatalogRegistration
|
||||
{
|
Loading…
Reference in New Issue