Api: refactoring method attribute
This commit is contained in:
parent
460d9a33ed
commit
fcaae79140
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
|
||||
namespace ASC.Web.Api.Routing
|
||||
@ -7,48 +8,41 @@ namespace ASC.Web.Api.Routing
|
||||
{
|
||||
public bool Check { get; set; }
|
||||
|
||||
public CustomHttpMethodAttribute(string method, string template, bool check = true)
|
||||
: base(new List<string>() { method }, template)
|
||||
public CustomHttpMethodAttribute(string method, string template = null, bool check = true, int order = 1)
|
||||
: base(new List<string>() { method }, $"[controller]{(template != null ? $"/{template}" : "")}")
|
||||
{
|
||||
Check = check;
|
||||
Order = order;
|
||||
}
|
||||
}
|
||||
|
||||
public class ReadAttribute : CustomHttpMethodAttribute
|
||||
{
|
||||
public ReadAttribute(bool check = true) :
|
||||
base("GET", $"[controller]", check)
|
||||
{
|
||||
}
|
||||
public ReadAttribute(bool check = true, int order = 1) :
|
||||
this(null, check, order) { }
|
||||
|
||||
public ReadAttribute(string template, bool check = true, int order = 1) :
|
||||
base("GET", $"[controller]/{template}", check) => Order = order;
|
||||
base(HttpMethod.Get.Method, template, check, order) { }
|
||||
}
|
||||
public class CreateAttribute : CustomHttpMethodAttribute
|
||||
{
|
||||
public CreateAttribute(bool check = true) :
|
||||
base("POST", $"[controller]", check)
|
||||
{
|
||||
}
|
||||
public CreateAttribute(bool check = true, int order = 1) :
|
||||
this(null, check, order) { }
|
||||
public CreateAttribute(string template, bool check = true, int order = 1) :
|
||||
base("POST", $"[controller]/{template}", check) => Order = order;
|
||||
}
|
||||
base(HttpMethod.Post.Method, template, check, order) { }
|
||||
}
|
||||
public class UpdateAttribute : CustomHttpMethodAttribute
|
||||
{
|
||||
public UpdateAttribute(bool check = true) :
|
||||
base("PUT", $"[controller]", check)
|
||||
{
|
||||
}
|
||||
|
||||
public UpdateAttribute(bool check = true, int order = 1) :
|
||||
this(null, check, order) { }
|
||||
public UpdateAttribute(string template, bool check = true, int order = 1) :
|
||||
base("PUT" ,$"[controller]/{template}", check) => Order = order;
|
||||
base(HttpMethod.Put.Method, template, check, order) { }
|
||||
}
|
||||
public class DeleteAttribute : CustomHttpMethodAttribute
|
||||
{
|
||||
public DeleteAttribute(bool check = true) :
|
||||
base("DELETE", $"[controller]", check)
|
||||
{
|
||||
}
|
||||
public DeleteAttribute(bool check = true, int order = 1) :
|
||||
this(null, check, order) { }
|
||||
public DeleteAttribute(string template, bool check = true, int order = 1) :
|
||||
base("DELETE", $"[controller]/{template}", check) => Order = order;
|
||||
base(HttpMethod.Delete.Method, template, check, order) { }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user