Resolved confilics with master

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2020-12-02 12:16:31 +01:00
19 changed files with 590 additions and 87 deletions

@ -1,7 +1,11 @@
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 java.util.function.Function;
import com.plannaplan.entities.Groups;
import com.plannaplan.repositories.GroupRepository;
@ -30,8 +34,7 @@ public class GroupService {
}
public Groups save(Groups group) {
this.repo.save(group);
return group;
return this.repo.save(group);
}
public void delete(Groups groups) {
@ -55,4 +58,30 @@ public class GroupService {
return Optional.empty();
}
/**
*
* @param groups list of groups you want to get taken places ammount
* @return HashMap<Long, Integer> where Long is group id and Integer is how many
* places in gorup is already taken
*/
public HashMap<Long, Integer> getTakenPlaces(List<Groups> groups) {
HashMap<Long, Integer> response = new HashMap<>();
List<Object[]> respoonses = this.repo
.getAssignedAmounts(groups.stream().filter(Objects::nonNull).map(new Function<Groups, Long>() {
@Override
public Long apply(Groups p) {
final Long id = p.getId();
response.put(id, 0);
return id;
}
}).collect(Collectors.toList()));
for (Object[] element : respoonses) {
response.put(((Groups) element[0]).getId(), ((Long) element[1]).intValue());
}
return response;
}
}