db and auth refactoring
This commit is contained in:
parent
0e1c16ab91
commit
aa472f9e29
45 changed files with 2182 additions and 697 deletions
39
Sledgemapper.Api/Controllers/CampaignController.cs
Normal file
39
Sledgemapper.Api/Controllers/CampaignController.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Notifications;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sledgemapper.Api.Controllers
|
||||
{
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[Route("[controller]")]
|
||||
public class CampaignController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private string UserId => HttpContext.User.Claims.FirstOrDefault(m => m.Type == "Id").Value;
|
||||
|
||||
public CampaignController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
[HttpPost]
|
||||
[Route("{campaignName}")]
|
||||
public async Task<bool> Post(string campaignName)
|
||||
{
|
||||
var result = await _mediator.Send(new NewCampaignCommand(campaignName, UserId.ToString()));
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<List<Core.Entities.Campaign>> Get()
|
||||
{
|
||||
var result = await _mediator.Send(new GetCampaignsCommand(UserId));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue