All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nancyfx.api.mustache Maven / Gradle / Ivy

The newest version!
using System;
using Nancy;
using Nancy.ModelBinding;
using System.Collections.Generic;
using Sharpility.Base;
using {{packageName}}.{{packageContext}}.Models;
using {{packageName}}.{{packageContext}}.Utils;
using NodaTime;
{{#imports}}using {{import}};
{{/imports}}

namespace {{packageName}}.{{packageContext}}.Modules
{ {{#operations}}{{#operation}}{{#allParams}}{{#isEnum}}
    {{>innerApiEnum}}{{/isEnum}}{{/allParams}}{{/operation}}

    /// 
    /// Module processing requests of {{classname}} domain.
    /// 
    public sealed class {{classname}}Module : NancyModule
    {
        /// 
        /// Sets up HTTP methods mappings.
        /// 
        /// Service handling requests
        public {{classname}}Module({{classname}}Service service) : base("{{baseContext}}")
        { {{#operation}}
            {{httpMethod}}["{{path}}"] = parameters =>
            {
                {{#allParams}}{{#isBodyParam}}var {{paramName}} = this.Bind<{{&dataType}}>();{{/isBodyParam}}{{^isBodyParam}}{{#isEnum}}var {{paramName}} = Parameters.ValueOf<{{>innerApiEnumName}}?>({{>innerParameterValueOfArgs}});{{/isEnum}}{{^isEnum}}var {{paramName}} = Parameters.ValueOf<{{&dataType}}>({{>innerParameterValueOfArgs}});{{/isEnum}}{{#hasMore}}
                {{/hasMore}}{{/isBodyParam}}{{/allParams}}{{#allParams}}{{#required}}
                Preconditions.IsNotNull({{paramName}}, "Required parameter: '{{paramName}}' is missing at '{{operationId}}'");
                {{/required}}{{/allParams}}
                {{#returnType}}return {{/returnType}}service.{{operationId}}(Context{{#allParams.0}}, {{/allParams.0}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{^returnType}}
                return new Response { ContentType = "{{produces.0.mediaType}}"};{{/returnType}}
            };
{{/operation}}
        }
    }

    /// 
    /// Service handling {{classname}} requests.
    /// 
    public interface {{classname}}Service
    {
        {{#operation}}/// 
        /// {{notes}}
        /// 
        /// Context of request
        {{#allParams}}/// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
        {{/allParams}}/// {{#returnType}}{{returnType}}{{/returnType}}
        {{#returnType}}{{&returnType}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}(NancyContext context{{#allParams.0}}, {{/allParams.0}}{{>paramsList}});{{#hasMore}}

        {{/hasMore}}{{/operation}}
    }

    /// 
    /// Abstraction of {{classname}}Service.
    /// 
    public abstract class Abstract{{classname}}Service: {{classname}}Service
    {
        {{#operation}}public virtual {{#returnType}}{{&returnType}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}(NancyContext context{{#allParams.0}}, {{/allParams.0}}{{>paramsList}})
        {
            {{#returnType}}return {{/returnType}}{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
        }{{#hasMore}}

        {{/hasMore}}{{/operation}}

        {{#operation}}protected abstract {{#returnType}}{{&returnType}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}({{>paramsList}});{{#hasMore}}

        {{/hasMore}}{{/operation}}
    }

{{/operations}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy