#nullable enable using System.Threading.Tasks; using API.Data; using API.DTOs; using API.Extensions; using API.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace API.Controllers; public class ReadingProfileController(ILogger logger, IUnitOfWork unitOfWork, IReadingProfileService readingProfileService): BaseApiController { /// /// Returns the ReadingProfile that should be applied to the given series, walks up the tree. /// Series -> Library -> Default /// /// /// [HttpGet("{seriesId}")] public async Task> GetProfileForSeries(int seriesId) { return Ok(await readingProfileService.GetReadingProfileForSeries(User.GetUserId(), seriesId)); } /// /// Update, or create the given profile /// /// /// /// Optionally, from which series the update is called. /// If set, will delete the implicit reading profile if it exists /// /// [HttpPost] public async Task UpdateReadingProfile([FromBody] UserReadingProfileDto dto, [FromQuery] int? seriesCtx) { if (seriesCtx.HasValue) { await readingProfileService.DeleteImplicitForSeries(User.GetUserId(), seriesCtx.Value); } var success = await readingProfileService.UpdateReadingProfile(User.GetUserId(), dto); if (!success) return BadRequest(); return Ok(); } /// /// Update the implicit reading profile for a series, creates one if none exists /// /// /// /// [HttpPost("series")] public async Task UpdateReadingProfileForSeries([FromBody] UserReadingProfileDto dto, [FromQuery] int seriesId) { var success = await readingProfileService.UpdateImplicitReadingProfile(User.GetUserId(), seriesId, dto); if (!success) return BadRequest(); return Ok(); } }