Resolve "Контроль уникальности названия" #213

Merged
VladimirZarayskiy merged 1 commits from 111-unique-name-control-conf into dev 2019-05-13 23:20:45 +04:00
3 changed files with 20 additions and 14 deletions

View File

@ -74,18 +74,9 @@ public class ConferenceController {
@PostMapping(value = "/conference", params = "save") @PostMapping(value = "/conference", params = "save")
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
conferenceService.filterEmptyDeadlines(conferenceDto); if (!conferenceService.save(conferenceDto, errors)) {
conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors);
conferenceDto.setName(conferenceDto.getTitle());
conferenceService.checkUniqueName(conferenceDto,
errors,
conferenceDto.getId(),
"title",
"Конференция с таким именем уже существует");
if (errors.hasErrors()) {
return CONFERENCE_PAGE; return CONFERENCE_PAGE;
} }
conferenceService.save(conferenceDto);
return String.format(REDIRECT_TO, CONFERENCES_PAGE); return String.format(REDIRECT_TO, CONFERENCES_PAGE);
} }

View File

@ -91,12 +91,26 @@ public class ConferenceService extends BaseService {
return new ConferenceDto(conferenceRepository.findOne(id)); return new ConferenceDto(conferenceRepository.findOne(id));
} }
public void save(ConferenceDto conferenceDto) throws IOException { public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException {
conferenceDto.setName(conferenceDto.getTitle());
filterEmptyDeadlines(conferenceDto);
checkEmptyFieldsOfDeadline(conferenceDto, errors);
checkUniqueName(conferenceDto,
errors,
conferenceDto.getId(),
"title",
"Конференция с таким именем уже существует");
if (errors.hasErrors()) {
return false;
}
if (isEmpty(conferenceDto.getId())) { if (isEmpty(conferenceDto.getId())) {
create(conferenceDto); create(conferenceDto);
} else { } else {
update(conferenceDto); update(conferenceDto);
} }
return true;
} }
@Transactional @Transactional

View File

@ -30,10 +30,11 @@
<label for="title">Название:</label> <label for="title">Название:</label>
<input class="form-control" th:field="*{title}" id="title" type="text" <input class="form-control" th:field="*{title}" id="title" type="text"
placeholder="Название конференции"/> placeholder="Название конференции"/>
</div>
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}" <p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
class="alert alert-danger">Incorrect title</p> class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p> <p class="help-block text-danger"></p>
</div>
<div class="form-group"> <div class="form-group">
<label for="url">URL:</label> <label for="url">URL:</label>