#111 save method refactor
This commit is contained in:
parent
d846192046
commit
6044d6f8e3
@ -74,18 +74,9 @@ public class ConferenceController {
|
||||
|
||||
@PostMapping(value = "/conference", params = "save")
|
||||
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||
conferenceService.filterEmptyDeadlines(conferenceDto);
|
||||
conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors);
|
||||
conferenceDto.setName(conferenceDto.getTitle());
|
||||
conferenceService.checkUniqueName(conferenceDto,
|
||||
errors,
|
||||
conferenceDto.getId(),
|
||||
"title",
|
||||
"Конференция с таким именем уже существует");
|
||||
if (errors.hasErrors()) {
|
||||
if (!conferenceService.save(conferenceDto, errors)) {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
conferenceService.save(conferenceDto);
|
||||
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
||||
}
|
||||
|
||||
|
@ -91,12 +91,26 @@ public class ConferenceService extends BaseService {
|
||||
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())) {
|
||||
create(conferenceDto);
|
||||
} else {
|
||||
update(conferenceDto);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -30,11 +30,12 @@
|
||||
<label for="title">Название:</label>
|
||||
<input class="form-control" th:field="*{title}" id="title" type="text"
|
||||
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>
|
||||
|
||||
<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">
|
||||
<label for="url">URL:</label>
|
||||
<input class="form-control" th:field="*{url}" id="url" type="text"
|
||||
|
Loading…
Reference in New Issue
Block a user