backend/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java

54 lines
1.2 KiB
Java
Raw Normal View History

package com.plannaplan.services;
2020-08-08 14:14:42 +02:00
import java.util.List;
import java.util.Optional;
2020-08-08 14:14:42 +02:00
import com.plannaplan.entities.Groups;
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-08 00:08:36 +02:00
public GroupService() {
}
public Optional<Groups> find(int time, int capacity, String room) {
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);
}
public Groups save(Groups group) {
this.repo.save(group);
return group;
}
2020-09-04 16:24:00 +02:00
public void delete(Groups groups) {
this.repo.delete(groups);
}
public int getGroupsAmmount() {
return (int) this.repo.count();
2020-09-04 16:24:00 +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
}
}