Docs + email sending
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -7,6 +8,7 @@ import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.EmailAcceptedData;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -28,6 +30,9 @@ public class AssignmentService {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
public AssignmentService() {
|
||||
}
|
||||
|
||||
@ -65,11 +70,19 @@ public class AssignmentService {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* this method will activate accept algorythm for all students. Algorythm is
|
||||
* takeing each student in order defined by ranking and accept for him groups
|
||||
* that are joinable for him
|
||||
*/
|
||||
public void callAcceptAlgorythm() {
|
||||
final List<User> students = this.userService.getStudentsSortedByRanking();
|
||||
|
||||
students.forEach(e -> {
|
||||
final Optional<Commision> com = this.service.getNewestCommision(e);
|
||||
final List<Groups> accepted = new ArrayList<>();
|
||||
final List<Groups> removed = new ArrayList<>();
|
||||
|
||||
if (com.isPresent()) {
|
||||
final List<Assignment> assignments = this.getCommisionAssignments(com.get());
|
||||
assignments.forEach(a -> {
|
||||
@ -77,9 +90,13 @@ public class AssignmentService {
|
||||
if (group.getCapacity() > group.getRegisteredStudents().size()) {
|
||||
e.claimGroup(group);
|
||||
this.userService.save(e);
|
||||
accepted.add(group);
|
||||
} else {
|
||||
removed.add(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.emailService.sendAcceptationResult(e, new EmailAcceptedData(accepted, removed));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.EmailAcceptedData;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
@ -35,4 +38,20 @@ public class EmailService {
|
||||
mailMessage.setText(message);
|
||||
emailSender.send(mailMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends email with infromation about accepted groups
|
||||
*
|
||||
* @param user user to send a mail
|
||||
* @param data EmailAcceptedData instance containing informations about accepted
|
||||
* and removed groups
|
||||
*/
|
||||
public void sendAcceptationResult(User user, EmailAcceptedData data) {
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
mailMessage.setFrom(appEmail);
|
||||
mailMessage.setTo(user.getEmail());
|
||||
mailMessage.setSubject("[PlanNaPlan] Akceptacja przedmiotów");
|
||||
mailMessage.setText(data.getEmailMessage());
|
||||
emailSender.send(mailMessage);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user