47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
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(AppDatabase db) : ServiceBase<IPublisherService>, IPublisherService
|
|
{
|
|
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();
|
|
}
|
|
}
|