move classes, add deadline to entities, fix db changelogs
parent
590cd16abe
commit
d71a8d2c83
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.deadline.model;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Deadline extends BaseEntity {
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Deadline() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Deadline(Date deadlineDate, String description) {
|
||||||
|
this.date = deadlineDate;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.deadline.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class DeadlineDto {
|
||||||
|
private final Integer id;
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
private final Date date;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public DeadlineDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("description") String description,
|
||||||
|
@JsonProperty("date") Date date) {
|
||||||
|
this.id = id;
|
||||||
|
this.description = description;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Deadline deadline) {
|
||||||
|
this.id = deadline.getId();
|
||||||
|
this.description = deadline.getDescription();
|
||||||
|
this.date = deadline.getDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package ru.ulstu.deadline.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package ru.ulstu.deadline.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeadlineService {
|
||||||
|
private final DeadlineRepository deadlineRepository;
|
||||||
|
|
||||||
|
public DeadlineService(DeadlineRepository deadlineRepository) {
|
||||||
|
this.deadlineRepository = deadlineRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> saveOrCreate(List<DeadlineDto> deadlines) {
|
||||||
|
return deadlines.stream().map(deadlineDto -> {
|
||||||
|
return deadlineDto.getId() != null ? update(deadlineDto) : create(deadlineDto);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline update(DeadlineDto deadlineDto) {
|
||||||
|
Deadline deadline = deadlineRepository.findOne(deadlineDto.getId());
|
||||||
|
deadlineRepository.save(copyFromDto(deadline, deadlineDto));
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline create(DeadlineDto deadlineDto) {
|
||||||
|
Deadline newDeadline = copyFromDto(new Deadline(), deadlineDto);
|
||||||
|
newDeadline = deadlineRepository.save(newDeadline);
|
||||||
|
return newDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deadline copyFromDto(Deadline deadline, DeadlineDto deadlineDto) {
|
||||||
|
deadline.setDate(deadlineDto.getDate());
|
||||||
|
deadline.setDescription(deadlineDto.getDescription());
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +0,0 @@
|
|||||||
package ru.ulstu.grant.model;
|
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
|
||||||
import ru.ulstu.file.model.FileData;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Deadline extends BaseEntity {
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "grant_id")
|
|
||||||
private Integer grantId;
|
|
||||||
|
|
||||||
public Integer getGrantId() { return grantId;}
|
|
||||||
public void setGrantId(Integer grantId) { this.grantId = grantId; }
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package ru.ulstu.grant.model;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class DeadlineDto {
|
|
||||||
private final Integer id;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final Integer grantId;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public DeadlineDto(@JsonProperty("id") Integer id,
|
|
||||||
@JsonProperty("grantId") Integer grantId){
|
|
||||||
this.id = id;
|
|
||||||
this.grantId = grantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeadlineDto(Deadline deadline) {
|
|
||||||
this.id = deadline.getId();
|
|
||||||
this.grantId = deadline.getGrantId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getGrantId() { return grantId; }
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package ru.ulstu.grant.model;
|
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
|
||||||
import ru.ulstu.file.model.FileData;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Project extends BaseEntity {
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) { this.title = title; }
|
|
||||||
}
|
|
@ -0,0 +1,39 @@
|
|||||||
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Project extends BaseEntity {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "project_id")
|
||||||
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> getDeadlines() {
|
||||||
|
return deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeadlines(List<Deadline> deadlines) {
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,35 @@
|
|||||||
package ru.ulstu.grant.model;
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
import ru.ulstu.deadline.model.DeadlineDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import java.util.List;
|
||||||
import java.util.Date;
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto {
|
||||||
private final Integer id;
|
private final Integer id;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private final String title;
|
private final String title;
|
||||||
|
|
||||||
|
private final List<DeadlineDto> deadlines;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ProjectDto(@JsonProperty("id") Integer id,
|
public ProjectDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title){
|
@JsonProperty("title") String title,
|
||||||
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectDto(Project project) {
|
public ProjectDto(Project project) {
|
||||||
this.id = project.getId();
|
this.id = project.getId();
|
||||||
this.title = project.getTitle();
|
this.title = project.getTitle();
|
||||||
|
this.deadlines = convert(project.getDeadlines(), DeadlineDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
Loading…
Reference in New Issue