2020-07-23 17:27:20 +02:00
|
|
|
package com.plannaplan.services;
|
|
|
|
|
2020-08-08 14:14:42 +02:00
|
|
|
import java.util.List;
|
2020-09-21 17:45:52 +02:00
|
|
|
import java.util.Optional;
|
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;
|
|
|
|
|
2020-11-20 13:20:44 +01:00
|
|
|
/**
|
|
|
|
* Service of GroupService which can find(optional), get(By Course, Groups Ammount, Group By Id, find Not Existing Group), save, delete group.
|
|
|
|
*/
|
|
|
|
|
2020-07-23 17:27:20 +02:00
|
|
|
@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-08-06 15:18:18 +02:00
|
|
|
this.repo.save(group);
|
2020-09-21 17:45:52 +02:00
|
|
|
return 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-07-23 17:27:20 +02:00
|
|
|
}
|