From acc5b166d51118605b3e249886e660d8060653c5 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:24:12 +0900 Subject: [PATCH] =?UTF-8?q?CompletableFeature=E3=82=92=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=97=E3=81=A6=E5=87=A6=E7=90=86=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/data/impl/DocumentImpl.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java index 1253d0a4..ab0f41ef 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java @@ -3,6 +3,7 @@ package one.nem.lacerta.data.impl; import java.util.ArrayList; import java.util.Date; import java.util.UUID; +import java.util.concurrent.CompletableFuture; // Hilt import javax.inject.Inject; @@ -49,31 +50,30 @@ public class DocumentImpl implements Document { @Override - public DocumentDetail createDocument(DocumentMeta meta) { - DocumentDetail detail = new DocumentDetail(); - detail.setMeta(meta); - detail.setPages(new ArrayList<>()); + public CompletableFuture createDocument(DocumentMeta meta) { + return CompletableFuture.supplyAsync(() -> { + DocumentDetail detail = new DocumentDetail(); + detail.setMeta(meta); + detail.setPages(new ArrayList<>()); + // Create DocumentEntity + DocumentEntity documentEntity = new DocumentEntity(); + documentEntity.id = meta.getId(); + documentEntity.title = meta.getTitle(); + documentEntity.author = meta.getAuthor(); + documentEntity.defaultBranch = meta.getDefaultBranch(); + documentEntity.updatedAt = meta.getUpdatedAt(); + documentEntity.createdAt = meta.getCreatedAt(); + documentEntity.publicPath = meta.getPath().getStringPath(); + documentEntity.tagIds = meta.getTagIds(); - // TODO-rca: UIスレッドから追い出す + database.documentDao().insert(documentEntity); - // Create DocumentEntity - DocumentEntity documentEntity = new DocumentEntity(); - documentEntity.id = meta.getId(); - documentEntity.title = meta.getTitle(); - documentEntity.author = meta.getAuthor(); - documentEntity.defaultBranch = meta.getDefaultBranch(); - documentEntity.updatedAt = meta.getUpdatedAt(); - documentEntity.createdAt = meta.getCreatedAt(); - documentEntity.publicPath = meta.getPath().getStringPath(); - documentEntity.tagIds = meta.getTagIds(); + // Vcs + LacertaVcs vcs = vcsFactory.create(meta.getId()); + vcs.createDocument(meta.getId()); - database.documentDao().insert(documentEntity); - - // Vcs - LacertaVcs vcs = vcsFactory.create(meta.getId()); - vcs.createDocument(meta.getId()); - - return detail; + return detail; + }); } @Override @@ -102,6 +102,6 @@ public class DocumentImpl implements Document { @Override public DocumentDetail getDocument(String documentId) { - return null; + } }