2020-07-23 17:27:20 +02:00
|
|
|
package com.plannaplan.services;
|
|
|
|
|
2020-11-22 03:51:24 +01:00
|
|
|
import java.util.HashMap;
|
2020-08-08 14:14:42 +02:00
|
|
|
import java.util.List;
|
2020-11-22 03:51:24 +01:00
|
|
|
import java.util.Objects;
|
2020-09-21 17:45:52 +02:00
|
|
|
import java.util.Optional;
|
2020-11-22 03:51:24 +01:00
|
|
|
import java.util.stream.Collectors;
|
2020-08-08 14:14:42 +02:00
|
|
|
|
2020-08-06 15:18:18 +02:00
|
|
|
import com.plannaplan.entities.Groups;
|
2020-07-23 17:27:20 +02:00
|
|
|
import com.plannaplan.repositories.GroupRepository;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class GroupService {
|
|
|
|
@Autowired
|
|
|
|
private GroupRepository repo;
|
2020-08-06 15:18:18 +02:00
|
|
|
|
2020-08-08 00:08:36 +02:00
|
|
|
public GroupService() {
|
|
|
|
}
|
|
|
|
|
2020-09-21 17:45:52 +02:00
|
|
|
public Optional<Groups> find(int time, int capacity, String room) {
|
2020-08-06 15:18:18 +02:00
|
|
|
return this.repo.find(time, room, capacity);
|
|
|
|
}
|
|
|
|
|
2020-08-08 14:14:42 +02:00
|
|
|
public List<Groups> getGroupsByCourse(Long id) {
|
|
|
|
return this.repo.getByCourse(id);
|
|
|
|
}
|
|
|
|
|
2020-09-21 17:45:52 +02:00
|
|
|
public Groups save(Groups group) {
|
2020-11-17 19:36:56 +01:00
|
|
|
return this.repo.save(group);
|
2020-08-06 15:18:18 +02:00
|
|
|
}
|
2020-09-04 16:24:00 +02:00
|
|
|
|
2020-09-21 17:45:52 +02:00
|
|
|
public void delete(Groups groups) {
|
2020-09-16 17:23:33 +02:00
|
|
|
this.repo.delete(groups);
|
|
|
|
}
|
|
|
|
|
2020-09-21 17:45:52 +02:00
|
|
|
public int getGroupsAmmount() {
|
|
|
|
return (int) this.repo.count();
|
2020-09-04 16:24:00 +02:00
|
|
|
}
|
2020-09-29 17:21:34 +02:00
|
|
|
|
|
|
|
public Optional<Groups> getGroupById(Long id) {
|
|
|
|
return this.repo.findById(id);
|
2020-09-04 16:24:00 +02:00
|
|
|
}
|
2020-10-29 16:25:55 +01:00
|
|
|
|
2020-10-29 17:38:05 +01:00
|
|
|
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
2020-10-29 16:25:55 +01:00
|
|
|
for (Long oneId : ids) {
|
|
|
|
if (this.repo.existsById(oneId) == false) {
|
2020-10-29 17:38:05 +01:00
|
|
|
return Optional.of(oneId);
|
2020-10-29 16:25:55 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 17:38:05 +01:00
|
|
|
return Optional.empty();
|
2020-10-29 16:25:55 +01:00
|
|
|
|
|
|
|
}
|
2020-11-17 19:36:56 +01:00
|
|
|
|
2020-11-22 03:51:24 +01:00
|
|
|
public HashMap<Groups, Integer> getTakenPlaces(List<Groups> groups) {
|
|
|
|
HashMap<Groups, Integer> respoonse = new HashMap<>();
|
|
|
|
|
|
|
|
List<Object[]> respoonse2 = this.repo.getAssignedAmounts(
|
|
|
|
groups.stream().filter(Objects::nonNull).map(Groups::getId).collect(Collectors.toList()));
|
2020-11-26 13:58:27 +01:00
|
|
|
|
2020-11-22 03:51:24 +01:00
|
|
|
return respoonse;
|
2020-11-17 19:36:56 +01:00
|
|
|
}
|
2020-07-23 17:27:20 +02:00
|
|
|
}
|