mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-14 07:17:54 +02:00
Add NewtonsoftJson to Swagger
Add RetrieveChaptersJob.cs Add UpdateFilesDownloadedJob.cs Remove DownloadNewChaptersJob.cs and instead use DownloadAvailableChaptersJob.cs
This commit is contained in:
@ -83,19 +83,24 @@ public class JobController(PgsqlContext context) : Controller
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new CreateNewDownloadChapterJob
|
||||
/// Create a new DownloadAvailableChaptersJob
|
||||
/// </summary>
|
||||
/// <param name="MangaId">ID of Manga</param>
|
||||
/// <param name="recurrenceTime">How often should we check for new chapters</param>
|
||||
/// <response code="201">Created new Job</response>
|
||||
/// <response code="404">Could not find Manga with ID</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("NewDownloadChapterJob/{MangaId}")]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[HttpPut("DownloadAvailableChaptersJob/{MangaId}")]
|
||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateNewDownloadChapterJob(string MangaId, [FromBody]ulong recurrenceTime)
|
||||
{
|
||||
Job job = new DownloadNewChaptersJob(recurrenceTime, MangaId);
|
||||
return AddJob(job);
|
||||
if (context.Manga.Find(MangaId) is null)
|
||||
return NotFound();
|
||||
Job dep = new RetrieveChaptersJob(recurrenceTime, MangaId);
|
||||
Job job = new DownloadAvailableChaptersJob(recurrenceTime, MangaId, null, [dep.JobId]);
|
||||
return AddJobs([dep, job]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,29 +108,37 @@ public class JobController(PgsqlContext context) : Controller
|
||||
/// </summary>
|
||||
/// <param name="ChapterId">ID of the Chapter</param>
|
||||
/// <response code="201">Created new Job</response>
|
||||
/// <response code="404">Could not find Chapter with ID</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("DownloadSingleChapterJob/{ChapterId}")]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateNewDownloadChapterJob(string ChapterId)
|
||||
{
|
||||
if(context.Chapters.Find(ChapterId) is null)
|
||||
return NotFound();
|
||||
Job job = new DownloadSingleChapterJob(ChapterId);
|
||||
return AddJob(job);
|
||||
return AddJobs([job]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new UpdateMetadataJob
|
||||
/// Create a new UpdateFilesDownloadedJob
|
||||
/// </summary>
|
||||
/// <param name="MangaId">ID of the Manga</param>
|
||||
/// <response code="201">Created new Job</response>
|
||||
/// <response code="201">Could not find Manga with ID</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("UpdateMetadataJob/{MangaId}")]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[HttpPut("UpdateFilesJob/{MangaId}")]
|
||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateUpdateMetadataJob(string MangaId)
|
||||
public IActionResult CreateUpdateFilesDownloadedJob(string MangaId)
|
||||
{
|
||||
Job job = new UpdateMetadataJob(0, MangaId);
|
||||
return AddJob(job);
|
||||
if(context.Manga.Find(MangaId) is null)
|
||||
return NotFound();
|
||||
Job job = new UpdateFilesDownloadedJob(0, MangaId);
|
||||
return AddJobs([job]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -133,7 +146,50 @@ public class JobController(PgsqlContext context) : Controller
|
||||
/// </summary>
|
||||
/// <response code="201">Created new Job</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("UpdateMetadataJob")]
|
||||
[HttpPut("UpdateAllFilesJob")]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateUpdateAllFilesDownloadedJob()
|
||||
{
|
||||
List<string> ids = context.Manga.Select(m => m.MangaId).ToList();
|
||||
List<UpdateFilesDownloadedJob> jobs = ids.Select(id => new UpdateFilesDownloadedJob(0, id)).ToList();
|
||||
try
|
||||
{
|
||||
context.Jobs.AddRange(jobs);
|
||||
context.SaveChanges();
|
||||
return Created();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return StatusCode(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new UpdateMetadataJob
|
||||
/// </summary>
|
||||
/// <param name="MangaId">ID of the Manga</param>
|
||||
/// <response code="201">Created new Job</response>
|
||||
/// <response code="404">Could not find Manga with ID</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("UpdateMetadataJob/{MangaId}")]
|
||||
[ProducesResponseType<string[]>(Status201Created, "application/json")]
|
||||
[ProducesResponseType(Status404NotFound)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateUpdateMetadataJob(string MangaId)
|
||||
{
|
||||
if(context.Manga.Find(MangaId) is null)
|
||||
return NotFound();
|
||||
Job job = new UpdateMetadataJob(0, MangaId);
|
||||
return AddJobs([job]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new UpdateMetadataJob for all Manga
|
||||
/// </summary>
|
||||
/// <response code="201">Created new Job</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPut("UpdateAllMetadataJob")]
|
||||
[ProducesResponseType(Status201Created)]
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public IActionResult CreateUpdateAllMetadataJob()
|
||||
@ -152,13 +208,13 @@ public class JobController(PgsqlContext context) : Controller
|
||||
}
|
||||
}
|
||||
|
||||
private IActionResult AddJob(Job job)
|
||||
private IActionResult AddJobs(Job[] jobs)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Jobs.Add(job);
|
||||
context.Jobs.AddRange(jobs);
|
||||
context.SaveChanges();
|
||||
return new CreatedResult(job.JobId, job);
|
||||
return new CreatedResult((string?)null, jobs.Select(j => j.JobId).ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -142,8 +142,8 @@ public class SearchController(PgsqlContext context) : Controller
|
||||
MangaTag? inDb = context.Tags.FirstOrDefault(t => t.Equals(mt));
|
||||
return inDb ?? mt;
|
||||
});
|
||||
manga.Tags = mergedTags.ToList();
|
||||
IEnumerable<MangaTag> newTags = manga.Tags.Where(mt => !context.Tags.Any(t => t.Tag.Equals(mt.Tag)));
|
||||
manga.MangaTags = mergedTags.ToList();
|
||||
IEnumerable<MangaTag> newTags = manga.MangaTags.Where(mt => !context.Tags.Any(t => t.Tag.Equals(mt.Tag)));
|
||||
context.Tags.AddRange(newTags);
|
||||
}
|
||||
|
||||
@ -195,6 +195,7 @@ public class SearchController(PgsqlContext context) : Controller
|
||||
context.Manga.Add(manga);
|
||||
|
||||
context.Jobs.Add(new DownloadMangaCoverJob(manga.MangaId));
|
||||
context.Jobs.Add(new RetrieveChaptersJob(0, manga.MangaId));
|
||||
|
||||
context.SaveChanges();
|
||||
return existing ?? manga;
|
||||
|
Reference in New Issue
Block a user