Merge branch '12-' into 'master'
Resolve "Реализовать уведомление о смене статуса статьи" Closes #12 See merge request romanov73/ng-tracker!13
This commit is contained in:
commit
40c668905f
@ -7,6 +7,8 @@ import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.paper.model.PaperStatusDto;
|
||||
import ru.ulstu.paper.repository.PaperRepository;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
import ru.ulstu.user.service.MailService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -20,11 +22,14 @@ public class PaperService {
|
||||
|
||||
private final PaperRepository paperRepository;
|
||||
private final FileService fileService;
|
||||
public final MailService mailService;
|
||||
|
||||
|
||||
public PaperService(PaperRepository paperRepository,
|
||||
FileService fileService) {
|
||||
FileService fileService, MailService mailService) {
|
||||
this.paperRepository = paperRepository;
|
||||
this.fileService = fileService;
|
||||
this.mailService = mailService;
|
||||
}
|
||||
|
||||
public List<PaperDto> findAll() {
|
||||
@ -62,6 +67,9 @@ public class PaperService {
|
||||
@Transactional
|
||||
public Integer update(PaperDto paperDto) throws IOException {
|
||||
Paper paper = paperRepository.findOne(paperDto.getId());
|
||||
if(paper != null && paper.getStatus() != paperDto.getStatus()){
|
||||
sendMessageAboutStatusChange(paper.getStatus(),paperDto);
|
||||
}
|
||||
if (paperDto.getTmpFileName() != null && paper.getFileData() != null) {
|
||||
fileService.deleteFile(paper.getFileData());
|
||||
}
|
||||
@ -80,4 +88,12 @@ public class PaperService {
|
||||
public List<PaperStatusDto> getPaperStatuses() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user