dev only mode
This commit is contained in:
21
Attributes/DevelopmentOnlyAttribute.cs
Normal file
21
Attributes/DevelopmentOnlyAttribute.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public class DevelopmentOnlyAttribute : Attribute, IResourceFilter
|
||||
{
|
||||
public void OnResourceExecuting(ResourceExecutingContext context)
|
||||
{
|
||||
var env = context.HttpContext.RequestServices.GetService<IHostingEnvironment>();
|
||||
if (!env.IsDevelopment())
|
||||
{
|
||||
context.Result = new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResourceExecuted(ResourceExecutedContext context)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// GET /contact/{id}
|
||||
[DevelopmentOnly]
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ContactDto>> GetContactAsync(Guid id)
|
||||
{
|
||||
@@ -56,6 +57,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// Delete /contact/{id}
|
||||
[DevelopmentOnly]
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> DeleteContactAsync(Guid id)
|
||||
{
|
||||
@@ -72,6 +74,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// GET /contacts
|
||||
[DevelopmentOnly]
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<ContactDto>> GetContactsAsync()
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// GET /family
|
||||
[DevelopmentOnly]
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<FamilyDto>> GetFamiliesAsync()
|
||||
{
|
||||
@@ -42,6 +43,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// GET /family/{id}
|
||||
[DevelopmentOnly]
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<FamilyDto>> GetFamilyAsync(Guid id)
|
||||
{
|
||||
@@ -80,6 +82,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// PUT /family/{id}
|
||||
[DevelopmentOnly]
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ActionResult> UpdateFamilyAsync(Guid id, UpdateFamilyDto familyDto)
|
||||
{
|
||||
@@ -108,6 +111,7 @@ namespace weddingapi.Controllers
|
||||
}
|
||||
|
||||
// Delete /family/{id}
|
||||
[DevelopmentOnly]
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<ActionResult> DeleteFamilyAsync(Guid id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user