WIP: Resolve "Создание проекта из гранта" #240

Draft
a.vasin wants to merge 2 commits from 99-project-from-grant into dev
5 changed files with 31 additions and 8 deletions
Showing only changes of commit 26c1b78960 - Show all commits

View File

@ -67,7 +67,7 @@ public class ProjectController {
if (projectDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
}
if (errors.hasErrors()) {
if (errors.hasErrors() || !projectService.save(projectDto, errors)) {
return "/projects/project";
}
projectService.save(projectDto);

View File

@ -7,6 +7,7 @@ import org.thymeleaf.util.StringUtils;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.name.NameContainer;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto;
@ -18,7 +19,7 @@ import java.util.stream.Collectors;
import static ru.ulstu.core.util.StreamApiUtils.convert;
public class ProjectDto {
public class ProjectDto extends NameContainer {
private Integer id;
@NotEmpty

View File

@ -1,8 +1,13 @@
package ru.ulstu.project.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ru.ulstu.name.BaseRepository;
import ru.ulstu.project.model.Project;
public interface ProjectRepository extends JpaRepository<Project, Integer> {
public interface ProjectRepository extends JpaRepository<Project, Integer>, BaseRepository {
@Override
@Query("SELECT title FROM Project c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ")
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
}

View File

@ -2,12 +2,14 @@ package ru.ulstu.project.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.Errors;
import org.thymeleaf.util.StringUtils;
import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.file.service.FileService;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.grant.repository.GrantRepository;
import ru.ulstu.name.BaseService;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.repository.ProjectRepository;
@ -26,7 +28,7 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
@Service
public class ProjectService {
public class ProjectService extends BaseService {
private final static int MAX_DISPLAY_SIZE = 40;
private final ProjectRepository projectRepository;
@ -48,6 +50,7 @@ public class ProjectService {
this.fileService = fileService;
this.eventService = eventService;
this.userService = userService;
this.baseRepository = projectRepository;
}
public List<Project> findAll() {
@ -118,6 +121,19 @@ public class ProjectService {
return project;
}
public Boolean save(ProjectDto projectDto, Errors errors) throws IOException {
projectDto.setName(projectDto.getTitle());
checkUniqueName(projectDto,
errors,
projectDto.getId(),
"title",
"Проект с таким именем уже существует");
if (errors.hasErrors()) {
return false;
}
return true;
}
public Project save(ProjectDto projectDto) throws IOException {
if (isEmpty(projectDto.getId())) {
return create(projectDto);

View File

@ -30,10 +30,11 @@
<input class="form-control" id="title" type="text"
placeholder="Название проекта"
th:field="*{title}"/>
</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>
<div class="form-group">
<label for="status">Статус:</label>