Search in sources :

Example 1 with UserListDTO

use of pl.morecraft.dev.settler.web.dto.UserListDTO in project Settler by EmhyrVarEmreis.

the class TransactionService method getMostUsedUsers.

public ResponseEntity<List<UserListDTO>> getMostUsedUsers(Long count) {
    QUser user = QUser.user;
    QTransaction transaction = QTransaction.transaction;
    QRedistribution redistribution = QRedistribution.redistribution;
    List<User> userList = new JPAQuery<>(entityManager).from(user).select(user).where(user.id.in(JPAExpressions.selectFrom(transaction).select(redistribution.id.user.id).leftJoin(redistribution).on(redistribution.id.parent.id.eq(transaction.id)).where(transaction.creator.id.eq(Security.currentUser().getId())).groupBy(redistribution.id.user.id).orderBy(redistribution.id.user.id.count().desc()).limit(count))).fetch();
    Type listType = new TypeToken<List<UserListDTO>>() {
    }.getType();
    List<UserListDTO> userListDTOList = getModelMapper().map(userList, listType);
    return new ResponseEntity<>(userListDTOList, HttpStatus.OK);
}
Also used : TransactionType(pl.morecraft.dev.settler.domain.dictionaries.TransactionType) OperationType(pl.morecraft.dev.settler.domain.dictionaries.OperationType) RedistributionType(pl.morecraft.dev.settler.domain.dictionaries.RedistributionType) Type(java.lang.reflect.Type) ResponseEntity(org.springframework.http.ResponseEntity) UserListDTO(pl.morecraft.dev.settler.web.dto.UserListDTO) ArrayList(java.util.ArrayList) List(java.util.List) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Aggregations

JPAQuery (com.querydsl.jpa.impl.JPAQuery)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ResponseEntity (org.springframework.http.ResponseEntity)1 OperationType (pl.morecraft.dev.settler.domain.dictionaries.OperationType)1 RedistributionType (pl.morecraft.dev.settler.domain.dictionaries.RedistributionType)1 TransactionType (pl.morecraft.dev.settler.domain.dictionaries.TransactionType)1 UserListDTO (pl.morecraft.dev.settler.web.dto.UserListDTO)1