mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-22 16:03:15 +00:00
Merge pull request #77 from lacerta-doc/feature/lacerta_library_recent
Feature/lacerta library recent
This commit is contained in:
commit
5c3d811979
|
@ -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<ListItem> getRecentDocument(int limit);
|
||||
ArrayList<ListItem> getRecentDocument(int limit, int offset);
|
||||
|
||||
// Get Library page
|
||||
LibraryItemPage getLibraryPage(int limit);
|
||||
|
|
|
@ -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<ListItem> getRecentDocument(int limit) {
|
||||
List<DocumentEntity> documentEntities = database.documentDao().getRecentDocument(limit);
|
||||
|
||||
ArrayList<ListItem> 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<ListItem> getRecentDocument(int limit, int offset) {
|
||||
return null; // TODO-rca: Implement
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -148,8 +148,8 @@ public class LacertaLibraryStubImpl implements LacertaLibrary {
|
|||
* @return ページオブジェクト
|
||||
*/
|
||||
@Override
|
||||
public LibraryItemPage getRecentDocument(int limit) {
|
||||
return getRecentDocumentPage(limit);
|
||||
public ArrayList<ListItem> 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<ListItem> getRecentDocument(int limit, int offset) {
|
||||
return getRecentDocumentPage(limit).getListItems();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,4 +47,7 @@ dependencies {
|
|||
// Utils モジュール
|
||||
implementation project(':utils')
|
||||
|
||||
// Model
|
||||
implementation project(':model')
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,12 @@ public interface DocumentDao {
|
|||
@Query("SELECT * FROM Document WHERE id IN (:ids)")
|
||||
List<DocumentEntity> findByIds(List<String> ids);
|
||||
|
||||
@Query("SELECT * FROM Document WHERE public_path = :publicPath LIMIT :limit")
|
||||
List<DocumentEntity> findByPublicPathWithLimit(String publicPath, int limit);
|
||||
|
||||
@Query("SELECT * FROM Document ORDER BY created_at DESC LIMIT :limit")
|
||||
List<DocumentEntity> getRecentDocument(int limit);
|
||||
|
||||
// Insert
|
||||
@Insert
|
||||
void insert(DocumentEntity document);
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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; // 公開パス
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user