WIP: Resolve "Создание проекта из гранта" #240
@ -67,7 +67,7 @@ public class ProjectController {
|
|||||||
if (projectDto.getDeadlines().isEmpty()) {
|
if (projectDto.getDeadlines().isEmpty()) {
|
||||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
||||||
}
|
}
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors() || !projectService.save(projectDto, errors)) {
|
||||||
return "/projects/project";
|
return "/projects/project";
|
||||||
}
|
}
|
||||||
projectService.save(projectDto);
|
projectService.save(projectDto);
|
||||||
|
@ -7,6 +7,7 @@ import org.thymeleaf.util.StringUtils;
|
|||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto extends NameContainer {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package ru.ulstu.project.repository;
|
package ru.ulstu.project.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ package ru.ulstu.project.service;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
import org.thymeleaf.util.StringUtils;
|
import org.thymeleaf.util.StringUtils;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.repository.GrantRepository;
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
|
import ru.ulstu.name.BaseService;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.project.repository.ProjectRepository;
|
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;
|
import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ProjectService {
|
public class ProjectService extends BaseService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
|
|
||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
@ -48,6 +50,7 @@ public class ProjectService {
|
|||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.baseRepository = projectRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Project> findAll() {
|
public List<Project> findAll() {
|
||||||
@ -118,6 +121,19 @@ public class ProjectService {
|
|||||||
return project;
|
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 {
|
public Project save(ProjectDto projectDto) throws IOException {
|
||||||
if (isEmpty(projectDto.getId())) {
|
if (isEmpty(projectDto.getId())) {
|
||||||
return create(projectDto);
|
return create(projectDto);
|
||||||
|
@ -10,7 +10,10 @@
|
|||||||
<span th:replace="projects/fragments/projectStatusFragment :: projectStatus(projectStatus=${project.status})"/>
|
<span th:replace="projects/fragments/projectStatusFragment :: projectStatus(projectStatus=${project.status})"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-10 text-right">
|
<div class="col col-10 text-right">
|
||||||
|
<a th:href="'project?id='+${project.id}">
|
||||||
<h7 class="service-heading" th:text="${project.title}"> title</h7>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,10 +30,11 @@
|
|||||||
<input class="form-control" id="title" type="text"
|
<input class="form-control" id="title" type="text"
|
||||||
placeholder="Название проекта"
|
placeholder="Название проекта"
|
||||||
th:field="*{title}"/>
|
th:field="*{title}"/>
|
||||||
|
</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="status">Статус:</label>
|
<label for="status">Статус:</label>
|
||||||
|
Loading…
Reference in New Issue
Block a user