From 76924a1532e5aefcde66413a6b691aad9a61842b Mon Sep 17 00:00:00 2001 From: Matthew Matz Date: Tue, 31 Jan 2017 15:29:38 -0800 Subject: [PATCH] update DAO implementation for shared projects by user --- .../server/blocklyprop/db/dao/ProjectDao.java | 9 ++++ .../db/dao/impl/ProjectDaoImpl.java | 46 +++++++++++++++++++ .../services/impl/ProjectServiceImpl.java | 4 +- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java b/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java index 7e46d0b3..60334cc7 100644 --- a/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java +++ b/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java @@ -73,10 +73,19 @@ List getSharedProjects( Integer offset, Long idUser); + List getSharedProjectsByUser( + TableSort sort, + TableOrder order, + Integer limit, + Integer offset, + Long idUser); + int countUserProjects(Long idUser); int countSharedProjects(Long idUser); + int countSharedProjectsByUser(Long idUser); + ProjectRecord cloneProject(Long idProject); boolean deleteProject(Long idProject); diff --git a/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java b/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java index 5ffe50a8..c87c0b1d 100644 --- a/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java +++ b/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java @@ -347,6 +347,34 @@ public List getUserProjects(Long idUser, TableSort sort, TableOrd public List getSharedProjects(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) { LOG.info("Retreive shared projects."); + SortField orderField = sort == null ? Tables.PROJECT.NAME.asc() : sort.getField().asc(); + if (TableOrder.desc == order) { + orderField = sort == null ? Tables.PROJECT.NAME.desc() : sort.getField().desc(); + } + Condition conditions = Tables.PROJECT.SHARED.eq(Boolean.TRUE); + if (idUser != null) { + conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser)); + } + return create.selectFrom(Tables.PROJECT) + .where(conditions) + .orderBy(orderField).limit(limit).offset(offset) + .fetch(); + } + + /** + * TODO: add details. + * + * @param sort + * @param order + * @param limit + * @param offset + * @param idUser + * @return + */ + @Override + public List getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) { + LOG.info("Retreive shared projects."); + SortField orderField = sort == null ? Tables.PROJECT.NAME.asc() : sort.getField().asc(); if (TableOrder.desc == order) { orderField = sort == null ? Tables.PROJECT.NAME.desc() : sort.getField().desc(); @@ -385,6 +413,24 @@ public int countUserProjects(Long idUser) { public int countSharedProjects(Long idUser) { LOG.info("Count shared projects for user {}.", idUser); + Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE); + if (idUser != null) { + conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser)); + } + return create.fetchCount(Tables.PROJECT, conditions); + } + + /** + * + * TODO: add details. + * + * @param idUser + * @return + */ + @Override + public int countSharedProjectsByUser(Long idUser) { + LOG.info("Count shared projects for user {}.", idUser); + Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE); if (idUser != null) { conditions = conditions.and(Tables.PROJECT.ID_USER.eq(idUser)); diff --git a/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java b/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java index b0a04d8f..69fcca98 100644 --- a/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java +++ b/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java @@ -88,7 +88,7 @@ public List getSharedProjects(TableSort sort, TableOrder order, I @Override public List getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) { - return projectDao.getSharedProjects(sort, order, limit, offset, idUser); + return projectDao.getSharedProjectsByUser(sort, order, limit, offset, idUser); } @Override @@ -103,7 +103,7 @@ public int countSharedProjects() { @Override public int countSharedProjectsByUser(Long idUser) { - return projectDao.countSharedProjects(idUser); + return projectDao.countSharedProjectsByUser(idUser); } @Override