public async Task <IActionResult> ManifestDeleteAsync( [HttpTrigger(AuthorizationLevel.Function, FunctionConstants.FunctionDelete, Route = "packageManifests/{packageIdentifier}")] HttpRequest req, string packageIdentifier, ILogger log) { Dictionary <string, string> headers = null; try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); await this.dataStore.DeletePackageManifest(packageIdentifier); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(new NoContentResult()); }
public async Task <IActionResult> ManifestGetAsync( [HttpTrigger(AuthorizationLevel.Anonymous, FunctionConstants.FunctionGet, Route = "packageManifests/{packageIdentifier?}")] HttpRequest req, string packageIdentifier, ILogger log) { Dictionary <string, string> headers = null; ApiDataPage <PackageManifest> manifests = new ApiDataPage <PackageManifest>(); try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); manifests = await this.dataStore.GetPackageManifests(packageIdentifier, req.Query); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(manifests.Items.Count switch { 0 => new NoContentResult(), 1 => new ApiObjectResult(new ApiResponse <PackageManifest>(manifests.Items.First(), manifests.ContinuationToken)), _ => new ApiObjectResult(new ApiResponse <List <PackageManifest> >(manifests.Items.ToList(), manifests.ContinuationToken)), });
public async Task <IActionResult> ManifestPostAsync( [HttpTrigger(AuthorizationLevel.Function, FunctionConstants.FunctionPost, Route = "packageManifests")] HttpRequest req, ILogger log) { Dictionary <string, string> headers = null; PackageManifest packageManifest = null; try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); // Parse Stream packageManifest = await Parser.StreamParser <PackageManifest>(req.Body, log); ApiDataValidator.Validate(packageManifest); await this.dataStore.AddPackageManifest(packageManifest); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(new ApiObjectResult(new ApiResponse <PackageManifest>(packageManifest))); }
public async Task <IActionResult> VersionsPostAsync( [HttpTrigger(AuthorizationLevel.Function, FunctionConstants.FunctionPost, Route = "packages/{packageIdentifier}/versions")] HttpRequest req, string packageIdentifier, ILogger log) { Dictionary <string, string> headers = null; Version version = null; try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); // Parse body as Version version = await Parser.StreamParser <Version>(req.Body, log); ApiDataValidator.Validate(version); // Save Document await this.dataStore.AddVersion(packageIdentifier, version); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(new ApiObjectResult(new ApiResponse <Version>(version))); }
public async Task <IActionResult> LocalePutAsync( [HttpTrigger( AuthorizationLevel.Function, FunctionConstants.FunctionPut, Route = "packages/{packageIdentifier}/versions/{packageVersion}/locales/{packageLocale}")] HttpRequest req, string packageIdentifier, string packageVersion, string packageLocale, ILogger log) { Dictionary <string, string> headers = null; Locale locale = null; try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); // Parse body as package locale = await Parser.StreamParser <Locale>(req.Body, log); ApiDataValidator.Validate(locale); if (locale.PackageLocale != packageLocale) { throw new InvalidArgumentException( new InternalRestError( ErrorConstants.LocaleDoesNotMatchErrorCode, ErrorConstants.LocaleDoesNotMatchErrorMessage)); } await this.dataStore.UpdateLocale(packageIdentifier, packageVersion, packageLocale, locale); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(new ApiObjectResult(new ApiResponse <Locale>(locale))); }
public async Task <IActionResult> ManifestPutAsync( [HttpTrigger(AuthorizationLevel.Function, FunctionConstants.FunctionPut, Route = "packageManifests/{packageIdentifier}")] HttpRequest req, string packageIdentifier, ILogger log) { Dictionary <string, string> headers = null; PackageManifest packageManifest = null; try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); // Parse Stream packageManifest = await Parser.StreamParser <PackageManifest>(req.Body, log); ApiDataValidator.Validate(packageManifest); // Validate Versions Match if (packageManifest.PackageIdentifier != packageIdentifier) { throw new InvalidArgumentException( new InternalRestError( ErrorConstants.PackageDoesNotMatchErrorCode, ErrorConstants.PackageDoesNotMatchErrorMessage)); } await this.dataStore.UpdatePackageManifest(packageIdentifier, packageManifest); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(new ApiObjectResult(new ApiResponse <PackageManifest>(packageManifest))); }
public async Task <IActionResult> ManifestSearchPostAsync( [HttpTrigger(AuthorizationLevel.Anonymous, FunctionConstants.FunctionPost, Route = "manifestSearch")] HttpRequest req, ILogger log) { Dictionary <string, string> headers = null; ManifestSearchRequest manifestSearch = null; ApiDataPage <ManifestSearchResponse> manifestSearchResponse = new ApiDataPage <ManifestSearchResponse>(); try { // Parse Headers headers = HeaderProcessor.ToDictionary(req.Headers); // Get Manifest Search Request and Validate. manifestSearch = await Parser.StreamParser <ManifestSearchRequest>(req.Body, log); ApiDataValidator.Validate(manifestSearch); manifestSearchResponse = await this.dataStore.SearchPackageManifests(manifestSearch, headers, req.Query); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(manifestSearchResponse.Items.Count() switch { 0 => new NoContentResult(), _ => new ApiObjectResult(new ApiResponse <List <ManifestSearchResponse> >(manifestSearchResponse.Items.ToList(), manifestSearchResponse.ContinuationToken)), });
public IActionResult InformationGetAsync( [HttpTrigger(AuthorizationLevel.Anonymous, FunctionConstants.FunctionGet, Route = "information")] HttpRequest req, ILogger log) { Information information = null; try { information = new Information(); } catch (DefaultException e) { log.LogError(e.ToString()); return(ActionResultHelper.ProcessError(e.InternalRestError)); } catch (Exception e) { log.LogError(e.ToString()); return(ActionResultHelper.UnhandledError(e)); } return(new ApiObjectResult(new ApiResponse <Information>(information))); }