diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 5b5eb4a..3244ccb 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -2,20 +2,16 @@ package ru.ulstu.project.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; -import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.*; -import ru.ulstu.deadline.model.Deadline; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; import springfox.documentation.annotations.ApiIgnore; -import javax.validation.Valid; -import java.io.IOException; import java.util.List; -import java.util.stream.Collectors; - -import static liquibase.util.StringUtils.isEmpty; @Controller() @RequestMapping(value = "/projects") @@ -36,4 +32,18 @@ public class ProjectController { public void getProjects(ModelMap modelMap) { modelMap.put("projects", projectService.findAllDto()); } + + @GetMapping("/project") + public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + if (id != null && id > 0) { + modelMap.put("projectDto", projectService.findOneDto(id)); + } else { + modelMap.put("projectDto", new ProjectDto()); + } + } + + @ModelAttribute("allStatuses") + public List getProjectStatuses() { + return projectService.getProjectStatuses(); + } } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 06722a1..2e0e86c 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -3,24 +3,60 @@ package ru.ulstu.project.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.grant.model.Grant; import javax.persistence.CascadeType; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.List; @Entity public class Project extends BaseEntity { + public enum ProjectStatus { + APPLICATION("Заявка"), + ON_COMPETITION("Отправлен на конкурс"), + SUCCESSFUL_PASSAGE("Успешное прохождение"), + IN_WORK("В работе"), + COMPLETED("Завершен"), + FAILED("Провалены сроки"); + + private String statusName; + + ProjectStatus(String statusName) { + this.statusName = statusName; + } + + public String getStatusName() { + return statusName; + } + } @NotBlank private String title; + @Enumerated(value = EnumType.STRING) + private ProjectStatus status = ProjectStatus.APPLICATION; + + @NotNull + private String description; + @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") private List deadlines = new ArrayList<>(); + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "grant_id") + private Grant grant; + + @NotNull + private String repository; + public String getTitle() { return title; } @@ -29,6 +65,38 @@ public class Project extends BaseEntity { this.title = title; } + public ProjectStatus getStatus() { + return status; + } + + public void setStatus(ProjectStatus status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Grant getGrant() { + return grant; + } + + public void setGrant(Grant grant) { + this.grant = grant; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + public List getDeadlines() { return deadlines; } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index db7fc75..6c83d59 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.grant.model.GrantDto; import java.util.ArrayList; import java.util.List; @@ -13,8 +14,11 @@ public class ProjectDto { @NotEmpty private String title; - + private Project.ProjectStatus status; + private String description; private List deadlines = new ArrayList<>(); + private GrantDto grant; + private String repository; public ProjectDto() { } @@ -26,9 +30,17 @@ public class ProjectDto { @JsonCreator public ProjectDto(@JsonProperty("id") Integer id, @JsonProperty("title") String title, + @JsonProperty("status") Project.ProjectStatus status, + @JsonProperty("description") String description, + @JsonProperty("grant") GrantDto grant, + @JsonProperty("repository") String repository, @JsonProperty("deadlines") List deadlines) { this.id = id; this.title = title; + this.status = status; + this.description = description; + this.grant = grant; + this.repository = repository; this.deadlines = deadlines; } @@ -36,6 +48,10 @@ public class ProjectDto { public ProjectDto(Project project) { this.id = project.getId(); this.title = project.getTitle(); + this.status = project.getStatus(); + this.description = project.getDescription(); + this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); + this.repository = project.getRepository(); this.deadlines = project.getDeadlines(); } @@ -55,6 +71,38 @@ public class ProjectDto { this.title = title; } + public Project.ProjectStatus getStatus() { + return status; + } + + public void setStatus(Project.ProjectStatus status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public GrantDto getGrant() { + return grant; + } + + public void setGrant(GrantDto grant) { + this.grant = grant; + } + + public String getRepository() { + return repository; + } + + public void setRepository(String repository) { + this.repository = repository; + } + public List getDeadlines() { return deadlines; } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 78a9d3c..99d8919 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -8,6 +8,7 @@ import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; +import java.util.Arrays; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -36,6 +37,14 @@ public class ProjectService { return projects; } + public ProjectDto findOneDto(Integer id) { + return new ProjectDto(projectRepository.findOne(id)); + } + + public List getProjectStatuses() { + return Arrays.asList(Project.ProjectStatus.values()); + } + @Transactional public Project create(ProjectDto projectDto) { Project newProject = copyFromDto(new Project(), projectDto); diff --git a/src/main/resources/db/changelog-20190418_000000-schema.xml b/src/main/resources/db/changelog-20190418_000000-schema.xml new file mode 100644 index 0000000..31cf21c --- /dev/null +++ b/src/main/resources/db/changelog-20190418_000000-schema.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 67d3c40..22d3cbd 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -24,5 +24,6 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/fragments/projectLineFragment.html b/src/main/resources/templates/projects/fragments/projectLineFragment.html new file mode 100644 index 0000000..3605273 --- /dev/null +++ b/src/main/resources/templates/projects/fragments/projectLineFragment.html @@ -0,0 +1,18 @@ + + + + + + +
+
+ + + + + + +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/fragments/projectNavigationFragment.html b/src/main/resources/templates/projects/fragments/projectNavigationFragment.html index c26d8b8..75dfff6 100644 --- a/src/main/resources/templates/projects/fragments/projectNavigationFragment.html +++ b/src/main/resources/templates/projects/fragments/projectNavigationFragment.html @@ -16,8 +16,8 @@ diff --git a/src/main/resources/templates/projects/fragments/projectStatusFragment.html b/src/main/resources/templates/projects/fragments/projectStatusFragment.html new file mode 100644 index 0000000..e5da374 --- /dev/null +++ b/src/main/resources/templates/projects/fragments/projectStatusFragment.html @@ -0,0 +1,31 @@ + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html new file mode 100644 index 0000000..3d356a7 --- /dev/null +++ b/src/main/resources/templates/projects/project.html @@ -0,0 +1,141 @@ + + + + + + + +
+ +
+
+
+
+

Редактирование проекта

+
+
+
+
+
+
+
+
+ +
+ + +

Incorrect title

+

+
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ + +

Incorrect repository link

+

+
+ +
+ +
+ +
+ +
+
+ +
+
+ + +
+
+

Incorrect title

+
+
+ +
+ +
+ +
+ +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+
+ + +
+ + diff --git a/src/main/resources/templates/projects/projects.html b/src/main/resources/templates/projects/projects.html index 0336770..fd19383 100644 --- a/src/main/resources/templates/projects/projects.html +++ b/src/main/resources/templates/projects/projects.html @@ -18,8 +18,8 @@
- -
+ +