Searching deleted package

main
Paul Schneider 1 year ago
parent e5932a11c2
commit e2775dedaf
8 changed files with 36 additions and 40 deletions

@ -18,8 +18,13 @@ namespace isnd.Controllers
// Web search // Web search
public async Task<IActionResult> Index(PackageRegistrationQuery model) public async Task<IActionResult> Index(PackageRegistrationQuery model)
{ {
return View(new RegistrationPageIndexQueryAndResult{Query = model, var pkgs = await packageManager.SearchPackageAsync(model);
Result = await packageManager.SearchPackageAsync(model)});
return View(new RegistrationPageIndexQueryAndResult
{
Query = model,
Result = pkgs.ToArray()
});
} }
public async Task<IActionResult> Details(PackageDetailViewModel model) public async Task<IActionResult> Details(PackageDetailViewModel model)
@ -30,6 +35,7 @@ namespace isnd.Controllers
} }
var packageVersion = dbContext.PackageVersions var packageVersion = dbContext.PackageVersions
.Include(p=>p.LatestCommit)
.Include(p => p.Package) .Include(p => p.Package)
.Where(m => m.PackageId == model.pkgid) .Where(m => m.PackageId == model.pkgid)
.OrderByDescending(p => p) .OrderByDescending(p => p)
@ -48,7 +54,7 @@ namespace isnd.Controllers
} }
const int MAX_PKG_VERSION_LIST = 50; const int MAX_PKG_VERSION_LIST = 50;
[Authorize] [Authorize, HttpGet]
public async Task<IActionResult> Delete(string pkgid, string version, string pkgtype) public async Task<IActionResult> Delete(string pkgid, string version, string pkgtype)
{ {
if (pkgid == null || version == null) if (pkgid == null || version == null)
@ -66,7 +72,7 @@ namespace isnd.Controllers
} }
// POST: PackageVersion/Delete/5 // POST: PackageVersion/Delete/5
[HttpPost, ActionName("Delete")] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString, public async Task<IActionResult> DeleteConfirmed(string PackageId, string FullString,
string Type) string Type)

@ -14,31 +14,17 @@ namespace isnd.Data.Catalog
Items = new List<CatalogPage>(); Items = new List<CatalogPage>();
} }
public PackageRegistration(string bid, string id, string apiBase, IEnumerable<Packages.Package> pkgs) : base(bid + $"/{id}/index.json") public PackageRegistration(string bid, string id, string apiBase, Packages.Package pkg) : base(bid + $"/{id}/index.json")
{ {
Items = new List<CatalogPage>(); 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(); new CatalogPage(bid, id, apiBase, pkg.Versions)
List<PackageVersion> versions = new List<PackageVersion>(); };
if (pkg.Versions.Count>0)
foreach(var l in pkgsbi.Select(p => p.Versions)) {
{ CommitId = pkg.Versions.Max(v=>v.CommitNId).ToString();
versions.AddRange(l); CommitTimeStamp = pkg.Versions.Max(v=>v.LatestCommit.CommitTimeStamp);
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")] [JsonProperty("count")]
@ -49,5 +35,7 @@ namespace isnd.Data.Catalog
public string CommitId { get; set; } public string CommitId { get; set; }
public DateTimeOffset CommitTimeStamp { get; internal set; } public DateTimeOffset CommitTimeStamp { get; internal set; }
} }
} }

@ -76,5 +76,6 @@ namespace isnd.Data
} }
); );
} }
public bool IsDeleted => LatestCommit.Action == PackageAction.DeletePackage;
} }
} }

@ -30,7 +30,7 @@ namespace isnd.Interfaces
Task<PackageRegistration> GetCatalogIndexAsync(); Task<PackageRegistration> GetCatalogIndexAsync();
Task<PackageRegistration> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query); Task<PackageRegistration> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
Task<PackageRegistration> SearchPackageAsync(PackageRegistrationQuery query); Task<IEnumerable<PackageRegistration>> SearchPackageAsync(PackageRegistrationQuery query);
} }
} }

