This commit is contained in:
Alyona 2018-10-28 00:26:09 +04:00
parent 7f54394b44
commit b3f8b334ef
2 changed files with 14 additions and 26 deletions

View File

@ -1,25 +0,0 @@
package ru.ulstu.paper.service;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.MailService;
import java.util.List;
public class PaperMessages {
public final MailService mailService;
public PaperMessages(MailService mailService){
this.mailService = mailService;
}
private void sendMessageAboutStatusChange(Paper.PaperStatus oldStatus, PaperDto paper){
List<UserDto> users = paper.getAuthors();
for (UserDto user: users) {
mailService.sendEmail(user.getEmail(), "Обновление статуса статьи",
"Статус статьи " + paper.getTitle() + " сменился с " + oldStatus.getName()
+ " на " + paper.getStatus().getName());
}
}
}

View File

@ -7,6 +7,8 @@ import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.model.PaperStatusDto;
import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.PaperRepository;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.MailService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -20,11 +22,14 @@ public class PaperService {
private final PaperRepository paperRepository; private final PaperRepository paperRepository;
private final FileService fileService; private final FileService fileService;
public final MailService mailService;
public PaperService(PaperRepository paperRepository, public PaperService(PaperRepository paperRepository,
FileService fileService) { FileService fileService, MailService mailService) {
this.paperRepository = paperRepository; this.paperRepository = paperRepository;
this.fileService = fileService; this.fileService = fileService;
this.mailService = mailService;
} }
public List<PaperDto> findAll() { public List<PaperDto> findAll() {
@ -80,4 +85,12 @@ public class PaperService {
public List<PaperStatusDto> getPaperStatuses() { public List<PaperStatusDto> getPaperStatuses() {
return convert(Arrays.asList(Paper.PaperStatus.values()), status ->new PaperStatusDto(status)); return convert(Arrays.asList(Paper.PaperStatus.values()), status ->new PaperStatusDto(status));
} }
private void sendMessageAboutStatusChange(Paper.PaperStatus oldStatus, PaperDto paper){
for (UserDto user: paper.getAuthors()) {
mailService.sendEmail(user.getEmail(), "Обновление статуса статьи",
"Статус статьи " + paper.getTitle() + " сменился с " + oldStatus.getName()
+ " на " + paper.getStatus().getName());
}
}
} }