PlotDirector/PlotLine/Services/WritingSolverWorkspaceContext.cs

19 lines
903 B
C#

using PlotLine.Data;
using PlotLine.Models;
namespace PlotLine.Services;
public interface IWritingSolverWorkspaceContext
{
Task<IReadOnlyList<Project>> ProjectsAsync();
Task<IReadOnlyList<Character>> CharactersAsync(int projectId);
}
public sealed class WritingSolverWorkspaceContext(IProjectRepository projects,ICharacterRepository characters,ICurrentUserService user) : IWritingSolverWorkspaceContext
{
public Task<IReadOnlyList<Project>> ProjectsAsync()=>user.UserId is int id?projects.ListActiveForUserAsync(id):Task.FromResult<IReadOnlyList<Project>>([]);
public async Task<IReadOnlyList<Character>> CharactersAsync(int projectId)
{
if(user.UserId is not int id || await projects.GetForUserAsync(projectId,id) is not {} project || project.IsArchived)return [];
return (await characters.ListCharactersAsync(projectId)).Where(c=>!c.IsArchived).ToArray();
}
}