@ -194,7 +194,7 @@ namespace isnd.Services
var commit = new Commit var commit = new Commit
{ {
Action = PackageAction.DeletePackage, Action = PackageAction.DeletePackage,
TimeStamp = DateTime.Now TimeStamp = DateTimeOffset.Now.ToUniversalTime()
}; };
dbContext.Commits.Add(commit); dbContext.Commits.Add(commit);
var pkg = await dbContext.PackageVersions.SingleOrDefaultAsync( var pkg = await dbContext.PackageVersions.SingleOrDefaultAsync(
@ -276,13 +276,13 @@ namespace isnd.Services
query.Query = query.Query.ToLower(); query.Query = query.Query.ToLower();
var scope = await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner) var scope = await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
.Include(p=>p.LatestVersion) .Include(p=>p.LatestVersion)
.Where(p => p.Id.ToLower() == query.Query).Skip(query.Skip).Take(query.Take).ToListAsync(); .SingleAsync(p => p.Id.ToLower() == query.Query);
if (scope.Versions.Count==0) return null;
string bid = $"{apiBase}{ApiConfig.Registration}"; string bid = $"{apiBase}{ApiConfig.Registration}";
return return
new PackageRegistration(bid, query.Query, apiBase, scope); new PackageRegistration(bid, query.Query, apiBase, scope);
} }
public async Task<PackageRegistration> SearchPackageAsync(PackageRegistrationQuery query) public async Task<IEnumerable<PackageRegistration>> SearchPackageAsync(PackageRegistrationQuery query)
{ {
string bid = $"{apiBase}{ApiConfig.Registration}"; string bid = $"{apiBase}{ApiConfig.Registration}";
@ -297,8 +297,7 @@ namespace isnd.Services
var total = scope.Count(); var total = scope.Count();
var pkgs = scope.Skip(query.Skip).Take(query.Take); var pkgs = scope.Skip(query.Skip).Take(query.Take);
return return pkgs.Select(p => new PackageRegistration(bid, query.Query, apiBase, p));
new PackageRegistration(bid, query.Query, apiBase, pkgs);
} }
private static bool MatchingExact(Data.Packages.Package p, PackageRegistrationQuery query) private static bool MatchingExact(Data.Packages.Package p, PackageRegistrationQuery query)

@ -1,3 +1,4 @@
using System.Collections.Generic;
using isnd.Data.Catalog; using isnd.Data.Catalog;
namespace isnd namespace isnd
@ -5,6 +6,6 @@ namespace isnd
public class RegistrationPageIndexQueryAndResult public class RegistrationPageIndexQueryAndResult
{ {
public PackageRegistrationQuery Query { get; set; } public PackageRegistrationQuery Query { get; set; }
public PackageRegistration Result { get; set; } public PackageRegistration[] Result { get; set; }
} }
} }

@ -43,7 +43,7 @@
</dd> </dd>
</dl> </dl>
<form asp-action="Delete"> <form asp-action="DeleteConfirmed">
<input type="hidden" asp-for="PackageId" /> <input type="hidden" asp-for="PackageId" />
<input type="hidden" asp-for="FullString" /> <input type="hidden" asp-for="FullString" />
<input type="hidden" asp-for="Type" /> <input type="hidden" asp-for="Type" />

@ -10,25 +10,26 @@
<thead> <thead>
<tr> <tr>
<th> <th>
@Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Id) @Html.DisplayNameFor(model => model.Result[0].Items[0].Items[0].Id)
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.Description) @Html.DisplayNameFor(model => model.Result[0].Items[0].Items[0].Entry.Description)
</th> </th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var regpage in Model.Result.Items) { @foreach (var regpage in Model.Result)
foreach (var i in regpage.Items) {
<tr> <tr>
<td> <td>
@regpage.GetPackageId() @i.GetPackageId()
</td> </td>
<td> <td>
</td> </td>
<td> <td>
@Html.ActionLink("Details", "Details", new { pkgid = regpage.GetPackageId() }) @Html.ActionLink("Details", "Details", new { pkgid = i.GetPackageId() })
</td> </td>
</tr> </tr>
} }

Loading…