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
Expand Up @@ -8,9 +8,7 @@
import org.springframework.web.bind.annotation.*;
import ru.worktechlab.work_task.dto.OkResponse;
import ru.worktechlab.work_task.dto.StringIdsDto;
import ru.worktechlab.work_task.dto.projects.ProjectDto;
import ru.worktechlab.work_task.dto.projects.ProjectRequestDto;
import ru.worktechlab.work_task.dto.projects.ShortProjectDataDto;
import ru.worktechlab.work_task.dto.projects.*;
import ru.worktechlab.work_task.exceptions.NotFoundException;
import ru.worktechlab.work_task.services.ProjectsService;

Expand Down Expand Up @@ -52,6 +50,17 @@ public ProjectDto getProjectData(
return projectsService.getProjectData(projectId);
}

@PostMapping("/{projectId}")
@Operation(summary = "Получение данных проекта по ИД и фильтру")
public ProjectDataDto getProjectDataByFilter(
@Parameter(description = "ИД проекта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String projectId,
@Parameter(description = "Данные фильтра")
@RequestBody @Valid ProjectDataFilterDto filter
) throws NotFoundException {
return projectsService.getProjectDataByFilter(projectId, filter);
}

@PutMapping("/finish-project/{projectId}")
@Operation(summary = "Завершение проекта по ИД")
public ProjectDto finishProject(
Expand All @@ -70,7 +79,7 @@ public ProjectDto startProject(
return projectsService.startProject(projectId);
}

@PutMapping("/{projectId}/add-project")
@PutMapping("/{projectId}/add-users")
@Operation(summary = "Добавление проекта пользователям")
public OkResponse addProjectForUsers(
@Parameter(description = "ИД проекта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
Expand All @@ -80,4 +89,15 @@ public OkResponse addProjectForUsers(
) throws NotFoundException {
return projectsService.addProjectForUsers(projectId, data);
}

@DeleteMapping("/{projectId}/delete-users")
@Operation(summary = "Удаление пользователей из проекта")
public OkResponse deleteProjectForUsers(
@Parameter(description = "ИД проекта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String projectId,
@Parameter(description = "Идентификаторы пользователей", example = "[\"656c989e-ceb1-4a9f-a6a9-9ab40cc11540\", \"656c989e-ceb1-4a9f-a6a9-9ab40cc11540\", ...]")
@RequestBody StringIdsDto data
) throws NotFoundException {
return projectsService.deleteProjectForUsers(projectId, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import ru.worktechlab.work_task.dto.sprints.ActivateSprintDtoRequest;
import ru.worktechlab.work_task.dto.sprints.SprintDtoRequest;
import ru.worktechlab.work_task.dto.sprints.SprintInfoDTO;
import ru.worktechlab.work_task.exceptions.BadRequestException;
Expand Down Expand Up @@ -35,12 +34,32 @@ public SprintInfoDTO createSprint(@Parameter(description = "ИД проекта"
return sprintsService.createSprint(projectId, data);
}

@PutMapping("/{sprintId}/activate")
@Operation(summary = "Запуск/завершение спринта спринта")
public SprintInfoDTO activateSprint(@Parameter(description = "ИД спринта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String sprintId,
@Parameter(description = "Признак запуска/завершения спринта", required = true)
@RequestBody ActivateSprintDtoRequest data) throws NotFoundException, BadRequestException {
return sprintsService.activateSprint(sprintId, data);
@PutMapping("/project/{projectId}/{sprintId}/activate")
@Operation(summary = "Запуск спринта спринта")
public SprintInfoDTO activateSprint(@Parameter(description = "ИД проекта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String projectId,
@Parameter(description = "ИД спринта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String sprintId) throws NotFoundException, BadRequestException {
return sprintsService.activateSprint(sprintId, projectId);
}

@PutMapping("/project/{projectId}/{sprintId}/finish")
@Operation(summary = "Завершение спринта")
public SprintInfoDTO finishSprint(@Parameter(description = "ИД проекта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String projectId,
@Parameter(description = "ИД спринта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String sprintId) throws NotFoundException, BadRequestException {
return sprintsService.finishSprint(sprintId, projectId);
}

@PutMapping("/project/{projectId}/{sprintId}/update")
@Operation(summary = "Изменение спринта")
public SprintInfoDTO updateSprint(@Parameter(description = "ИД проекта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String projectId,
@Parameter(description = "ИД спринта", example = "656c989e-ceb1-4a9f-a6a9-9ab40cc11540", required = true)
@PathVariable String sprintId,
@Parameter(description = "Данные спринта", required = true)
@RequestBody SprintDtoRequest data) throws NotFoundException, BadRequestException {
return sprintsService.updateSprint(sprintId, projectId, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import ru.worktechlab.work_task.dto.response_dto.UsersTasksInProjectDTO;
import ru.worktechlab.work_task.dto.task_history.TaskHistoryResponseDto;
import ru.worktechlab.work_task.dto.tasks.TaskDataDto;
import ru.worktechlab.work_task.dto.tasks.TaskModelDTO;
import ru.worktechlab.work_task.dto.tasks.UpdateStatusRequestDTO;
import ru.worktechlab.work_task.dto.tasks.UpdateTaskModelDTO;
import ru.worktechlab.work_task.dto.tasks.TaskResponse;
import ru.worktechlab.work_task.dto.response_dto.UsersTasksInProjectDTO;
import ru.worktechlab.work_task.dto.task_history.TaskHistoryResponseDto;
import ru.worktechlab.work_task.exceptions.NotFoundException;
import ru.worktechlab.work_task.models.tables.TaskModel;
import ru.worktechlab.work_task.services.TaskHistoryService;
import ru.worktechlab.work_task.services.TaskService;

Expand All @@ -31,7 +30,7 @@ public class TaskController {

@PostMapping("/create-task")
@Operation(summary = "Создать задачу")
public TaskResponse createTask(
public TaskDataDto createTask(
@Valid
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "Данные для создания задачи",
Expand All @@ -46,7 +45,7 @@ public TaskResponse createTask(

@PutMapping("/update-task")
@Operation(summary = "Обновить задачу")
public TaskResponse updateTask(
public TaskDataDto updateTask(
@Valid
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "Данные для обновления задачи",
Expand All @@ -61,7 +60,7 @@ public TaskResponse updateTask(

@PutMapping("/update-status")
@Operation(summary = "Обновить статус задачи")
public TaskResponse updateTask(
public TaskDataDto updateTaskStatus(
@Valid
@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "Данные для обновления статуса задачи",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ public List<UserShortDataDto> findUsersByIdsIn(
}

@Operation(summary = "Активировать пользователей по существующим ИД")
@PutMapping()
@PutMapping("/activate")
public OkResponse activateUsers(
@Parameter(description = "Идентификаторы пользователей", example = "[\"656c989e-ceb1-4a9f-a6a9-9ab40cc11540\", \"656c989e-ceb1-4a9f-a6a9-9ab40cc11540\", ...]")
@RequestBody StringIdsDto data) throws NotFoundException {
return userService.activateUsers(data);
return userService.activateUsers(data, true);
}

@Operation(summary = "Заблокировать пользователей по существующим ИД")
@PutMapping("/block")
public OkResponse blockUsers(
@Parameter(description = "Идентификаторы пользователей", example = "[\"656c989e-ceb1-4a9f-a6a9-9ab40cc11540\", \"656c989e-ceb1-4a9f-a6a9-9ab40cc11540\", ...]")
@RequestBody StringIdsDto data) throws NotFoundException {
return userService.activateUsers(data, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.worktechlab.work_task.dto.projects;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor
@Getter
@Setter
public class ProjectDataDto {

private List<UserWithTasksDto> users = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.worktechlab.work_task.dto.projects;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@NoArgsConstructor
@Getter
@Setter
public class ProjectDataFilterDto {
private List<String> userIds;
private List<Long> statusIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ru.worktechlab.work_task.dto.projects;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ru.worktechlab.work_task.dto.tasks.TaskDataDto;

import java.util.List;

@NoArgsConstructor
@Getter
@Setter
public class UserWithTasksDto {
@NotNull
@Schema(description = "ИД пользователя")
private String id;
@NotNull
@Schema(description = "Email пользователя")
private String email;
@NotNull
@Schema(description = "Имя пользователя")
private String firstName;
@Schema(description = "Фамилия пользователя")
private String lastName;
@NotNull
@Schema(description = "Пол пользователя")
private String gender;
@Schema(description = "Список задач")
private List<TaskDataDto> tasks;

public UserWithTasksDto(String id,
String email,
String firstName,
String lastName,
String gender,
List<TaskDataDto> tasks) {
this.id = id;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.tasks = tasks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ru.worktechlab.work_task.dto.response_dto.UsersProjectsDTO;
import ru.worktechlab.work_task.dto.response_dto.UsersTasksInProjectDTO;
import ru.worktechlab.work_task.dto.sprints.SprintInfoDTO;
import ru.worktechlab.work_task.dto.statuses.TaskStatusShortDto;
import ru.worktechlab.work_task.dto.users.UserShortDataDto;
import ru.worktechlab.work_task.models.tables.TaskModel;
import ru.worktechlab.work_task.validators.*;

import java.util.List;

@NoArgsConstructor
@Getter
@Setter
public class TaskResponse {
public class TaskDataDto {
@Schema(description = "id задачи")
@NotBlank(message = "Поле ID не может быть пустым")
@ValidTaskId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import ru.worktechlab.work_task.config.MapStructConfiguration;
import ru.worktechlab.work_task.dto.tasks.TaskResponse;
import ru.worktechlab.work_task.dto.tasks.TaskDataDto;
import ru.worktechlab.work_task.models.tables.TaskModel;

@Mapper(config = MapStructConfiguration.class, uses = {UserMapper.class, TaskStatusMapper.class})
public interface TaskMapper {

@Mapping(source = "project.id", target = "projectId")
@Mapping(source = "sprint.id", target = "sprintId")
TaskResponse toDo(TaskModel taskModel);
TaskDataDto toDo(TaskModel taskModel);
}
15 changes: 8 additions & 7 deletions src/main/java/ru/worktechlab/work_task/models/tables/Sprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Sprint {
private LocalDate endDate;
@Column
private LocalDate createdAt;
@Column
private LocalDate finishedAt;
@Column(name = "is_active")
private boolean active;
@Column
Expand Down Expand Up @@ -66,15 +68,14 @@ public void setEndDate(LocalDate endDate) {
this.endDate = endDate;
}

public void setActive(boolean active) {
this.active = active;
}

public void setDefaultSprint(boolean defaultSprint) {
this.defaultSprint = defaultSprint;
public void activate() {
this.active = true;
this.finisher = null;
this.finishedAt = null;
}

public void setFinisher(User finisher) {
public void finish(User finisher) {
this.finisher = finisher;
this.finishedAt = LocalDate.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class UsersProject {
@Column(name = "id", nullable = false, unique = true)
private Integer id;

@Column(name = "user_id")
private String userId;
@ManyToOne
private User user;

@Column(name = "project_id")
private String projectId;
@ManyToOne
private Project project;

public UsersProject(String userId, String projectId) {
this.userId = userId;
this.projectId = projectId;
public UsersProject(User user, Project project) {
this.user = user;
this.project = project;
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
package ru.worktechlab.work_task.repositories;

import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import ru.worktechlab.work_task.models.tables.Project;
import ru.worktechlab.work_task.dto.response_dto.UsersProjectsDTO;

import java.util.List;
import java.util.Optional;

@Repository
public interface ProjectRepository extends JpaRepository<Project, String> {
@Query("SELECT NEW ru.worktechlab.work_task.dto.response_dto.UsersProjectsDTO(p.name, p.id) FROM Project p WHERE p.id IN :projectIds AND p.active = true")
List<UsersProjectsDTO> findProjectIdAndNameByIds(@Param("projectIds") List<String> projectIds);

@Query("SELECT p.active FROM Project p WHERE p.id = :id")
Boolean isProjectActive(@Param("id") String id);

@Query("SELECT p.name FROM Project p WHERE p.id = :id")
String getProjectNameById(@Param("id") String id);

@Query("SELECT p.code FROM Project p WHERE p.id = :id")
String getCodeById(@Param("id") String id);

@Transactional
@Modifying
@Query("UPDATE Project p SET p.taskCounter = p.taskCounter + 1 WHERE p.id = :id")
void incrementCount(@Param("id") String id);

@Query("SELECT p.taskCounter FROM Project p WHERE p.id = :id")
Integer getCountById(@Param("id") String id);

@Query(nativeQuery = true,
value = "select * from project where id = :projectId for update skip locked")
value = "select * from project where id = :projectId for update skip locked")
Optional<Project> findProjectByIdForUpdate(String projectId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public interface SprintsRepository extends JpaRepository<Sprint, String> {
Boolean isSprintActive(@Param("id") String id);

@Query(nativeQuery = true,
value = "select * from sprint where id = :sprintId for update skip locked")
Optional<Sprint> findSprintByIdForUpdate(String sprintId);
value = "select * from sprint where id = :sprintId and project_id = :projectId for update skip locked")
Optional<Sprint> findSprintByIdForUpdate(String sprintId, String projectId);

@Query(nativeQuery = true,
value = "select exists (select * from sprint s where s.project_id = :projectId and s.is_active")
Expand Down
Loading