Works with native query now needst to be hql
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
@ -21,4 +22,10 @@ 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);
|
||||
|
||||
// @Query("SELECT group, COUNT(*) AS assinged_times FROM Assignment WHERE
|
||||
// isPastAssignment=false GROUP BY 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 (7,9,10,12)")
|
||||
|
||||
List<Object[]> getAssignedAmounts(@Param("ids") List<Long> groupIds);
|
||||
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.repositories.GroupRepository;
|
||||
@ -51,7 +54,17 @@ public class GroupService {
|
||||
|
||||
}
|
||||
|
||||
public int getAssignedAmount(Long groupId) {
|
||||
return this.repo.getAssignedAmount(groupId).orElse(Integer.valueOf(0)).intValue();
|
||||
public HashMap<Groups, Integer> getTakenPlaces(List<Groups> groups) {
|
||||
HashMap<Groups, Integer> respoonse = new HashMap<>();
|
||||
// groups.forEach(group -> {
|
||||
// final Long id = group.getId();
|
||||
// final Integer ammount =
|
||||
// this.repo.getAssignedAmount(id).orElse(Integer.valueOf(0)).intValue();
|
||||
// respoonse.put(group, ammount);
|
||||
// });
|
||||
|
||||
List<Object[]> respoonse2 = this.repo.getAssignedAmounts(
|
||||
groups.stream().filter(Objects::nonNull).map(Groups::getId).collect(Collectors.toList()));
|
||||
return respoonse;
|
||||
}
|
||||
}
|
@ -31,4 +31,9 @@ public class GroupServiceTest {
|
||||
groupService.delete(group);
|
||||
assertTrue(this.groupService.getGroupsAmmount() == startAmmount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetGroupsAssignmentsAmmounts() {
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user