Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.barashkovmalofeev.tasktracker.model.dto;

import com.barashkovmalofeev.tasktracker.model.entity.Notification;
import com.barashkovmalofeev.tasktracker.model.entity.User;

import javax.persistence.*;
import java.time.LocalDate;

public class NotificationResponseDTO {
private Long id;
private String text;
private String taskName;
private LocalDate productionDate;
private Boolean isRead;

public NotificationResponseDTO(){}

Expand All @@ -12,7 +20,11 @@ public NotificationResponseDTO(String text) {
}

public NotificationResponseDTO(Notification notification) {
this.text = notification.getText();
id = notification.getId();
text = notification.getText();
taskName = notification.getTaskName();
productionDate = notification.getProductionDate();
isRead = notification.getRead();
}

public String getText() {
Expand All @@ -22,4 +34,36 @@ public String getText() {
public void setText(String text) {
this.text = text;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getTaskName() {
return taskName;
}

public void setTaskName(String taskName) {
this.taskName = taskName;
}

public LocalDate getProductionDate() {
return productionDate;
}

public void setProductionDate(LocalDate productionDate) {
this.productionDate = productionDate;
}

public Boolean getRead() {
return isRead;
}

public void setRead(Boolean read) {
isRead = read;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.barashkovmalofeev.tasktracker.model.dto;

import com.barashkovmalofeev.tasktracker.model.enums.TaskStatus;

public class TaskFilterDto {
private String description;
private String name;
private TaskStatus status;
private String comment;

// Конструктор по умолчанию (обязателен для JSON десериализации)
public TaskFilterDto() {
}

// Геттеры и сеттеры
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public TaskStatus getStatus() {
return status;
}

public void setStatus(TaskStatus status) {
this.status = status;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

@Override
public String toString() {
return "TaskFilterDto{" +
"description='" + description + '\'' +
", name='" + name + '\'' +
", status=" + status +
", comment='" + comment + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "Comment")
Expand Down Expand Up @@ -71,4 +73,5 @@ public Task getTask() {
public void setTask(Task task) {
this.task = task;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.barashkovmalofeev.tasktracker.model.entity;

import javax.persistence.*;
import java.time.LocalDate;

@Entity
@Table(name = "Notification")
Expand All @@ -13,6 +14,9 @@ public class Notification {
@JoinColumn(name = "assigned_user_id")
private User assignedUser;
private String text;
private String taskName;
private LocalDate productionDate;
private Boolean isRead;

public Notification(){}

Expand All @@ -22,6 +26,15 @@ public Notification(Long id, User assignedUser, String text) {
this.text = text;
}

public Notification(Long id, User assignedUser, String text, String taskName, LocalDate productionDate, Boolean isRead) {
this.id = id;
this.assignedUser = assignedUser;
this.text = text;
this.taskName = taskName;
this.productionDate = productionDate;
this.isRead = isRead;
}

public Long getId() {
return id;
}
Expand All @@ -45,4 +58,28 @@ public String getText() {
public void setText(String text) {
this.text = text;
}

public String getTaskName() {
return taskName;
}

public void setTaskName(String taskName) {
this.taskName = taskName;
}

public LocalDate getProductionDate() {
return productionDate;
}

public void setProductionDate(LocalDate productionDate) {
this.productionDate = productionDate;
}

public Boolean getRead() {
return isRead;
}

public void setRead(Boolean read) {
isRead = read;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javax.persistence.*;
import java.time.Duration;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "Task")
Expand All @@ -27,6 +29,8 @@ public class Task {
@ManyToOne // Много задач (Task) к Одному Пользователю (User)
@JoinColumn(name = "assigned_user_id") // Внешний ключ в таблице Task
private User assignedUser;
@OneToMany(mappedBy = "task", fetch = FetchType.LAZY)
private List<Comment> comments = new ArrayList<>();
private LocalDate productionDate;
private LocalDate endDate;
private TaskComplexity complexity;
Expand Down Expand Up @@ -157,4 +161,12 @@ public Long getId() {
public void setId(Long id) {
this.id = id;
}

public List<Comment> getComments() {
return comments;
}

public void setComments(List<Comment> comments) {
this.comments = comments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public Notification saveNotification(Notification notification) {
return em.merge(notification); // UPDATE
}
}

public Notification findById(Long id) {
return em.find(Notification.class, id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import com.barashkovmalofeev.tasktracker.model.dto.CommentResponseDTO;
import com.barashkovmalofeev.tasktracker.model.dto.NotificationResponseDTO;
import com.barashkovmalofeev.tasktracker.model.dto.TaskCreateDTO;
import com.barashkovmalofeev.tasktracker.model.dto.TaskResponseDTO;
import com.barashkovmalofeev.tasktracker.model.entity.Notification;
import com.barashkovmalofeev.tasktracker.model.entity.Task;
import com.barashkovmalofeev.tasktracker.repository.NotificationRepository;
import com.barashkovmalofeev.tasktracker.service.CommentService;
import com.barashkovmalofeev.tasktracker.service.NotificationService;

import javax.ejb.EJB;
import javax.persistence.EntityNotFoundException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Path("/notifications")
Expand All @@ -20,6 +25,9 @@ public class NotificationResource {
@EJB
private NotificationService notificationService;

@EJB
private NotificationRepository notificationRepository;

@GET
@Path("/{userId}")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -38,4 +46,31 @@ public Response getCommentsByTaskId(@PathParam("userId") Long userId) {
.collect(Collectors.toList());
return Response.ok(notificationResponseDTOS).build();
}

@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{notificationId}")
public Response updateTask(@PathParam("notificationId") Long notificationId, Map<String, Object> data) {

try {
Boolean isRead = (Boolean) data.get("isRead");
Notification notification = notificationRepository.findById(notificationId);
notification.setRead(isRead);
Notification savedNotification = notificationRepository.saveNotification(notification);
NotificationResponseDTO notificationResponseDTO = new NotificationResponseDTO(savedNotification);
return Response.status(Response.Status.CREATED)
.entity(notificationResponseDTO)
.build();

} catch (EntityNotFoundException e) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Notification not found: " + e.getMessage())
.build();
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Error updating Notification: " + e.getMessage())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.barashkovmalofeev.tasktracker.rest;

import com.barashkovmalofeev.tasktracker.model.dto.TaskCreateDTO;
import com.barashkovmalofeev.tasktracker.model.dto.TaskFilterDto;
import com.barashkovmalofeev.tasktracker.model.dto.TaskResponseDTO;
import com.barashkovmalofeev.tasktracker.model.entity.Task;
import com.barashkovmalofeev.tasktracker.model.entity.User;
import com.barashkovmalofeev.tasktracker.service.ProjectService;
import com.barashkovmalofeev.tasktracker.service.TaskService;
import com.barashkovmalofeev.tasktracker.service.UserService;
import com.barashkovmalofeev.tasktracker.testAOP.TaskAdvice;

import javax.ejb.EJB;
import javax.inject.Inject;
import javax.interceptor.Interceptors;
import javax.persistence.EntityNotFoundException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -31,6 +34,46 @@ public class TaskResource {
@Context
private HttpServletRequest req;

@Inject
private ProjectService projectService;

@POST
@Consumes("application/json")
@Produces("application/json")
@Path("/project/{projectId}/filter")
public Response filterTasksByProject(
@PathParam("projectId") Long projectId,
TaskFilterDto filterDto) {



// Получаем отфильтрованные задачи
List<Task> tasks = taskService.findTasksByProjectWithFilters(projectId, filterDto);

List<TaskResponseDTO> taskResponseDTOS = tasks.stream()
.map(task -> new TaskResponseDTO(task))
.collect(Collectors.toList());

return Response.ok(taskResponseDTOS).build();
}

@POST
@Consumes("application/json")
@Produces("application/json")
@Path("/user/filter")
public Response filterTasksByUser(
@CookieParam("userId") Long userId,
TaskFilterDto filterDto) {

List<Task> tasks = taskService.findTasksByUserWithFilters(userId, filterDto);

List<TaskResponseDTO> taskResponseDTOS = tasks.stream()
.map(task -> new TaskResponseDTO(task))
.collect(Collectors.toList());

return Response.ok(taskResponseDTOS).build();
}

@GET
@Path("/user/{userId}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,5 @@ public boolean addUserToProject(Long projectId, String username) {
}
projectRepository.addUserToProject(projectId, user.getId());
return true;

}
}
Loading