Skip to content

Commit

Permalink
Make possible adding labels while creating/updating Task
Browse files Browse the repository at this point in the history
  • Loading branch information
niyatanya committed Aug 17, 2024
1 parent 6ec9939 commit 0f601f1
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/main/java/hexlet/code/controller/LabelController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package hexlet.code.controller;

import hexlet.code.dto.LabelParamsDTO;
import hexlet.code.exception.EntityCanNotBeDeletedException;
import hexlet.code.exception.ResourceNotFoundException;
import hexlet.code.mapper.LabelMapper;
import hexlet.code.model.Task;
import hexlet.code.model.Label;
import hexlet.code.repository.TaskRepository;
import hexlet.code.repository.LabelRepository;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hexlet/code/dto/TaskCreateDTO.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package hexlet.code.dto;

import hexlet.code.model.Label;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;

@Getter
@Setter
public class TaskCreateDTO {
Expand All @@ -19,4 +22,6 @@ public class TaskCreateDTO {

@NotNull
private String status;

private Set<Label> labels;
}
5 changes: 5 additions & 0 deletions src/main/java/hexlet/code/dto/TaskUpdateDTO.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package hexlet.code.dto;

import hexlet.code.model.Label;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;
import org.openapitools.jackson.nullable.JsonNullable;

import java.util.Set;

@Getter
@Setter
public class TaskUpdateDTO {
Expand All @@ -20,4 +23,6 @@ public class TaskUpdateDTO {

@NotNull
private JsonNullable<String> status;

private JsonNullable<Set<Label>> labels;
}
6 changes: 0 additions & 6 deletions src/main/java/hexlet/code/model/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Table;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.JoinTable;
import jakarta.persistence.JoinColumn;

import jakarta.validation.constraints.Size;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -23,7 +18,6 @@

import java.sql.Timestamp;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static jakarta.persistence.GenerationType.IDENTITY;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/hexlet/code/model/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/hexlet/code/controller/LabelControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import hexlet.code.dto.LabelParamsDTO;
import hexlet.code.mapper.LabelMapper;
import hexlet.code.model.Task;
import hexlet.code.model.Label;
import hexlet.code.model.TaskStatus;
import hexlet.code.repository.TaskRepository;
import hexlet.code.repository.LabelRepository;
import hexlet.code.repository.TaskStatusRepository;
Expand Down
24 changes: 21 additions & 3 deletions src/test/java/hexlet/code/controller/TaskControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import hexlet.code.dto.TaskCreateDTO;
import hexlet.code.mapper.TaskMapper;
import hexlet.code.model.Label;
import hexlet.code.model.Task;
import hexlet.code.model.TaskStatus;
import hexlet.code.model.User;
import hexlet.code.repository.LabelRepository;
import hexlet.code.repository.TaskRepository;
import hexlet.code.repository.TaskStatusRepository;
import hexlet.code.repository.UserRepository;
Expand All @@ -25,6 +27,8 @@
import org.springframework.web.context.WebApplicationContext;

import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -55,6 +59,9 @@ public class TaskControllerTest {
@Autowired
private TaskStatusRepository statusRepository;

@Autowired
private LabelRepository labelRepository;

@Autowired
private TaskMapper mapper;

Expand All @@ -67,6 +74,8 @@ public class TaskControllerTest {

private User testUser;

private Label testLabel;

@BeforeEach
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac)
Expand All @@ -89,6 +98,13 @@ public void setUp() {
.create();
statusRepository.save(testStatus);

testLabel = Instancio.of(Label.class)
.ignore(Select.field(Label::getId))
.ignore(Select.field(Label::getCreatedAt))
.ignore(Select.field(Label::getTasks))
.create();
labelRepository.save(testLabel);

testTask = Instancio.of(Task.class)
.ignore(Select.field(Task::getId))
.ignore(Select.field(Task::getCreatedAt))
Expand All @@ -98,6 +114,10 @@ public void setUp() {
.create();
testTask.setAssignee(testUser);
testTask.setTaskStatus(testStatus);

Set<Label> labels = new HashSet<>();
labels.add(testLabel);
testTask.setLabels(labels);
}

@Test
Expand Down Expand Up @@ -140,6 +160,7 @@ public void testCreate() throws Exception {
dto.setTitle("Add front to app");
dto.setContent("Install npm, unpack front application, debug");
dto.setStatus(testStatus.getSlug());
dto.setLabels(testTask.getLabels());

MockHttpServletRequestBuilder request = post("/api/tasks")
.with(jwt())
Expand All @@ -165,10 +186,8 @@ public void testUpdate() throws Exception {
taskRepository.save(testTask);

TaskCreateDTO data = new TaskCreateDTO();
data.setAssigneeId(testUser.getId());
data.setTitle("Write CRUD for task");
data.setContent("Write model, dto, mapper, repository, tests and controller");
data.setStatus(testStatus.getSlug());

MockHttpServletRequestBuilder request = put("/api/tasks/{id}", testTask.getId())
.with(jwt())
Expand All @@ -183,7 +202,6 @@ public void testUpdate() throws Exception {
assertThat(task).isNotNull();
assertThat(task.getName()).isEqualTo(data.getTitle());
assertThat(task.getDescription()).isEqualTo(data.getContent());
assertThat(task.getAssignee().getId()).isEqualTo(data.getAssigneeId());

taskRepository.delete(task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import hexlet.code.dto.TaskStatusCreateDTO;
import hexlet.code.mapper.TaskStatusMapper;
import hexlet.code.model.Task;
import hexlet.code.model.TaskStatus;
import hexlet.code.repository.TaskRepository;
import hexlet.code.repository.TaskStatusRepository;
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/hexlet/code/controller/UsersControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import hexlet.code.dto.UserCreateDTO;
import hexlet.code.dto.UserDTO;
import hexlet.code.mapper.UserMapper;
import hexlet.code.model.Task;
import hexlet.code.model.TaskStatus;
import hexlet.code.repository.TaskRepository;
import hexlet.code.repository.TaskStatusRepository;
import hexlet.code.service.UserService;
Expand Down

0 comments on commit 0f601f1

Please sign in to comment.