Permalink
Browse files

Merge pull request #512 from NuGet/tab-completion

Packages tab completion info API
  • Loading branch information...
2 parents 3064088 + 2ac072b commit 764a1f2c9ac43f3cf8ae7b37b0be59d9951ca02f @half-ogre half-ogre committed Jun 12, 2012
@@ -101,7 +101,7 @@ public void WillPushTheCuratedFeedNameIntoTheViewBagAndShowTheCreateCuratedPacka
{
var controller = new TestableCuratedPackagesController();
controller.StubCuratedFeed.Name = "theCuratedFeedName";
- controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((PackageRegistration)null);
+ controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).Returns((PackageRegistration)null);
var result = controller.PostCuratedPackages("aFeedName", new CreateCuratedPackageRequest()) as ViewResult;
@@ -150,7 +150,7 @@ public void WillShowAnErrorWhenThePackageHasAlreadyBeenCurated()
var controller = new TestableCuratedPackagesController();
controller.StubCuratedFeed.Name = "theCuratedFeedName";
controller.StubCuratedFeed.Packages.Add(new CuratedPackage{ PackageRegistration = new PackageRegistration{ Key = 42 } });
- controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>())).Returns((new PackageRegistration{ Key = 42 }));
+ controller.StubPackageRegistrationByIdQry.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).Returns((new PackageRegistration { Key = 42 }));
var result = controller.PostCuratedPackages("theCuratedFeedName", new CreateCuratedPackageRequest()) as ViewResult;
@@ -168,7 +168,7 @@ public TestableCuratedPackagesController()
.Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>()))
.Returns(StubCuratedFeed);
StubPackageRegistrationByIdQry
- .Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>()))
+ .Setup(stub => stub.Execute(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
.Returns(StubPackageRegistration);
}
}
@@ -61,6 +61,16 @@ public partial class ApiController {
public System.Web.Mvc.ActionResult PublishPackage() {
return new T4MVC_ActionResult(Area, Name, ActionNames.PublishPackage);
}
+ [NonAction]
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public System.Web.Mvc.ActionResult GetPackageIds() {
+ return new T4MVC_ActionResult(Area, Name, ActionNames.GetPackageIds);
+ }
+ [NonAction]
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public System.Web.Mvc.ActionResult GetPackageVersions() {
+ return new T4MVC_ActionResult(Area, Name, ActionNames.GetPackageVersions);
+ }
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public ApiController Actions { get { return MVC.Api; } }
@@ -81,6 +91,8 @@ public class ActionNamesClass {
public readonly string CreatePackagePost = "PushPackageApi";
public readonly string DeletePackage = "DeletePackageApi";
public readonly string PublishPackage = "PublishPackageApi";
+ public readonly string GetPackageIds = "PackageIDs";
+ public readonly string GetPackageVersions = "PackageVersions";
}
@@ -144,6 +156,20 @@ public class T4MVC_ApiController: NuGetGallery.ApiController {
return callInfo;
}
+ public override System.Web.Mvc.ActionResult GetPackageIds(string partialId, bool? includePrerelease) {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.GetPackageIds);
+ callInfo.RouteValueDictionary.Add("partialId", partialId);
+ callInfo.RouteValueDictionary.Add("includePrerelease", includePrerelease);
+ return callInfo;
+ }
+
+ public override System.Web.Mvc.ActionResult GetPackageVersions(string id, bool? includePrerelease) {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.GetPackageVersions);
+ callInfo.RouteValueDictionary.Add("id", id);
+ callInfo.RouteValueDictionary.Add("includePrerelease", includePrerelease);
+ return callInfo;
+ }
+
}
}
@@ -207,6 +207,12 @@ public override void Load()
Bind<IUserByUsernameQuery>()
.To<UserByUsernameQuery>()
.InRequestScope();
+ Bind<IPackageIdsQuery>()
+ .To<PackageIdsQuery>()
+ .InRequestScope();
+ Bind<IPackageVersionsQuery>()
+ .To<PackageVersionsQuery>()
+ .InRequestScope();
}
}
}
@@ -100,22 +100,22 @@ public static void RegisterRoutes(RouteCollection routes)
routes.MapRoute(
RouteName.CuratedFeed,
"curated-feeds/{name}",
- new { controller = CuratedFeedsController.Name, action = "CuratedFeed" });
+ new { controller = CuratedFeedsController.ControllerName, action = "CuratedFeed" });
routes.MapRoute(
RouteName.CreateCuratedPackageForm,
"forms/add-package-to-curated-feed",
- new { controller = CuratedPackagesController.Name, action = "CreateCuratedPackageForm" });
+ new { controller = CuratedPackagesController.ControllerName, action = "CreateCuratedPackageForm" });
routes.MapRoute(
RouteName.CuratedPackage,
"curated-feeds/{curatedFeedName}/curated-packages/{curatedPackageId}",
- new { controller = CuratedPackagesController.Name, action = "CuratedPackage" });
+ new { controller = CuratedPackagesController.ControllerName, action = "CuratedPackage" });
routes.MapRoute(
RouteName.CuratedPackages,
"curated-feeds/{curatedFeedName}/curated-packages",
- new { controller = CuratedPackagesController.Name, action = "CuratedPackages" });
+ new { controller = CuratedPackagesController.ControllerName, action = "CuratedPackages" });
// TODO : Most of the routes are essentially of the format api/v{x}/*. We should refactor the code to vary them by the version.
// V1 Routes
@@ -198,6 +198,16 @@ public static void RegisterRoutes(RouteCollection routes)
defaults: null,
constraints: new { httpMethod = new HttpMethodConstraint("DELETE") });
+ routes.MapRoute(
+ "v2PackageIds",
+ "api/v2/package-ids",
+ MVC.Api.GetPackageIds());
+
+ routes.MapRoute(
+ "v2PackageVersions",
+ "api/v2/package-versions/{id}",
+ MVC.Api.GetPackageVersions());
+
routes.MapServiceRoute(
RouteName.V2ApiCuratedFeed,
"api/v2/curated-feed",
@@ -239,7 +249,7 @@ public static void RegisterRoutes(RouteCollection routes)
// r => r.MapRoute(
// "EditPackage",
// "Package/Edit/{id}/{version}",
- // new { controller = PackagesController.Name, action = "EditPackage" }),
+ // new { controller = PackagesController.ControllerName, action = "EditPackage" }),
// permanent: true).To(packageVersionActionRoute);
routes.Redirect(
@@ -28,8 +28,6 @@ public static class Constants
public const string UploadFileNameTemplate = "{0}{1}";
public const string UploadsFolderName = "uploads";
-
public const string NuGetCommandLinePackageId = "NuGet.CommandLine";
-
}
}
@@ -1,15 +1,18 @@
using System;
+using System.Collections.Generic;
+using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
+using System.Runtime.Serialization;
using System.Web.Mvc;
using System.Web.UI;
using NuGet;
namespace NuGetGallery
{
- public partial class ApiController : Controller
+ public partial class ApiController : AppController
{
private readonly IPackageService packageSvc;
private readonly IUserService userSvc;
@@ -30,8 +33,8 @@ public partial class ApiController : Controller
[ActionName("GetPackageApi"), HttpGet]
public virtual ActionResult GetPackage(string id, string version)
{
- // if the version is null, the user is asking for the latest version. Presumably they don't want pre release versions.
- // The allow prerelease flag is ignored if both id and version are specified.
+ // if the version is null, the user is asking for the latest version. Presumably they don't want includePrerelease release versions.
+ // The allow prerelease flag is ignored if both partialId and version are specified.
var package = packageSvc.FindPackageByIdAndVersion(id, version, allowPrerelease: false);
if (package == null)
@@ -72,7 +75,7 @@ public virtual ActionResult VerifyPackageKey(string apiKey, string id, string ve
if (!String.IsNullOrEmpty(id))
{
- // If the id is present, then verify that the user has permission to push for the specific Id \ version combination.
+ // If the partialId is present, then verify that the user has permission to push for the specific Id \ version combination.
var package = packageSvc.FindPackageByIdAndVersion(id, version);
if (package == null)
return new HttpStatusCodeWithBodyResult(HttpStatusCode.NotFound, string.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version));
@@ -110,7 +113,7 @@ private ActionResult CreatePackageInternal(string apiKey)
var packageToPush = ReadPackageFromRequest();
- // Ensure that the user can push packages for this id.
+ // Ensure that the user can push packages for this partialId.
var packageRegistration = packageSvc.FindPackageRegistrationById(packageToPush.Id);
if (packageRegistration != null)
{
@@ -189,5 +192,23 @@ protected internal virtual IPackage ReadPackageFromRequest()
return new ZipPackage(stream);
}
+
+ [ActionName("PackageIDs"), HttpGet]
+ public virtual ActionResult GetPackageIds(
+ string partialId,
+ bool? includePrerelease)
+ {
+ var qry = GetService<IPackageIdsQuery>();
+ return new JsonNetResult(qry.Execute(partialId, includePrerelease).ToArray());
+ }
+
+ [ActionName("PackageVersions"), HttpGet]
+ public virtual ActionResult GetPackageVersions(
+ string id,
+ bool? includePrerelease)
+ {
+ var qry = GetService<IPackageVersionsQuery>();
+ return new JsonNetResult(qry.Execute(id, includePrerelease).ToArray());
+ }
}
}
@@ -3,7 +3,7 @@
namespace NuGetGallery
{
- public class AppController : Controller
+ public abstract class AppController : Controller
{
protected virtual IIdentity Identity
{
@@ -4,12 +4,12 @@
namespace NuGetGallery
{
[Authorize]
- public class CuratedFeedsController : AppController
+ public partial class CuratedFeedsController : AppController
{
- public const string Name = "CuratedFeeds";
+ public const string ControllerName = "CuratedFeeds";
[HttpGet]
- public ActionResult CuratedFeed(string name)
+ public virtual ActionResult CuratedFeed(string name)
{
var curatedFeed = GetService<ICuratedFeedByNameQuery>().Execute(name, includePackages: true);
if (curatedFeed == null)
@@ -4,12 +4,12 @@
namespace NuGetGallery
{
[Authorize]
- public class CuratedPackagesController : AppController
+ public partial class CuratedPackagesController : AppController
{
- public const string Name = "CuratedPackages";
+ public const string ControllerName = "CuratedPackages";
[ActionName("CreateCuratedPackageForm"), HttpGet]
- public ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
+ public virtual ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
{
var curatedFeed = GetService<ICuratedFeedByNameQuery>().Execute(curatedFeedName);
if (curatedFeed == null)
@@ -23,7 +23,7 @@ public ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
}
[ActionName("CuratedPackage"), HttpDelete]
- public ActionResult DeleteCuratedPackage(
+ public virtual ActionResult DeleteCuratedPackage(
string curatedFeedName,
string curatedPackageId)
{
@@ -46,7 +46,7 @@ public ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
}
[ActionName("CuratedPackage"), AcceptVerbs("patch")]
- public ActionResult PatchCuratedPackage(
+ public virtual ActionResult PatchCuratedPackage(
string curatedFeedName,
string curatedPackageId,
ModifyCuratedPackageRequest request)
@@ -74,7 +74,7 @@ public ActionResult GetCreateCuratedPackageForm(string curatedFeedName)
}
[ActionName("CuratedPackages"), HttpPost]
- public ActionResult PostCuratedPackages(
+ public virtual ActionResult PostCuratedPackages(
string curatedFeedName,
CreateCuratedPackageRequest request)
{
@@ -0,0 +1,82 @@
+// <auto-generated />
+// This file was generated by a T4 template.
+// Don't change it directly as your change would get overwritten. Instead, make changes
+// to the .tt file (i.e. the T4 template) and save it to regenerate this file.
+
+// Make sure the compiler doesn't complain about missing Xml comments
+#pragma warning disable 1591
+#region T4MVC
+
+using System;
+using System.Diagnostics;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Web;
+using System.Web.Hosting;
+using System.Web.Mvc;
+using System.Web.Mvc.Ajax;
+using System.Web.Mvc.Html;
+using System.Web.Routing;
+using T4MVC;
+namespace NuGetGallery {
+ public partial class CuratedFeedsController {
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public CuratedFeedsController() { }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected CuratedFeedsController(Dummy d) { }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ protected RedirectToRouteResult RedirectToAction(ActionResult result) {
+ var callInfo = result.GetT4MVCResult();
+ return RedirectToRoute(callInfo.RouteValueDictionary);
+ }
+
+ [NonAction]
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public System.Web.Mvc.ActionResult CuratedFeed() {
+ return new T4MVC_ActionResult(Area, Name, ActionNames.CuratedFeed);
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public CuratedFeedsController Actions { get { return MVC.CuratedFeeds; } }
+ [GeneratedCode("T4MVC", "2.0")]
+ public readonly string Area = "";
+ [GeneratedCode("T4MVC", "2.0")]
+ public readonly string Name = "CuratedFeeds";
+
+ static readonly ActionNamesClass s_actions = new ActionNamesClass();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ActionNamesClass ActionNames { get { return s_actions; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ActionNamesClass {
+ public readonly string CuratedFeed = "CuratedFeed";
+ }
+
+
+ static readonly ViewNames s_views = new ViewNames();
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public ViewNames Views { get { return s_views; } }
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class ViewNames {
+ public readonly string CuratedFeed = "~/Views/CuratedFeeds/CuratedFeed.cshtml";
+ }
+ }
+
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public class T4MVC_CuratedFeedsController: NuGetGallery.CuratedFeedsController {
+ public T4MVC_CuratedFeedsController() : base(Dummy.Instance) { }
+
+ public override System.Web.Mvc.ActionResult CuratedFeed(string name) {
+ var callInfo = new T4MVC_ActionResult(Area, Name, ActionNames.CuratedFeed);
+ callInfo.RouteValueDictionary.Add("name", name);
+ return callInfo;
+ }
+
+ }
+}
+
+#endregion T4MVC
+#pragma warning restore 1591
Oops, something went wrong. Retry.

0 comments on commit 764a1f2

Please sign in to comment.