Skip to content

Commit e94b913

Browse files
author
Rick Verkuijlen
committed
Added hours from project
1 parent 61f5b24 commit e94b913

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
<scope>test</scope>
7070
<version>${jacoco.version}</version>
7171
</dependency>
72+
<dependency>
73+
<groupId>org.projectlombok</groupId>
74+
<artifactId>lombok</artifactId>
75+
</dependency>
7276

7377
</dependencies>
7478

src/main/java/context/MySQLHourContext.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,16 @@ public List<Hour> getAllFromWeek(Date start, Date end) {
155155
}
156156
return result;
157157
}
158+
159+
public List<Hour> getAllFromProject(String projectId) {
160+
List<Hour> result = new ArrayList<>();
161+
try (Session session = HibernateUtil.getSessionFactory().openSession()) {
162+
Query query = session.createQuery("FROM Hour WHERE projectId = :projectId");
163+
query.setParameter("projectId", projectId);
164+
result = query.getResultList();
165+
} catch (Exception e) {
166+
log.error(e.toString());
167+
}
168+
return result;
169+
}
158170
}

src/main/java/controllers/HourController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,17 @@ HttpEntity<List<Hour>> getWeeklyOverview(@PathVariable("week") String week,
7070
}
7171
}
7272

73+
@GetMapping(value="/{projectId}")
74+
public @ResponseBody
75+
HttpEntity<List<Hour>> getHourOverviewById(@PathVariable("projectId") String projectId) {
76+
List<Hour> hours = hourRepository.getAllHoursFromProject(projectId);
77+
78+
if(hours != null && !hours.isEmpty()) {
79+
return new ResponseEntity<>(hours, HttpStatus.OK);
80+
} else {
81+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
82+
}
83+
}
84+
7385

7486
}

src/main/java/objects/Project.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ public class Project extends ResourceSupport {
5757
@Column(name = "lastModified",
5858
updatable = false, insertable = false)
5959
private LocalDateTime lastModified;
60+
6061
}

src/main/java/repositories/HourRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,8 @@ public List<Hour> getAllHoursFromWeek(String week, String year) {
105105

106106
return allHours;
107107
}
108+
109+
public List<Hour> getAllHoursFromProject(String projectId) {
110+
return hourContext.getAllFromProject(projectId);
111+
}
108112
}

0 commit comments

Comments
 (0)