Added service method tests + javadocs
This commit is contained in:
@ -21,11 +21,15 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
|
||||
@Query("SELECT COUNT(*) AS assinged_times FROM Assignment WHERE isPastAssignment=false GROUP BY group HAVING group_id=?1")
|
||||
Optional<Number> getAssignedAmount(Long groupId);
|
||||
|
||||
/**
|
||||
* PLAIN SQL QUERY: SELECT group_id, COUNT(*) assinged_times FROM assignment
|
||||
* WHERE is_past_assignment=0 GROUP BY group_id HAVING group_id IN (:ids)")
|
||||
*
|
||||
* @param groupIds list of groups ids
|
||||
* @return list of objects arrays where first object is Groups instance and
|
||||
* second is Long that is taken places value
|
||||
*/
|
||||
@Query("SELECT group, COUNT(*) AS assinged_times FROM Assignment a WHERE a.isPastAssignment=false GROUP BY a.group HAVING group_id IN (:ids)")
|
||||
// @Query(nativeQuery = true, value = "SELECT group_id, COUNT(*) AS
|
||||
// assinged_times FROM assignment WHERE is_past_assignment=0 GROUP BY group_id
|
||||
// HAVING group_id IN (:ids)")
|
||||
|
||||
List<Object[]> getAssignedAmounts(@Param("ids") List<Long> groupIds);
|
||||
|
||||
}
|
@ -54,12 +54,22 @@ public class GroupService {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Groups, Integer> getTakenPlaces(List<Groups> groups) {
|
||||
HashMap<Groups, Integer> respoonse = new HashMap<>();
|
||||
/**
|
||||
*
|
||||
* @param groups list of groups you want to get taken places ammount
|
||||
* @return HashMap<Long, Integer> where Long is group id and Integer is how many
|
||||
* places in gorup is already taken
|
||||
*/
|
||||
public HashMap<Long, Integer> getTakenPlaces(List<Groups> groups) {
|
||||
HashMap<Long, Integer> response = new HashMap<>();
|
||||
|
||||
List<Object[]> respoonse2 = this.repo.getAssignedAmounts(
|
||||
List<Object[]> respoonses = this.repo.getAssignedAmounts(
|
||||
groups.stream().filter(Objects::nonNull).map(Groups::getId).collect(Collectors.toList()));
|
||||
|
||||
return respoonse;
|
||||
for (Object[] element : respoonses) {
|
||||
response.put(((Groups) element[0]).getId(), ((Long) element[1]).intValue());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user