1.1 --- a/src/main/java/de/uapcore/lightpit/dao/postgres/PGProjectDao.java Sun May 24 15:30:43 2020 +0200 1.2 +++ b/src/main/java/de/uapcore/lightpit/dao/postgres/PGProjectDao.java Sat May 30 15:26:15 2020 +0200 1.3 @@ -46,6 +46,7 @@ 1.4 public final class PGProjectDao implements ProjectDao { 1.5 1.6 private final PreparedStatement insert, update, list, find; 1.7 + private final PreparedStatement issue_summary; 1.8 1.9 public PGProjectDao(Connection connection) throws SQLException { 1.10 list = connection.prepareStatement( 1.11 @@ -62,6 +63,14 @@ 1.12 "left join lpit_user owner on lpit_project.owner = owner.userid " + 1.13 "where projectid = ?"); 1.14 1.15 + issue_summary = connection.prepareStatement( 1.16 + "select phase, count(*) as total "+ 1.17 + "from lpit_issue " + 1.18 + "join lpit_issue_phases using(status) " + 1.19 + "where project = ? "+ 1.20 + "group by phase " 1.21 + ); 1.22 + 1.23 insert = connection.prepareStatement( 1.24 "insert into lpit_project (name, description, repourl, owner) values (?, ?, ?, ?)" 1.25 ); 1.26 @@ -89,6 +98,26 @@ 1.27 return proj; 1.28 } 1.29 1.30 + private void mapIssueSummary(Project proj) throws SQLException { 1.31 + issue_summary.setInt(1, proj.getId()); 1.32 + final var result = issue_summary.executeQuery(); 1.33 + while (result.next()) { 1.34 + final var phase = result.getInt("phase"); 1.35 + final var total = result.getInt("total"); 1.36 + switch(phase) { 1.37 + case 0: 1.38 + proj.setOpenIssues(total); 1.39 + break; 1.40 + case 1: 1.41 + proj.setActiveIssues(total); 1.42 + break; 1.43 + case 2: 1.44 + proj.setDoneIssues(total); 1.45 + break; 1.46 + } 1.47 + } 1.48 + } 1.49 + 1.50 @Override 1.51 public void save(Project instance) throws SQLException { 1.52 Objects.requireNonNull(instance.getName()); 1.53 @@ -116,7 +145,9 @@ 1.54 List<Project> projects = new ArrayList<>(); 1.55 try (var result = list.executeQuery()) { 1.56 while (result.next()) { 1.57 - projects.add(mapColumns(result)); 1.58 + final var project = mapColumns(result); 1.59 + mapIssueSummary(project); 1.60 + projects.add(project); 1.61 } 1.62 } 1.63 return projects; 1.64 @@ -127,7 +158,9 @@ 1.65 find.setInt(1, id); 1.66 try (var result = find.executeQuery()) { 1.67 if (result.next()) { 1.68 - return mapColumns(result); 1.69 + final var project = mapColumns(result); 1.70 + mapIssueSummary(project); 1.71 + return project; 1.72 } else { 1.73 return null; 1.74 }