♻️ No idea, but errors all gone
This commit is contained in:
53
DysonNetwork.Pass/Publisher/PublisherService.cs
Normal file
53
DysonNetwork.Pass/Publisher/PublisherService.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using MagicOnion.Server;
|
||||
using DysonNetwork.Shared.Services;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Pass.Publisher;
|
||||
|
||||
public class PublisherService : ServiceBase<IPublisherService>, IPublisherService
|
||||
{
|
||||
private readonly AppDatabase _db;
|
||||
|
||||
public PublisherService(AppDatabase db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<Shared.Models.Publisher?> GetPublisherByName(string name)
|
||||
{
|
||||
return await _db.Publishers.FirstOrDefaultAsync(p => p.Name == name);
|
||||
}
|
||||
|
||||
public async Task<List<Shared.Models.Publisher>> GetUserPublishers(Guid accountId)
|
||||
{
|
||||
var publisherIds = await _db.PublisherMembers
|
||||
.Where(m => m.AccountId == accountId)
|
||||
.Select(m => m.PublisherId)
|
||||
.ToListAsync();
|
||||
|
||||
return await _db.Publishers
|
||||
.Where(p => publisherIds.Contains(p.Id))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> IsMemberWithRole(Guid publisherId, Guid accountId, PublisherMemberRole role)
|
||||
{
|
||||
return await _db.PublisherMembers.AnyAsync(m =>
|
||||
m.PublisherId == publisherId &&
|
||||
m.AccountId == accountId &&
|
||||
m.Role >= role);
|
||||
}
|
||||
|
||||
public async Task<List<PublisherFeature>> GetPublisherFeatures(Guid publisherId)
|
||||
{
|
||||
return await _db.PublisherFeatures
|
||||
.Where(f => f.PublisherId == publisherId)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user