48 lines
1.8 KiB
Java
Executable File
48 lines
1.8 KiB
Java
Executable File
package com.plannaplan.repositories;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
import com.plannaplan.entities.Groups;
|
|
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
import org.springframework.data.jpa.repository.Query;
|
|
import org.springframework.data.repository.query.Param;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
/**
|
|
* GroupRepository.find:
|
|
* Return list of:
|
|
* SELECT * FROM Groups WHERE time = i AND room = j AND capacity = k .
|
|
*
|
|
* Where i, j, k, ?1, ?2, ?3 are equale to variables.
|
|
*
|
|
* GroupRepository.getByCourse:
|
|
* Return list of:
|
|
* SELECT * FROM Groups WHERE course_id = i .
|
|
*
|
|
* Where i, ?1 are equale to variables.
|
|
*/
|
|
@Repository
|
|
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
|
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
|
Optional<Groups> find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
|
|
|
@Query("FROM Groups WHERE course_id = ?1")
|
|
List<Groups> getByCourse(@Param("id") Long id);
|
|
|
|
@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)")
|
|
List<Object[]> getAssignedAmounts(@Param("ids") List<Long> groupIds);
|
|
|
|
} |