Resolve "Контроль уникальности названия" #213
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -30,11 +30,12 @@
|
|||||||
<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="Название конференции"/>
|
||||||
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
|
|
||||||
class="alert alert-danger">Incorrect title</p>
|
|
||||||
<p class="help-block text-danger"></p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
|
||||||
|
class="alert alert-danger">Incorrect title</p>
|
||||||
|
<p class="help-block text-danger"></p>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="url">URL:</label>
|
<label for="url">URL:</label>
|
||||||
<input class="form-control" th:field="*{url}" id="url" type="text"
|
<input class="form-control" th:field="*{url}" id="url" type="text"
|
||||||
|
Loading…
Reference in New Issue
Block a user