summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Controllers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-22 03:01:40 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-22 03:01:40 -0400
commit86d4827df211cc28549acb88ee7cb08d6cc4d4aa (patch)
treecfe021ee92fb8312b12ca83eda8575e4271cf8a6 /src/StardewModdingAPI.Web/Controllers
parent399b98b36b6111d364702b117fff3c5f21b8783a (diff)
downloadSMAPI-86d4827df211cc28549acb88ee7cb08d6cc4d4aa.tar.gz
SMAPI-86d4827df211cc28549acb88ee7cb08d6cc4d4aa.tar.bz2
SMAPI-86d4827df211cc28549acb88ee7cb08d6cc4d4aa.zip
simplify input & output format (#336)
Diffstat (limited to 'src/StardewModdingAPI.Web/Controllers')
-rw-r--r--src/StardewModdingAPI.Web/Controllers/ModsController.cs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/StardewModdingAPI.Web/Controllers/ModsController.cs b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
index d3b49445..876f5248 100644
--- a/src/StardewModdingAPI.Web/Controllers/ModsController.cs
+++ b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
@@ -29,33 +29,39 @@ namespace StardewModdingAPI.Web.Controllers
** Public methods
*********/
/// <summary>Fetch version metadata for the given mods.</summary>
- /// <param name="modKeys">The namespaced mod keys to search.</param>
- [HttpGet]
- public async Task<ModInfoModel[]> Post(IEnumerable<string> modKeys)
+ /// <param name="search">The search options.</param>
+ [HttpPost]
+ public async Task<IDictionary<string, ModInfoModel>> Post([FromBody] ModSearchModel search)
{
- IList<ModInfoModel> result = new List<ModInfoModel>();
+ // sort & filter keys
+ string[] modKeys = (search.ModKeys ?? new string[0])
+ .Distinct(StringComparer.CurrentCultureIgnoreCase)
+ .OrderBy(p => p, StringComparer.CurrentCultureIgnoreCase)
+ .ToArray();
+ // fetch mod info
+ IDictionary<string, ModInfoModel> result = new Dictionary<string, ModInfoModel>(StringComparer.CurrentCultureIgnoreCase);
foreach (string modKey in modKeys)
{
// parse mod key
if (!this.TryParseModKey(modKey, out string vendorKey, out string modID))
{
- result.Add(new ModInfoModel(modKey, "The mod key isn't in a valid format. It should contain the mod repository key and mod ID like 'Nexus:541'."));
+ result[modKey] = new ModInfoModel("The mod key isn't in a valid format. It should contain the mod repository key and mod ID like 'Nexus:541'.");
continue;
}
// get matching repository
if (!this.Repositories.TryGetValue(vendorKey, out IModRepository repository))
{
- result.Add(new ModInfoModel(modKey, "There's no mod repository matching this namespaced mod ID."));
+ result[modKey] = new ModInfoModel("There's no mod repository matching this namespaced mod ID.");
continue;
}
// fetch mod info
- result.Add(await repository.GetModInfoAsync(modID));
+ result[modKey] = await repository.GetModInfoAsync(modID);
}
- return result.ToArray();
+ return result;
}