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

Draft
a.vasin wants to merge 2 commits from 99-project-from-grant into dev
6 changed files with 35 additions and 9 deletions

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

@ -10,7 +10,10 @@
<span th:replace="projects/fragments/projectStatusFragment :: projectStatus(projectStatus=${project.status})"/>
</div>
<div class="col col-10 text-right">
<a th:href="'project?id='+${project.id}">
<h7 class="service-heading" th:text="${project.title}"> title</h7>
</a>
<p class="text-muted" th:text="${project.status.statusName}"> status</p>
</div>
</div>
</div>

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>