Skip to content

Commit 842b5fa

Browse files
authored
Merge pull request #902 from MatzElectronics/demo
Update DAO to access shared projects by user
2 parents 3a56f76 + 76924a1 commit 842b5fa

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,19 @@ List<ProjectRecord> getSharedProjects(
7373
Integer offset,
7474
Long idUser);
7575

76+
List<ProjectRecord> getSharedProjectsByUser(
77+
TableSort sort,
78+
TableOrder order,
79+
Integer limit,
80+
Integer offset,
81+
Long idUser);
82+
7683
int countUserProjects(Long idUser);
7784

7885
int countSharedProjects(Long idUser);
7986

87+
int countSharedProjectsByUser(Long idUser);
88+
8089
ProjectRecord cloneProject(Long idProject);
8190

8291
boolean deleteProject(Long idProject);

src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,34 @@ public List<ProjectRecord> getUserProjects(Long idUser, TableSort sort, TableOrd
347347
public List<ProjectRecord> getSharedProjects(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) {
348348
LOG.info("Retreive shared projects.");
349349

350+
SortField<?> orderField = sort == null ? Tables.PROJECT.NAME.asc() : sort.getField().asc();
351+
if (TableOrder.desc == order) {
352+
orderField = sort == null ? Tables.PROJECT.NAME.desc() : sort.getField().desc();
353+
}
354+
Condition conditions = Tables.PROJECT.SHARED.eq(Boolean.TRUE);
355+
if (idUser != null) {
356+
conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser));
357+
}
358+
return create.selectFrom(Tables.PROJECT)
359+
.where(conditions)
360+
.orderBy(orderField).limit(limit).offset(offset)
361+
.fetch();
362+
}
363+
364+
/**
365+
* TODO: add details.
366+
*
367+
* @param sort
368+
* @param order
369+
* @param limit
370+
* @param offset
371+
* @param idUser
372+
* @return
373+
*/
374+
@Override
375+
public List<ProjectRecord> getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) {
376+
LOG.info("Retreive shared projects.");
377+
350378
SortField<?> orderField = sort == null ? Tables.PROJECT.NAME.asc() : sort.getField().asc();
351379
if (TableOrder.desc == order) {
352380
orderField = sort == null ? Tables.PROJECT.NAME.desc() : sort.getField().desc();
@@ -385,6 +413,24 @@ public int countUserProjects(Long idUser) {
385413
public int countSharedProjects(Long idUser) {
386414
LOG.info("Count shared projects for user {}.", idUser);
387415

416+
Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE);
417+
if (idUser != null) {
418+
conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser));
419+
}
420+
return create.fetchCount(Tables.PROJECT, conditions);
421+
}
422+
423+
/**
424+
*
425+
* TODO: add details.
426+
*
427+
* @param idUser
428+
* @return
429+
*/
430+
@Override
431+
public int countSharedProjectsByUser(Long idUser) {
432+
LOG.info("Count shared projects for user {}.", idUser);
433+
388434
Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE);
389435
if (idUser != null) {
390436
conditions = conditions.and(Tables.PROJECT.ID_USER.eq(idUser));

src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public List<ProjectRecord> getSharedProjects(TableSort sort, TableOrder order, I
8888

8989
@Override
9090
public List<ProjectRecord> getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) {
91-
return projectDao.getSharedProjects(sort, order, limit, offset, idUser);
91+
return projectDao.getSharedProjectsByUser(sort, order, limit, offset, idUser);
9292
}
9393

9494
@Override
@@ -103,7 +103,7 @@ public int countSharedProjects() {
103103

104104
@Override
105105
public int countSharedProjectsByUser(Long idUser) {
106-
return projectDao.countSharedProjects(idUser);
106+
return projectDao.countSharedProjectsByUser(idUser);
107107
}
108108

109109
@Override

0 commit comments

Comments
 (0)