diff --git a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java index cb19b425..6d424179 100644 --- a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java +++ b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java @@ -21,4 +21,7 @@ public interface LacertaLibrary { CompletableFuture getLibraryPage(String pageId, int limit); CompletableFuture getLibraryPage(String pageId, int limit, int offset); + // Create Folder + CompletableFuture createFolder(String path, String name); + } diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java index 7fcf9cb5..7d7f7aaa 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java @@ -5,6 +5,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import javax.inject.Inject; @@ -13,6 +14,7 @@ import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItemType; +import one.nem.lacerta.model.PublicPath; import one.nem.lacerta.model.document.DocumentDetail; import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.common.DateTypeConverter; @@ -143,4 +145,26 @@ public class LacertaLibraryImpl implements LacertaLibrary { return null; }); } + + @Override + public CompletableFuture createFolder(String parentId, String name) { + return CompletableFuture.supplyAsync(() -> { + + FolderEntity parentFolderEntity = database.folderDao().findById(parentId); + PublicPath publicPath; + if (parentFolderEntity == null) { + publicPath = new PublicPath().resolve("/"); + } else { + publicPath = new PublicPath().resolve(parentFolderEntity.publicPath); + } + publicPath = publicPath.resolve(name); + + FolderEntity folderEntity = new FolderEntity(); + folderEntity.id = UUID.randomUUID().toString(); + folderEntity.name = name; + folderEntity.publicPath = publicPath.toString(); + database.folderDao().insert(folderEntity); + return folderEntity.id; + }); + } }