use of pl.morecraft.dev.settler.domain.QTransaction in project Settler by EmhyrVarEmreis.
the class CategoryService method getCategoriesWithValue.
public ResponseEntity<List<CategoryWithValueDTO>> getCategoriesWithValue(Long userId) {
if (Objects.isNull(userId) || userId < 0) {
userId = Security.currentUser().getId();
}
QCategory category = QCategory.category;
QTransaction transaction = QTransaction.transaction;
List<Tuple> fetch = new JPAQuery<>(entityManager).from(category, transaction).select(category, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(transaction.categories.contains(category)).groupBy(category.code, category.description).orderBy(transaction.value.sum().desc()).fetch();
ModelMapper preparedModelMapper = getModelMapper();
List<CategoryWithValueDTO> categoryWithValueDTOList = new ArrayList<>(fetch.size());
for (Tuple tuple : fetch) {
Category c = tuple.get(category);
Double d = tuple.get(transaction.value.sum());
if (Objects.nonNull(c)) {
categoryWithValueDTOList.add(new CategoryWithValueDTO(userId, preparedModelMapper.map(c, CategoryDTO.class), d));
}
}
return new ResponseEntity<>(categoryWithValueDTOList, HttpStatus.OK);
}
use of pl.morecraft.dev.settler.domain.QTransaction in project Settler by EmhyrVarEmreis.
the class UserService method getUsersWithValue.
public ResponseEntity<List<UserWithValueDTO>> getUsersWithValue(Long userId) {
if (Objects.isNull(userId) || userId < 0) {
userId = Security.currentUser().getId();
}
QUser user = QUser.user;
QTransaction transaction = QTransaction.transaction;
List<Tuple> fetch = new JPAQuery<>(entityManager).from(user, transaction).select(user, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(user.id.ne(userId)).where(transaction.owners.any().id.user.eq(user).or(transaction.contractors.any().id.user.eq(user))).groupBy(user.id, user.firstName, user.lastName, user.email, user.created, user.avatar, user.login, user.accountExpireDate).orderBy(transaction.value.sum().desc()).fetch();
ModelMapper preparedModelMapper = getModelMapper();
List<UserWithValueDTO> userWithValueDTOList = new ArrayList<>(fetch.size());
for (Tuple tuple : fetch) {
User u = tuple.get(user);
Double d = tuple.get(transaction.value.sum());
if (Objects.nonNull(u)) {
userWithValueDTOList.add(new UserWithValueDTO(userId, preparedModelMapper.map(u, String.class), d));
}
}
return new ResponseEntity<>(userWithValueDTOList, HttpStatus.OK);
}
Aggregations