REORG
This commit is contained in:
48
src/isnd/ViewModels/PackageSearchResult.cs
Normal file
48
src/isnd/ViewModels/PackageSearchResult.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text.Json.Serialization;
|
||||
using isnd.Data.Packages;
|
||||
using isnd.Entities;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class PackageSearchResult
|
||||
{
|
||||
|
||||
public IEnumerable<Package> GetResults()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<Package> result;
|
||||
|
||||
[JsonIgnore]
|
||||
public string ApiBase{get; private set;}
|
||||
|
||||
public PackageSearchResult(IEnumerable<Package> result, string apiBase, int totalHit)
|
||||
{
|
||||
this.result = result;
|
||||
this.ApiBase = apiBase;
|
||||
data=result.Select(r => NewPackageHit(apiBase, r)).ToArray();
|
||||
this.totalHits = totalHit;
|
||||
}
|
||||
|
||||
private static PackageHit NewPackageHit(string apiBase, Package package)
|
||||
{
|
||||
string regId = $"{apiBase}{ApiConfig.Registration}/{package.Id}/index.json";
|
||||
return new PackageHit(regId)
|
||||
{
|
||||
version = package.GetLatestVersion(),
|
||||
description = package.Description,
|
||||
title = package.Id,
|
||||
versions = package.Versions.Select(v => new SearchVersionInfo(regId, v)).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
public PackageHit[] data { get; protected set; }
|
||||
|
||||
public int totalHits { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user