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 4748d7d0..eeb8546b 100644 --- a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java +++ b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java @@ -1,5 +1,8 @@ package one.nem.lacerta.data; +import java.util.ArrayList; + +import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItemType; import one.nem.lacerta.model.LibraryItemPage; @@ -8,8 +11,8 @@ import one.nem.lacerta.model.document.DocumentDetail; public interface LacertaLibrary { // Get History - LibraryItemPage getRecentDocument(int limit); - LibraryItemPage getRecentDocument(int limit, int offset); + ArrayList getRecentDocument(int limit); + ArrayList getRecentDocument(int limit, int offset); // Get Library page LibraryItemPage getLibraryPage(int limit); 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 49f7303a..01a7209f 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 @@ -1,18 +1,48 @@ package one.nem.lacerta.data.impl; +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + 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.document.DocumentDetail; +import one.nem.lacerta.source.database.LacertaDatabase; +import one.nem.lacerta.source.database.common.DateTypeConverter; +import one.nem.lacerta.source.database.entity.DocumentEntity; +import one.nem.lacerta.utils.LacertaLogger; public class LacertaLibraryImpl implements LacertaLibrary { + + @Inject + LacertaLogger logger; + + @Inject + LacertaDatabase database; + @Override - public LibraryItemPage getRecentDocument(int limit) { - return null; + public ArrayList getRecentDocument(int limit) { + List documentEntities = database.documentDao().getRecentDocument(limit); + + ArrayList listItems = new ArrayList<>(); + for (DocumentEntity documentEntity : documentEntities) { + ListItem listItem = new ListItem(); + listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); + listItem.setTitle(documentEntity.title); + listItem.setDescription(DateFormat.getDateInstance().format(documentEntity.updatedAt)); + listItem.setItemId(documentEntity.id); + listItems.add(listItem); + } + return listItems; } @Override - public LibraryItemPage getRecentDocument(int limit, int offset) { - return null; + public ArrayList getRecentDocument(int limit, int offset) { + return null; // TODO-rca: Implement } @Override diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java index 47d547f8..df5aec9a 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java @@ -148,8 +148,8 @@ public class LacertaLibraryStubImpl implements LacertaLibrary { * @return ページオブジェクト */ @Override - public LibraryItemPage getRecentDocument(int limit) { - return getRecentDocumentPage(limit); + public ArrayList getRecentDocument(int limit) { + return getRecentDocumentPage(limit).getListItems(); } /** @@ -159,8 +159,8 @@ public class LacertaLibraryStubImpl implements LacertaLibrary { * @return ページオブジェクト */ @Override - public LibraryItemPage getRecentDocument(int limit, int offset) { - return getRecentDocumentPage(limit); + public ArrayList getRecentDocument(int limit, int offset) { + return getRecentDocumentPage(limit).getListItems(); } /** diff --git a/source/build.gradle b/source/build.gradle index 84bcd0a1..f4c32001 100644 --- a/source/build.gradle +++ b/source/build.gradle @@ -47,4 +47,7 @@ dependencies { // Utils モジュール implementation project(':utils') + // Model + implementation project(':model') + } \ No newline at end of file diff --git a/source/src/main/java/one/nem/lacerta/source/database/LacertaDatabase.java b/source/src/main/java/one/nem/lacerta/source/database/LacertaDatabase.java index bb8667ab..47e0e4bb 100644 --- a/source/src/main/java/one/nem/lacerta/source/database/LacertaDatabase.java +++ b/source/src/main/java/one/nem/lacerta/source/database/LacertaDatabase.java @@ -4,6 +4,8 @@ import androidx.room.Database; import androidx.room.RoomDatabase; // Entities +import one.nem.lacerta.source.database.dao.FolderDao; +import one.nem.lacerta.source.database.entity.FolderEntity; import one.nem.lacerta.source.database.entity.TagEntity; import one.nem.lacerta.source.database.entity.DocumentEntity; import one.nem.lacerta.source.database.entity.LibraryEntity; @@ -17,11 +19,12 @@ import one.nem.lacerta.source.database.dao.LibraryDao; import one.nem.lacerta.source.database.dao.VcsRevDao; import one.nem.lacerta.source.database.dao.VcsLogDao; -@Database(entities = {TagEntity.class, DocumentEntity.class, LibraryEntity.class, VcsRevEntity.class, VcsLogEntity.class}, version = 3) +@Database(entities = {TagEntity.class, DocumentEntity.class, LibraryEntity.class, VcsRevEntity.class, VcsLogEntity.class, FolderEntity.class}, version = 4) public abstract class LacertaDatabase extends RoomDatabase { public abstract TagDao tagDao(); public abstract DocumentDao documentDao(); public abstract LibraryDao libraryDao(); public abstract VcsRevDao vcsRevDao(); public abstract VcsLogDao vcsLogDao(); + public abstract FolderDao folderDao(); } diff --git a/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java b/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java index 265b20bc..802afb7f 100644 --- a/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java +++ b/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java @@ -28,6 +28,12 @@ public interface DocumentDao { @Query("SELECT * FROM Document WHERE id IN (:ids)") List findByIds(List ids); + @Query("SELECT * FROM Document WHERE public_path = :publicPath LIMIT :limit") + List findByPublicPathWithLimit(String publicPath, int limit); + + @Query("SELECT * FROM Document ORDER BY created_at DESC LIMIT :limit") + List getRecentDocument(int limit); + // Insert @Insert void insert(DocumentEntity document); diff --git a/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java b/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java new file mode 100644 index 00000000..1d429245 --- /dev/null +++ b/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java @@ -0,0 +1,23 @@ +package one.nem.lacerta.source.database.dao; + +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.Query; + +import one.nem.lacerta.source.database.entity.FolderEntity; + +@Dao +public interface FolderDao { + + @Query("SELECT * FROM Folder WHERE id = :id") + FolderEntity findById(String id); + + @Query("SELECT * FROM Folder WHERE public_path = :publicPath") + FolderEntity findByPublicPath(String publicPath); + + @Insert + void insert(FolderEntity folderEntity); + + @Insert + void insertAll(FolderEntity... folderEntities); +} diff --git a/source/src/main/java/one/nem/lacerta/source/database/entity/FolderEntity.java b/source/src/main/java/one/nem/lacerta/source/database/entity/FolderEntity.java new file mode 100644 index 00000000..f3a9091d --- /dev/null +++ b/source/src/main/java/one/nem/lacerta/source/database/entity/FolderEntity.java @@ -0,0 +1,22 @@ +package one.nem.lacerta.source.database.entity; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +@Entity(tableName = "folder") +public class FolderEntity { + + @PrimaryKey + @ColumnInfo(name = "id") + @NonNull + public String id; // フォルダID + + @ColumnInfo(name = "title") + public String name; // フォルダ名 + + @ColumnInfo(name = "public_path") + public String publicPath; // 公開パス + +}