Skip to content

Commit

Permalink
Merge pull request #172 from FEBFES/feature/157/create-order-service
Browse files Browse the repository at this point in the history
Order
  • Loading branch information
IvanShish authored Sep 22, 2023
2 parents 90f35b1 + 9fe5fc7 commit d8e0ef5
Show file tree
Hide file tree
Showing 55 changed files with 701 additions and 377 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ build/
### scripts ###
deploy.sh

./userPics
./files
.userPics
.files
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public ColumnDto editColumn(
@RequestBody ColumnDto columnDto
) {
roleCheckerComponent.checkIfHasRole(pathVars.projectId(), RoleName.MEMBER_PLUS);
TaskColumnEntity updatedColumn = columnService.editColumn(
ColumnMapper.INSTANCE.columnDtoToColumn(columnDto, pathVars.columnId(), pathVars.projectId())
);
TaskColumnEntity updatedColumn = columnService.editColumn(columnDto, pathVars.columnId());
return ColumnMapper.INSTANCE.columnToColumnDto(updatedColumn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -64,8 +64,11 @@ public byte[] getImageWithMediaType(@PathVariable Long userId) throws IOExceptio
path = "task/{taskId}",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE
)
public List<TaskFileDto> saveTaskFiles(@PathVariable Long taskId, @RequestParam("files") MultipartFile[] files) {
UserEntity user = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
public List<TaskFileDto> saveTaskFiles(
@AuthenticationPrincipal UserEntity user,
@PathVariable Long taskId,
@RequestParam("files") MultipartFile[] files
) {
List<TaskFileDto> response = new ArrayList<>();
Arrays.stream(files).forEach(file -> {
FileEntity savedFile = fileService.saveFile(user.getId(), taskId, EntityType.TASK, file);
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/febfes/fftmback/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import jakarta.validation.Valid;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -42,27 +41,26 @@ public class ProjectController {

@Operation(summary = "Get all projects for authenticated user")
@ApiGet
public List<ProjectDto> getProjectsForUser() {
UserEntity user = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Long userId = user.getId();
return projectService.getProjectsForUser(userId);
public List<ProjectDto> getProjectsForUser(@AuthenticationPrincipal UserEntity user) {
return projectService.getProjectsForUser(user.getId());
}

@Operation(summary = "Create new project")
@ApiCreate
public ProjectDto createNewProject(@RequestBody @Valid ProjectDto projectDto) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
public ProjectDto createNewProject(
@AuthenticationPrincipal UserEntity user,
@RequestBody @Valid ProjectDto projectDto
) {
ProjectEntity project = projectService.createProject(
ProjectMapper.INSTANCE.projectDtoToProject(projectDto), authentication.getName()
ProjectMapper.INSTANCE.projectDtoToProject(projectDto), user.getId()
);
return ProjectMapper.INSTANCE.projectToProjectDto(project);
}

@Operation(summary = "Get project by its id")
@ApiGetOne(path = "{id}")
@SuppressWarnings("MVCPathVariableInspection") // fake warn "Cannot resolve path variable 'id' in @RequestMapping"
public OneProjectDto getProject(@PathVariable Long id) {
UserEntity user = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
public OneProjectDto getProject(@AuthenticationPrincipal UserEntity user, @PathVariable Long id) {
return projectService.getProjectForUser(id, user.getId());
}

Expand All @@ -86,10 +84,10 @@ public void deleteProject(@PathVariable Long id) {
@Operation(summary = "Edit project partially")
@ApiPatch(path = "{id}")
public void editProjectPartially(
@AuthenticationPrincipal UserEntity user,
@PathVariable Long id,
@RequestBody List<PatchDto> patchDtoList
) {
UserEntity user = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
projectService.editProjectPartially(id, user.getId(), patchDtoList);
}

Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/febfes/fftmback/controller/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.febfes.fftmback.domain.common.RoleName;
import com.febfes.fftmback.domain.common.specification.TaskSpec;
import com.febfes.fftmback.domain.dao.FileEntity;
import com.febfes.fftmback.domain.dao.TaskEntity;
import com.febfes.fftmback.domain.dao.TaskView;
import com.febfes.fftmback.domain.dao.UserEntity;
import com.febfes.fftmback.dto.EditTaskDto;
import com.febfes.fftmback.dto.TaskDto;
import com.febfes.fftmback.dto.TaskShortDto;
Expand All @@ -21,8 +23,7 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -66,16 +67,16 @@ public TaskDto getTaskById(@ParameterObject TaskParameters pathVars) {
@Operation(summary = "Create new task")
@ApiCreate(path = "{projectId}/columns/{columnId}/tasks")
public TaskShortDto createTask(
@AuthenticationPrincipal UserEntity user,
@ParameterObject ColumnParameters pathVars,
@RequestBody @Valid EditTaskDto taskDto
@RequestBody @Valid EditTaskDto editTaskDto
) {
roleCheckerComponent.checkIfHasRole(pathVars.projectId(), RoleName.MEMBER);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
TaskView task = taskService.createTask(
TaskMapper.INSTANCE.taskDtoToTask(pathVars.projectId(), pathVars.columnId(), taskDto),
authentication.getName()
Long createdTaskId = taskService.createTask(
TaskMapper.INSTANCE.taskDtoToTask(pathVars.projectId(), pathVars.columnId(), editTaskDto),
user.getId()
);
return TaskMapper.INSTANCE.taskViewToTaskShortDto(task);
return TaskMapper.INSTANCE.taskViewToTaskShortDto(taskService.getTaskById(createdTaskId));
}

@Operation(summary = "Edit task by its id")
Expand All @@ -85,8 +86,10 @@ public TaskShortDto updateTask(
@RequestBody EditTaskDto editTaskDto
) {
roleCheckerComponent.checkIfHasRole(pathVars.projectId(), RoleName.MEMBER);
TaskView task = taskService.updateTask(pathVars.taskId(), pathVars.projectId(), pathVars.columnId(), editTaskDto);
return TaskMapper.INSTANCE.taskViewToTaskShortDto(task);
TaskEntity editTask = TaskMapper.INSTANCE.taskDtoToTask(pathVars.projectId(), pathVars.columnId(), editTaskDto);
editTask.setId(pathVars.taskId());
taskService.updateTask(editTask);
return TaskMapper.INSTANCE.taskViewToTaskShortDto(taskService.getTaskById(pathVars.taskId()));
}

@Operation(summary = "Delete task by its id")
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/febfes/fftmback/domain/dao/FileEntity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.febfes.fftmback.domain.dao;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import com.febfes.fftmback.domain.common.EntityType;
import com.febfes.fftmback.domain.dao.abstracts.BaseEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -30,7 +30,8 @@ public class FileEntity extends BaseEntity {
private String name;

@Column(name = "entity_type")
private String entityType;
@Enumerated(EnumType.STRING)
private EntityType entityType;

@Column(name = "content_type")
private String contentType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.dao.abstracts.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -28,6 +29,7 @@ public class ProjectEntity extends BaseEntity {
@JoinColumn(name = "project_id")
private List<TaskColumnEntity> taskColumnEntityList;
//TODO problem when project was deleted
// TODO: rename to columns

@OneToMany(cascade = CascadeType.REMOVE)
@JoinColumn(name = "project_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.dao.abstracts.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.dao.abstracts.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.dao.abstracts.OrderedEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand All @@ -14,7 +15,7 @@
@Getter
@Setter
@ToString(callSuper = true)
public class TaskColumnEntity extends BaseEntity {
public class TaskColumnEntity extends OrderedEntity {

public static final String ENTITY_NAME = "Task column";

Expand All @@ -24,15 +25,13 @@ public class TaskColumnEntity extends BaseEntity {
@Column(name = "project_id", nullable = false)
private Long projectId;

@Column(name = "column_order", nullable = false)
private Integer columnOrder;

@Column(name = "child_task_column_id")
private Long childTaskColumnId;

@OneToMany(cascade = CascadeType.REMOVE)
@JoinColumn(name = "\"columnId\"")
@ToString.Exclude
private List<TaskView> taskList;

@Override
public String getColumnToFindOrder() {
return "projectId";
}
}
8 changes: 7 additions & 1 deletion src/main/java/com/febfes/fftmback/domain/dao/TaskEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.febfes.fftmback.domain.common.TaskPriority;
import com.febfes.fftmback.domain.dao.abstracts.OrderedEntity;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType;
import jakarta.persistence.*;
import lombok.*;
Expand All @@ -21,7 +22,7 @@
@Setter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TaskEntity extends BaseEntity {
public class TaskEntity extends OrderedEntity {

public static final String ENTITY_NAME = "Task";

Expand Down Expand Up @@ -55,4 +56,9 @@ public class TaskEntity extends BaseEntity {
@Column(name = "update_date")
@UpdateTimestamp
private Date updateDate;

@Override
public String getColumnToFindOrder() {
return "columnId";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.febfes.fftmback.domain.dao;


import com.febfes.fftmback.domain.dao.abstracts.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/febfes/fftmback/domain/dao/TaskView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.common.TaskPriority;
import com.febfes.fftmback.domain.dao.abstracts.OrderedView;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand All @@ -16,7 +17,7 @@
@Setter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class TaskView extends BaseView {
public class TaskView extends OrderedView {

@Column(name = "\"name\"")
private String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.dao.abstracts.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/febfes/fftmback/domain/dao/UserView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.febfes.fftmback.domain.dao;

import com.febfes.fftmback.domain.dao.abstracts.BaseView;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.febfes.fftmback.domain.dao;
package com.febfes.fftmback.domain.dao.abstracts;

import jakarta.persistence.*;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.febfes.fftmback.domain.dao;
package com.febfes.fftmback.domain.dao.abstracts;

import jakarta.persistence.*;
import lombok.*;
Expand All @@ -14,7 +14,6 @@
@Getter
@Setter
@ToString
//@Immutable
public abstract class BaseView {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.febfes.fftmback.domain.dao.abstracts;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.*;
import lombok.experimental.SuperBuilder;

import java.lang.reflect.Field;

@MappedSuperclass
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
public abstract class OrderedEntity extends BaseEntity {

@Column(name = "entity_order")
private Integer entityOrder;

/**
* This method is used in OrderService. Field name that returned in this method will be used to
* find entity order
*
* @return field name
*/
public abstract String getColumnToFindOrder();

public Object getValueToFindOrder() {
try {
Field field = getClass().getDeclaredField(getColumnToFindOrder());
field.setAccessible(true);
return field.get(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.febfes.fftmback.domain.dao.abstracts;

import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.*;
import lombok.experimental.SuperBuilder;

@MappedSuperclass
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
public abstract class OrderedView extends BaseView {

@Column(name = "\"entityOrder\"")
private Integer entityOrder;
}
Loading

0 comments on commit d8e0ef5

Please sign in to comment.