REORG
parent
89e1b5a235
commit
d6180aa154
@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using isnd.Entities;
|
||||
using isn.abst;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Data.Catalog;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
// TODO /search GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
||||
|
||||
public partial class PackagesController
|
||||
{
|
||||
// Web get the paquet
|
||||
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Search)]
|
||||
[HttpHead("~" + Constants.ApiVersionPrefix + ApiConfig.Search)]
|
||||
public async Task<IActionResult> Search(
|
||||
string q=null,
|
||||
int skip=0,
|
||||
int take=25,
|
||||
bool prerelease=false,
|
||||
string semVerLevel = "2.0.0",
|
||||
string packageType = null)
|
||||
{
|
||||
PackageRegistrationQuery query = new PackageRegistrationQuery
|
||||
{
|
||||
Prerelease= prerelease,
|
||||
Query = q,
|
||||
Skip = skip,
|
||||
Take = take
|
||||
};
|
||||
var result = await packageManager.SearchPackageAsync(query);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace isnd.Data.Packages
|
||||
{
|
||||
public interface IPackage
|
||||
{
|
||||
string Id { get; set; }
|
||||
string OwnerId { get; set; }
|
||||
string Description { get; set; }
|
||||
bool Public { get; set; }
|
||||
ApplicationUser Owner { get; set; }
|
||||
List<PackageVersion> Versions { get; set; }
|
||||
long CommitNId { get; set; }
|
||||
string CommitId { get; }
|
||||
Commit LatestCommit { get; set; }
|
||||
DateTimeOffset CommitTimeStamp { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using isnd.Data.Catalog;
|
||||
using Newtonsoft.Json;
|
||||
using NuGet.Packaging.Core;
|
||||
using NuGet.Protocol.Core.Types;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class PackageHit : Permalink
|
||||
{
|
||||
public PackageHit(string id) : base(id, "Package")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The full SemVer 2.0.0 version string of the package (could contain build metadata)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[Required]
|
||||
public string version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All of the versions of the package matching the prerelease parameter
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SearchVersionInfo[] versions { get; set; }
|
||||
|
||||
public string description { get; set; }
|
||||
|
||||
public string[] authors { get; set; }
|
||||
public string iconUrl { get; set; }
|
||||
public string licenseUrl { get; set; }
|
||||
public string projectUrl { get; set; }
|
||||
/// <summary>
|
||||
/// The absolute URL to the associated registration index
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string registration { get; set; }
|
||||
public string summary { get; set; }
|
||||
public string[] tags { get; set; }
|
||||
public string title { get; set; }
|
||||
/// <summary>
|
||||
/// This value can be inferred by the sum of downloads in the versions array
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int totalDownloads { get; set; }
|
||||
/// <summary>
|
||||
/// boolean indicating whether the package is verified
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public bool verified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The package types defined by the package author (added in SearchQueryService/3.5.0)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[Required]
|
||||
public PackageType[] packageTypes { get; set; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using isnd.Data.Catalog;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class SearchVersionInfo: Permalink
|
||||
{
|
||||
public SearchVersionInfo(string id, Data.PackageVersion v) : base(id, "VersionInfo")
|
||||
{
|
||||
Version = v.FullString;
|
||||
}
|
||||
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
|
||||
[JsonProperty("downloads")]
|
||||
public long Downloads { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue