Delete DeadlineDTO and update usages
This commit is contained in:
parent
99d85a5648
commit
29df7120bf
@ -1,5 +1,8 @@
|
||||
package ru.ulstu.deadline.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
@ -13,6 +16,7 @@ public class Deadline extends BaseEntity {
|
||||
private String description;
|
||||
|
||||
@Temporal(value = TemporalType.TIMESTAMP)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date date;
|
||||
|
||||
public Deadline() {
|
||||
@ -23,6 +27,15 @@ public class Deadline extends BaseEntity {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public Deadline(@JsonProperty("id") Integer id,
|
||||
@JsonProperty("description") String description,
|
||||
@JsonProperty("date") Date date) {
|
||||
this.setId(id);
|
||||
this.description = description;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
package ru.ulstu.deadline.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DeadlineDto {
|
||||
private Integer id;
|
||||
|
||||
private String description;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date date;
|
||||
|
||||
public DeadlineDto() {
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -17,29 +16,29 @@ public class DeadlineService {
|
||||
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());
|
||||
public List<Deadline> saveOrCreate(List<Deadline> deadlines) {
|
||||
return deadlines
|
||||
.stream()
|
||||
.map(deadline -> {
|
||||
return deadline.getId() != null ? update(deadline) : create(deadline);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Deadline update(DeadlineDto deadlineDto) {
|
||||
Deadline deadline = deadlineRepository.findOne(deadlineDto.getId());
|
||||
deadlineRepository.save(copyFromDto(deadline, deadlineDto));
|
||||
return deadline;
|
||||
public Deadline update(Deadline deadline) {
|
||||
Deadline updateDeadline = deadlineRepository.findOne(deadline.getId());
|
||||
updateDeadline.setDate(deadline.getDate());
|
||||
updateDeadline.setDescription(deadline.getDescription());
|
||||
deadlineRepository.save(updateDeadline);
|
||||
return updateDeadline;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Deadline create(DeadlineDto deadlineDto) {
|
||||
Deadline newDeadline = copyFromDto(new Deadline(), deadlineDto);
|
||||
public Deadline create(Deadline deadline) {
|
||||
Deadline newDeadline = new Deadline();
|
||||
newDeadline.setDate(deadline.getDate());
|
||||
newDeadline.setDescription(deadline.getDescription());
|
||||
newDeadline = deadlineRepository.save(newDeadline);
|
||||
return newDeadline;
|
||||
}
|
||||
|
||||
private Deadline copyFromDto(Deadline deadline, DeadlineDto deadlineDto) {
|
||||
deadline.setDate(deadlineDto.getDate());
|
||||
deadline.setDescription(deadlineDto.getDescription());
|
||||
return deadline;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.grant.model.GrantDto;
|
||||
import ru.ulstu.grant.service.GrantService;
|
||||
@ -69,7 +69,7 @@ public class GrantController {
|
||||
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
||||
filterEmptyDeadlines(grantDto);
|
||||
hasErrors(errors, GRANT_PAGE);
|
||||
grantDto.getDeadlines().add(new DeadlineDto());
|
||||
grantDto.getDeadlines().add(new Deadline());
|
||||
return GRANT_PAGE;
|
||||
}
|
||||
|
||||
|
@ -3,33 +3,31 @@ package ru.ulstu.grant.model;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||
|
||||
public class GrantDto {
|
||||
private Integer id;
|
||||
@NotEmpty
|
||||
private String title;
|
||||
private Grant.GrantStatus status;
|
||||
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
private String comment;
|
||||
private String applicationFileName;
|
||||
private ProjectDto project;
|
||||
|
||||
public GrantDto() {
|
||||
deadlines.add(new DeadlineDto());
|
||||
deadlines.add(new Deadline());
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public GrantDto(@JsonProperty("id") Integer id,
|
||||
@JsonProperty("title") String title,
|
||||
@JsonProperty("status") Grant.GrantStatus status,
|
||||
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||
@JsonProperty("comment") String comment,
|
||||
@JsonProperty("project") ProjectDto project) {
|
||||
this.id = id;
|
||||
@ -45,7 +43,7 @@ public class GrantDto {
|
||||
this.id = grant.getId();
|
||||
this.title = grant.getTitle();
|
||||
this.status = grant.getStatus();
|
||||
this.deadlines = convert(grant.getDeadlines(), DeadlineDto::new);
|
||||
this.deadlines = grant.getDeadlines();
|
||||
this.comment = grant.getComment();
|
||||
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
||||
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
||||
@ -75,11 +73,11 @@ public class GrantDto {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public List<DeadlineDto> getDeadlines() {
|
||||
public List<Deadline> getDeadlines() {
|
||||
return deadlines;
|
||||
}
|
||||
|
||||
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||
public void setDeadlines(List<Deadline> deadlines) {
|
||||
this.deadlines = deadlines;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.paper.model.PaperFilterDto;
|
||||
@ -80,7 +80,7 @@ public class PaperController {
|
||||
if (errors.hasErrors()) {
|
||||
return "/papers/paper";
|
||||
}
|
||||
paperDto.getDeadlines().add(new DeadlineDto());
|
||||
paperDto.getDeadlines().add(new Deadline());
|
||||
return "/papers/paper";
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
@ -27,7 +27,7 @@ public class PaperDto {
|
||||
private Date createDate;
|
||||
private Date updateDate;
|
||||
@NotEmpty
|
||||
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
private String comment;
|
||||
private Boolean locked;
|
||||
private String tmpFileName;
|
||||
@ -39,7 +39,7 @@ public class PaperDto {
|
||||
private Integer filterAuthorId;
|
||||
|
||||
public PaperDto() {
|
||||
deadlines.add(new DeadlineDto());
|
||||
deadlines.add(new Deadline());
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
@ -48,7 +48,7 @@ public class PaperDto {
|
||||
@JsonProperty("status") Paper.PaperStatus status,
|
||||
@JsonProperty("createDate") Date createDate,
|
||||
@JsonProperty("updateDate") Date updateDate,
|
||||
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||
@JsonProperty("comment") String comment,
|
||||
@JsonProperty("locked") Boolean locked,
|
||||
@JsonProperty("tmpFileName") String tmpFileName,
|
||||
@ -75,7 +75,7 @@ public class PaperDto {
|
||||
this.status = paper.getStatus();
|
||||
this.createDate = paper.getCreateDate();
|
||||
this.updateDate = paper.getUpdateDate();
|
||||
this.deadlines = convert(paper.getDeadlines(), DeadlineDto::new);
|
||||
this.deadlines = paper.getDeadlines();
|
||||
this.comment = paper.getComment();
|
||||
this.locked = paper.getLocked();
|
||||
this.tmpFileName = null;
|
||||
@ -126,11 +126,11 @@ public class PaperDto {
|
||||
this.updateDate = updateDate;
|
||||
}
|
||||
|
||||
public List<DeadlineDto> getDeadlines() {
|
||||
public List<Deadline> getDeadlines() {
|
||||
return deadlines;
|
||||
}
|
||||
|
||||
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||
public void setDeadlines(List<Deadline> deadlines) {
|
||||
this.deadlines = deadlines;
|
||||
}
|
||||
|
||||
|
@ -3,20 +3,18 @@ package ru.ulstu.project.model;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||
|
||||
public class ProjectDto {
|
||||
private Integer id;
|
||||
|
||||
@NotEmpty
|
||||
private String title;
|
||||
|
||||
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
|
||||
public ProjectDto() {
|
||||
}
|
||||
@ -28,7 +26,7 @@ public class ProjectDto {
|
||||
@JsonCreator
|
||||
public ProjectDto(@JsonProperty("id") Integer id,
|
||||
@JsonProperty("title") String title,
|
||||
@JsonProperty("deadlines") List<DeadlineDto> deadlines) {
|
||||
@JsonProperty("deadlines") List<Deadline> deadlines) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.deadlines = deadlines;
|
||||
@ -38,7 +36,7 @@ public class ProjectDto {
|
||||
public ProjectDto(Project project) {
|
||||
this.id = project.getId();
|
||||
this.title = project.getTitle();
|
||||
this.deadlines = convert(project.getDeadlines(), DeadlineDto::new);
|
||||
this.deadlines = project.getDeadlines();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
@ -57,11 +55,11 @@ public class ProjectDto {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<DeadlineDto> getDeadlines() {
|
||||
public List<Deadline> getDeadlines() {
|
||||
return deadlines;
|
||||
}
|
||||
|
||||
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||
public void setDeadlines(List<Deadline> deadlines) {
|
||||
this.deadlines = deadlines;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user