Skip to content

Commit a53ede0

Browse files
committed
Made a temprary end-point to migrate chapters
1 parent aaee446 commit a53ede0

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Inshapardaz.Domain.Ports.Command.Library.Book.Chapter;
2+
using Inshapardaz.Domain.Ports.Query.Library.Book.Chapter;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Paramore.Brighter;
5+
using Paramore.Darker;
26

37
namespace Inshapardaz.Api.Controllers;
48

59
public class HomeController : Controller
610
{
11+
private readonly IAmACommandProcessor _commandProcessor;
12+
private readonly IQueryProcessor _queryProcessor;
13+
14+
public HomeController(IAmACommandProcessor commandProcessor,
15+
IQueryProcessor queryProcessor)
16+
{
17+
_commandProcessor = commandProcessor;
18+
_queryProcessor = queryProcessor;
19+
}
20+
721
[HttpGet("health/check")]
822
public IActionResult GetHeathCheck()
923
{
1024
return Ok();
1125
}
26+
27+
[HttpPost("/libraries/{libraryId}/books/{bookId}/migrateChapters")]
28+
public async Task<IActionResult> MigrateBook(int libraryId, int bookId, CancellationToken token)
29+
{
30+
var query = new GetChaptersByBookQuery(libraryId, bookId);
31+
var chapters = await _queryProcessor.ExecuteAsync(query, cancellationToken: token);
32+
foreach (var chapter in chapters)
33+
{
34+
foreach (var content in chapter.Contents)
35+
{
36+
var chapterContentQuery = new GetChapterContentQuery(libraryId, bookId, chapter.ChapterNumber, content.Language);
37+
38+
var chapterContents = await _queryProcessor.ExecuteAsync(chapterContentQuery, cancellationToken: token);
39+
40+
if (chapterContents != null && chapterContents.FileId == null)
41+
{
42+
var request = new UpdateChapterContentRequest(libraryId, bookId,
43+
chapter.ChapterNumber, chapterContents.Text, chapterContents.Language);
44+
await _commandProcessor.SendAsync(request, cancellationToken: token);
45+
}
46+
}
47+
}
48+
49+
return Ok("Migrated chapters successfully.");
50+
}
1251
}
1352

0 commit comments

Comments
 (0)