wiring up new auth endpoint
This commit is contained in:
parent
b6999cef0a
commit
a13fb49942
17 changed files with 850 additions and 37 deletions
|
@ -2,6 +2,7 @@ using MediatR;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Sledgemapper.Api.Commands;
|
||||
using Sledgemapper.Api.Infrastructure.Data;
|
||||
using Sledgemapper.Shared.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -10,7 +11,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Sledgemapper.Api.Handlers
|
||||
{
|
||||
public class GetCampaignsCommandHandler : IRequestHandler<GetCampaignsCommand, List<Core.Entities.Campaign>>
|
||||
public class GetCampaignsCommandHandler : IRequestHandler<GetCampaignsCommand, List<Campaign>>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly SledgemapperDbContext _dbcontext;
|
||||
|
@ -21,20 +22,22 @@ namespace Sledgemapper.Api.Handlers
|
|||
_dbcontext = dbcontext;
|
||||
}
|
||||
|
||||
public async Task<List<Core.Entities.Campaign>> Handle(GetCampaignsCommand command, CancellationToken cancellationToken)
|
||||
public async Task<List<Campaign>> Handle(GetCampaignsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await _dbcontext.Users.FindAsync(command.UserId);
|
||||
_dbcontext.Attach(user);
|
||||
var campaigns = _dbcontext.Campaigns.Include(c=>c.InvitedUsers).Include(c=>c.Owner).Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user));
|
||||
var campaigns = _dbcontext.Campaigns.Include(c => c.InvitedUsers).Include(c => c.Owner).Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user));
|
||||
|
||||
return campaigns.ToList();
|
||||
return campaigns.
|
||||
Select(c => new Shared.Entities.Campaign { Id = c.CampaignId, Name = c.CampaignName, Maps = c.Maps.Select(m => new Shared.Entities.Map { SessionName = m.MapName }).ToList()})
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return new List<Core.Entities.Campaign>();
|
||||
return new List<Campaign>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue