db and auth refactoring

This commit is contained in:
Michele 2021-02-20 00:18:07 +00:00
parent 0e1c16ab91
commit aa472f9e29
45 changed files with 2182 additions and 697 deletions

View 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;
}
}
}