mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 09:43:15 +00:00
getLibraryPage実装WIP
This commit is contained in:
parent
bb7b628d2f
commit
3130be88be
|
@ -1,6 +1,7 @@
|
||||||
package one.nem.lacerta.data.impl;
|
package one.nem.lacerta.data.impl;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -16,6 +17,7 @@ import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
import one.nem.lacerta.source.database.LacertaDatabase;
|
import one.nem.lacerta.source.database.LacertaDatabase;
|
||||||
import one.nem.lacerta.source.database.common.DateTypeConverter;
|
import one.nem.lacerta.source.database.common.DateTypeConverter;
|
||||||
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
||||||
|
import one.nem.lacerta.source.database.entity.FolderEntity;
|
||||||
import one.nem.lacerta.utils.LacertaLogger;
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
|
||||||
public class LacertaLibraryImpl implements LacertaLibrary {
|
public class LacertaLibraryImpl implements LacertaLibrary {
|
||||||
|
@ -60,10 +62,48 @@ public class LacertaLibraryImpl implements LacertaLibrary {
|
||||||
return null; // TODO-rca: Implement
|
return null; // TODO-rca: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
private CompletableFuture<List<FolderEntity>> getFolderEntitiesByPublicPath(String publicPath) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
return database.folderDao().findByPublicPathWithLimit(publicPath, 10); // TODO-rca: ハードコーディングやめる
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<List<DocumentEntity>> getDocumentEntitiesByPublicPath(String publicPath) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
return database.documentDao().findByPublicPathWithLimit(publicPath, 10); // TODO-rca: ハードコーディングやめる
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<LibraryItemPage> getLibraryPage(int limit) {
|
public CompletableFuture<LibraryItemPage> getLibraryPage(int limit) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
return null;
|
LibraryItemPage libraryItemPage = new LibraryItemPage();
|
||||||
|
|
||||||
|
List<FolderEntity> folderEntities = getFolderEntitiesByPublicPath("/").join();
|
||||||
|
List<DocumentEntity> documentEntities = getDocumentEntitiesByPublicPath("/").join();
|
||||||
|
|
||||||
|
ArrayList<ListItem> listItems = new ArrayList<>();
|
||||||
|
for (FolderEntity folderEntity : folderEntities) {
|
||||||
|
ListItem listItem = new ListItem();
|
||||||
|
listItem.setItemType(ListItemType.ITEM_TYPE_FOLDER);
|
||||||
|
listItem.setTitle(folderEntity.name);
|
||||||
|
listItem.setDescription("フォルダ"); // TODO-rca: ハードコーディングやめる
|
||||||
|
listItem.setItemId(folderEntity.id);
|
||||||
|
listItems.add(listItem);
|
||||||
|
}
|
||||||
|
for (DocumentEntity documentEntity : documentEntities) {
|
||||||
|
ListItem listItem = new ListItem();
|
||||||
|
listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT);
|
||||||
|
listItem.setTitle(documentEntity.title);
|
||||||
|
listItem.setDescription(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm").format(documentEntity.updatedAt.toInstant()));
|
||||||
|
listItem.setItemId(documentEntity.id);
|
||||||
|
listItems.add(listItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
libraryItemPage.setListItems(listItems);
|
||||||
|
|
||||||
|
return libraryItemPage;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import androidx.room.Insert;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
import androidx.room.Update;
|
import androidx.room.Update;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
import one.nem.lacerta.source.database.entity.DocumentEntity;
|
||||||
|
|
|
@ -4,6 +4,9 @@ import androidx.room.Dao;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import one.nem.lacerta.source.database.entity.FolderEntity;
|
import one.nem.lacerta.source.database.entity.FolderEntity;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
|
@ -15,6 +18,9 @@ public interface FolderDao {
|
||||||
@Query("SELECT * FROM Folder WHERE public_path = :publicPath")
|
@Query("SELECT * FROM Folder WHERE public_path = :publicPath")
|
||||||
FolderEntity findByPublicPath(String publicPath);
|
FolderEntity findByPublicPath(String publicPath);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Folder WHERE public_path = :publicPath LIMIT :limit")
|
||||||
|
List<FolderEntity> findByPublicPathWithLimit(String publicPath, int limit);
|
||||||
|
|
||||||
@Insert
|
@Insert
|
||||||
void insert(FolderEntity folderEntity);
|
void insert(FolderEntity folderEntity);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user