createFolder関数実装

This commit is contained in:
ろむねこ 2024-01-22 11:34:03 +09:00
parent 839433dbb1
commit b05ee22c29
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 27 additions and 0 deletions

View File

@ -21,4 +21,7 @@ public interface LacertaLibrary {
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit);
CompletableFuture<LibraryItemPage> getLibraryPage(String pageId, int limit, int offset);
// Create Folder
CompletableFuture<String> createFolder(String path, String name);
}

View File

@ -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<String> 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;
});
}
}