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

72 lines
1.7 KiB
Java
Raw Normal View History

2020-07-25 10:38:19 +02:00
package com.plannaplan.services;
2020-09-30 19:15:32 +02:00
import java.util.List;
import java.util.Optional;
2020-09-30 19:15:32 +02:00
import com.plannaplan.entities.Assignment;
2020-09-30 19:15:32 +02:00
import com.plannaplan.entities.Commision;
2021-01-02 14:35:00 +01:00
import com.plannaplan.entities.User;
2020-07-25 10:38:19 +02:00
import com.plannaplan.repositories.AssignmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
2020-11-20 13:20:44 +01:00
/**
2021-01-02 14:35:00 +01:00
* Service of Assignment which can save assignments, diplay assignments, get
* ammount of assigments.
2020-11-20 13:20:44 +01:00
*/
2020-07-25 10:38:19 +02:00
@Service
2020-09-30 19:15:32 +02:00
public class AssignmentService {
2020-07-25 10:38:19 +02:00
@Autowired
2020-07-25 10:56:11 +02:00
private AssignmentRepository repo;
2020-07-25 10:38:19 +02:00
2021-01-02 14:35:00 +01:00
@Autowired
private UserService userService;
2020-07-27 16:44:04 +02:00
public AssignmentService() {
2020-07-25 10:38:19 +02:00
}
/**
* Save given assignment
2021-01-02 14:35:00 +01:00
*
* @param assignment assignment to save
* @return assignment saved assignment with database id
*/
public Assignment save(Assignment assignment) {
return this.repo.save(assignment);
}
2020-09-30 19:15:32 +02:00
/*
2021-01-02 14:35:00 +01:00
* getCommisionAssignments Return id of the commision
*/
2020-09-30 19:15:32 +02:00
public List<Assignment> getCommisionAssignments(Commision com) {
return this.repo.getByCommision(com.getId());
}
2020-10-02 17:18:03 +02:00
/*
2021-01-02 14:35:00 +01:00
* getAssignmentsAmmount Return count assignments ammount
*/
2020-10-02 17:18:03 +02:00
public long getAssignmentsAmmount() {
return this.repo.count();
}
/**
* Get assigmnent by id
2021-01-02 14:35:00 +01:00
*
* @param id id of assigmnent
* @return Optional of assignment
*/
public Optional<Assignment> getById(Long id) {
return this.repo.findById(id);
}
2021-01-02 14:35:00 +01:00
public void callAcceptAlgorythm() {
final List<User> students = this.userService.getStudentsSortedByRanking();
students.forEach(e -> {
System.out.println(e.getRanking());
});
}
}