backend/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java
Marcin Woźniak f51979484f
Added new columns into a FileMigrator and etc
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
2020-12-26 13:17:39 +01:00

51 lines
2.0 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 zajCykId = ?1 AND grNr = ?2")
Optional<Groups> find(@Param("zajCykId") Integer zaj_cyk_id, @Param("grNr") Integer gr_nr);
@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);
}