Skip to content

Commit f4c58d7

Browse files
Fix:Review-2
1 parent dcfb890 commit f4c58d7

File tree

14 files changed

+96
-86
lines changed

14 files changed

+96
-86
lines changed

src/main/java/hexlet/code/controller/TaskStatusController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package hexlet.code.controller;
22

3-
43
import hexlet.code.dto.taskstatus.TaskStatusCreateDTO;
54
import hexlet.code.dto.taskstatus.TaskStatusDTO;
65
import hexlet.code.dto.taskstatus.TaskStatusUpdateDTO;

src/main/java/hexlet/code/dto/task/TaskDTO.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.Getter;
66
import lombok.Setter;
77

8-
import java.time.LocalDateTime;
8+
import java.time.LocalDate;
99
import java.util.Set;
1010

1111
@Getter
@@ -21,8 +21,7 @@ public class TaskDTO {
2121
private Long assigneeId;
2222

2323
@JsonFormat(pattern = "yyyy-MM-dd")
24-
private LocalDateTime createdAt;
24+
private LocalDate createdAt;
2525

2626
private Set<Long> taskLabelIds;
27-
2827
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package hexlet.code.dto.taskstatus;
22

3+
import java.time.LocalDate;
4+
35
import com.fasterxml.jackson.annotation.JsonFormat;
46
import lombok.Getter;
57
import lombok.Setter;
68

7-
import java.time.LocalDateTime;
8-
99
@Getter
1010
@Setter
1111
public class TaskStatusDTO {
1212

1313
private Long id;
1414
private String name;
1515
private String slug;
16-
1716
@JsonFormat(pattern = "yyyy-MM-dd")
18-
private LocalDateTime createdAt;
17+
private LocalDate createdAt;
1918
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package hexlet.code.dto.user;
22

3+
import java.time.LocalDate;
4+
35
import com.fasterxml.jackson.annotation.JsonFormat;
46
import lombok.Getter;
57
import lombok.Setter;
68

7-
import java.time.LocalDateTime;
8-
99
@Getter
1010
@Setter
1111
public class UserDTO {
@@ -16,6 +16,5 @@ public class UserDTO {
1616
private String lastName;
1717

1818
@JsonFormat(pattern = "yyyy-MM-dd")
19-
// @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
20-
private LocalDateTime createdAt;
19+
private LocalDate createdAt;
2120
}

src/main/java/hexlet/code/mapper/TaskMapper.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.HashSet;
2020
import java.util.List;
21-
import java.util.Optional;
2221
import java.util.Set;
2322
import java.util.stream.Collectors;
2423

@@ -29,10 +28,9 @@
2928
@SuppressWarnings("java:S6813")
3029
public abstract class TaskMapper {
3130
@Autowired
32-
private TaskStatusRepository taskStatusRepository;
31+
private TaskStatusRepository taskStatusRepository;
3332
@Autowired
34-
private LabelRepository labelRepository;
35-
33+
private LabelRepository labelRepository;
3634

3735
@Mapping(target = "name", source = "title")
3836
@Mapping(target = "description", source = "content")
@@ -48,6 +46,13 @@ public abstract class TaskMapper {
4846
@Mapping(target = "taskLabelIds", source = "labels") // , qualifiedByName = "mapTaskLabel")
4947
public abstract TaskDTO map(Task model);
5048

49+
@Mapping(target = "name", source = "title")
50+
@Mapping(target = "description", source = "content")
51+
@Mapping(target = "taskStatus.slug", source = "status")
52+
@Mapping(target = "assignee.id", source = "assigneeId")
53+
@Mapping(target = "labels", source = "taskLabelIds")
54+
public abstract Task map(TaskDTO model); // for test
55+
5156
@Mapping(target = "name", source = "title")
5257
@Mapping(target = "description", source = "content")
5358
@Mapping(target = "taskStatus", source = "status")
@@ -72,17 +77,8 @@ public Set<Label> toLabels(Set<Long> taskLabelIds) {
7277
if (taskLabelIds == null) {
7378
return new HashSet<>();
7479
} else {
75-
Set<Label> result = new HashSet<>();
76-
List<Label> listLabels = labelRepository.findAll();
77-
for (Long n : taskLabelIds) {
78-
Optional<Label> value = listLabels.stream()
79-
.filter(v -> (v.getId() == n))
80-
.findFirst();
81-
if (value.isPresent()) {
82-
result.add(value.get());
83-
}
84-
}
85-
return result;
80+
List<Label> listLabels = labelRepository.findAllById(taskLabelIds);
81+
return new HashSet<>(listLabels);
8682
}
8783
}
8884

src/main/java/hexlet/code/mapper/TaskStatusMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
unmappedTargetPolicy = ReportingPolicy.IGNORE)
1818
public abstract class TaskStatusMapper {
1919

20+
public abstract TaskStatus map(TaskStatusCreateDTO dto);
21+
2022
public abstract TaskStatusDTO map(TaskStatus model);
2123

22-
public abstract TaskStatus map(TaskStatusCreateDTO dto);
24+
public abstract TaskStatus map(TaskStatusDTO model); //for test
25+
2326

2427
public abstract void update(TaskStatusUpdateDTO dto, @MappingTarget TaskStatus model);
2528

src/main/java/hexlet/code/mapper/UserMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public abstract class UserMapper {
3333

3434
public abstract UserDTO map(User model);
3535

36+
public abstract User map(UserDTO model); //for test
37+
3638
@Mapping(target = "passwordDigest", source = "password")
3739
public abstract void update(UserUpdateDTO dto, @MappingTarget User user);
3840

src/main/java/hexlet/code/model/Label.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package hexlet.code.model;
22

3-
43
import jakarta.persistence.Column;
54
import jakarta.persistence.Entity;
65
import jakarta.persistence.EntityListeners;
@@ -18,7 +17,7 @@
1817
import org.springframework.data.annotation.CreatedDate;
1918
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
2019

21-
import java.time.LocalDateTime;
20+
import java.time.LocalDate;
2221
import java.util.Set;
2322

2423
@Getter
@@ -36,11 +35,13 @@ public class Label {
3635
@NotBlank
3736
@Column(unique = true)
3837
@Size(min = 3, max = 1000)
38+
@EqualsAndHashCode.Include
3939
private String name;
4040

4141
@CreatedDate
4242
@Column(nullable = false, updatable = false)
43-
private LocalDateTime createdAt;
43+
@EqualsAndHashCode.Include
44+
private LocalDate createdAt;
4445

4546
//разные метки назначены разным задачам (полагаю метки уникальные)
4647
@ManyToMany(mappedBy = "labels", fetch = FetchType.EAGER)
Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package hexlet.code.model;
22

3-
43
import jakarta.persistence.CascadeType;
54
import jakarta.persistence.Column;
65
import jakarta.persistence.Entity;
@@ -16,29 +15,33 @@
1615
import jakarta.persistence.Table;
1716
import jakarta.validation.constraints.NotNull;
1817
import jakarta.validation.constraints.Size;
18+
import lombok.EqualsAndHashCode;
1919
import lombok.Getter;
2020
import lombok.Setter;
2121
import org.springframework.data.annotation.CreatedDate;
2222
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
2323

24-
import java.time.LocalDateTime;
24+
import java.time.LocalDate;
2525
import java.util.HashSet;
26-
import java.util.Objects;
2726
import java.util.Set;
2827

2928
@Getter
3029
@Setter
3130

3231
@Entity
32+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
3333
@EntityListeners(AuditingEntityListener.class)
3434
@Table(name = "tasks")
3535
public class Task {
36+
3637
@Id
3738
@GeneratedValue(strategy = GenerationType.IDENTITY)
39+
@EqualsAndHashCode.Include
3840
private Long id;
3941

4042
@NotNull
4143
@Size(min = 1)
44+
@EqualsAndHashCode.Include
4245
private String name; //Обязательное. Минимум 1 символ. Названия задач могут быть любыми
4346

4447
private Integer index; //Необязательное, целое число. Нужно для прав-го отображ. задач во фронте
@@ -54,7 +57,7 @@ public class Task {
5457

5558
@CreatedDate
5659
@Column(nullable = false, updatable = false)
57-
private LocalDateTime createdAt;
60+
private LocalDate createdAt;
5861

5962
//задачи могут иметь разные метки
6063
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@@ -64,28 +67,4 @@ public class Task {
6467
inverseJoinColumns = @JoinColumn(name = "label_id")
6568
)
6669
private Set<Label> labels = new HashSet<>();
67-
68-
/**
69-
* @return int
70-
*/
71-
@Override
72-
public int hashCode() {
73-
return Objects.hash(id, name);
74-
}
75-
76-
/**
77-
* @param o
78-
* @return boolean
79-
*/
80-
@Override
81-
public boolean equals(Object o) {
82-
if (this == o) {
83-
return true;
84-
}
85-
if (o == null || getClass() != o.getClass()) {
86-
return false;
87-
}
88-
Label label = (Label) o;
89-
return id == label.getId() && name.equals(label.getName());
90-
}
9170
}

src/main/java/hexlet/code/model/TaskStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import lombok.Getter;
1717
import lombok.Setter;
1818

19-
import java.time.LocalDateTime;
19+
import java.time.LocalDate;
2020

2121
@Getter
2222
@Setter
@@ -40,5 +40,5 @@ public class TaskStatus {
4040

4141
@CreatedDate
4242
@Column(nullable = false, updatable = false)
43-
private LocalDateTime createdAt;
43+
private LocalDate createdAt;
4444
}

0 commit comments

Comments
 (0)