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}
|
// GET /contact/{id}
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<ActionResult<ContactDto>> GetContactAsync(Guid id)
|
public async Task<ActionResult<ContactDto>> GetContactAsync(Guid id)
|
||||||
{
|
{
|
||||||
@@ -56,6 +57,7 @@ namespace weddingapi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete /contact/{id}
|
// Delete /contact/{id}
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<ActionResult> DeleteContactAsync(Guid id)
|
public async Task<ActionResult> DeleteContactAsync(Guid id)
|
||||||
{
|
{
|
||||||
@@ -72,6 +74,7 @@ namespace weddingapi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET /contacts
|
// GET /contacts
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IEnumerable<ContactDto>> GetContactsAsync()
|
public async Task<IEnumerable<ContactDto>> GetContactsAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace weddingapi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET /family
|
// GET /family
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IEnumerable<FamilyDto>> GetFamiliesAsync()
|
public async Task<IEnumerable<FamilyDto>> GetFamiliesAsync()
|
||||||
{
|
{
|
||||||
@@ -42,6 +43,7 @@ namespace weddingapi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET /family/{id}
|
// GET /family/{id}
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<ActionResult<FamilyDto>> GetFamilyAsync(Guid id)
|
public async Task<ActionResult<FamilyDto>> GetFamilyAsync(Guid id)
|
||||||
{
|
{
|
||||||
@@ -80,6 +82,7 @@ namespace weddingapi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PUT /family/{id}
|
// PUT /family/{id}
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public async Task<ActionResult> UpdateFamilyAsync(Guid id, UpdateFamilyDto familyDto)
|
public async Task<ActionResult> UpdateFamilyAsync(Guid id, UpdateFamilyDto familyDto)
|
||||||
{
|
{
|
||||||
@@ -108,6 +111,7 @@ namespace weddingapi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete /family/{id}
|
// Delete /family/{id}
|
||||||
|
[DevelopmentOnly]
|
||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<ActionResult> DeleteFamilyAsync(Guid id)
|
public async Task<ActionResult> DeleteFamilyAsync(Guid id)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user