/// <summary> /// Adds a <see cref="DynamicControllerComposedTemplate" /> for creating a resources but NOT getting back an immediate /// result. /// <para> /// Results are always returned in an <see cref="HandlerResponse" />. instance. /// </para> /// </summary> /// <remarks> /// When not set, response codes defaults to 202, 401, 403, 404, 409 /// </remarks> /// <typeparam name="TRequest">The type of the t request.</typeparam> /// <param name="templates">Current list of templates.</param> /// <param name="options">The controller template options.</param> /// <exception cref="ArgumentException">Must be a single object type. - TResponse</exception> public static IEnumerable <IComposedTemplate> WritePostAcceptedController <TRequest>( this IEnumerable <IComposedTemplate> templates, DynamicControllerTemplateOptions options ) where TRequest : new() { var codes = (options.StatusCodes ?? new List <int> { 202, 400, 401, 403, 404, 409 }).ToList(); if (!codes.Any()) { throw new ArgumentException("When providing status codes you must not use an empty list!", nameof(options.StatusCodes)); } var(ac, cc) = GetComments(options, "Create a new resource."); var action = Templates.GetDynamicAction("PostAccepted", options.ActionRoute, ac); var template = new DynamicControllerComposedTemplate(options.NameSpace, options.ControllerRoute, action, cc); ((List <IComposedTemplate>)templates).Add(ParseReplaceAndAddToCollection( template, typeof(TRequest), null, true, req => options.ControllerName ?? $"PostAccepted{req}Controller", BuildResponseTypes(codes) ) ); return(templates); }
/// <summary> /// Adds a <see cref="DynamicControllerComposedTemplate" /> for querying resources by some value(s). /// <para> /// Results are always returned in an <see cref="HandlerResponse" />. instance. /// </para> /// </summary> /// <remarks> /// When not set, response codes defaults to 200, 204, 401, 403. /// </remarks> /// <typeparam name="TRequest">The type of the t request.</typeparam> /// <typeparam name="TResponse">The type of the t response.</typeparam> /// <param name="templates">The templates.</param> /// <param name="options">The options.</param> /// <returns>IEnumerable<IComposedTemplate>.</returns> /// <exception cref="ArgumentException"> /// Must be a single object type. - TResponse /// or /// When providing status codes you must not use an empty list! - StatusCodes /// </exception> public static IEnumerable <IComposedTemplate> WriteQueryByController <TRequest, TResponse>( this IEnumerable <IComposedTemplate> templates, DynamicControllerTemplateOptions options ) where TRequest : new() { var t = typeof(TResponse); if (t.Name != nameof(Object) && t.Name != nameof(String)) { if (t.IsAssignableTo(typeof(IEnumerable))) { throw new ArgumentException("Must be a single object type.", nameof(TResponse)); } } var codes = (options.StatusCodes ?? new List <int> { 200, 204, 401, 403 }).ToList(); if (!codes.Any()) { throw new ArgumentException("When providing status codes you must not use an empty list!", nameof(options.StatusCodes)); } var(ac, cc) = GetComments(options, "Get a specific resource."); var action = Templates.GetDynamicAction("QueryBy", options.ActionRoute, ac); var template = new DynamicControllerComposedTemplate(options.NameSpace, options.ControllerRoute, action, cc); ((List <IComposedTemplate>)templates).Add(ParseReplaceAndAddToCollection( template, typeof(TRequest), typeof(TResponse), false, req => options.ControllerName ?? $"QueryBy{req}Controller", BuildResponseTypes(codes) ) ); return(templates); }