From 6ab5d87a8bc9f838198db4939378d3342402fd66 Mon Sep 17 00:00:00 2001 From: Ivan Shishkin Date: Thu, 23 May 2024 19:20:53 +0300 Subject: [PATCH 1/2] 191 - changed Date to LocalDateTime and added deadline --- .../domain/dao/RefreshTokenEntity.java | 4 +-- .../fftmback/domain/dao/TaskEntity.java | 7 +++-- .../febfes/fftmback/domain/dao/TaskView.java | 7 +++-- .../domain/dao/abstracts/BaseEntity.java | 4 +-- .../domain/dao/abstracts/BaseView.java | 4 +-- .../projection/ProjectForUserProjection.java | 4 +-- .../domain/projection/ProjectProjection.java | 4 +-- .../com/febfes/fftmback/dto/ColumnDto.java | 4 +-- .../febfes/fftmback/dto/OneProjectDto.java | 4 +-- .../com/febfes/fftmback/dto/ProjectDto.java | 4 +-- .../java/com/febfes/fftmback/dto/TaskDto.java | 30 +++++++++---------- .../com/febfes/fftmback/dto/TaskFileDto.java | 4 +-- .../com/febfes/fftmback/dto/TaskShortDto.java | 9 +++--- .../febfes/fftmback/dto/error/ErrorDto.java | 4 +-- .../fftmback/exception/ControllerAdvisor.java | 10 +++---- .../service/impl/RefreshTokenServiceImpl.java | 6 ++-- .../com/febfes/fftmback/util/DateUtils.java | 24 ++++++++++----- .../changes/2024.05.01-add-task-deadline.yaml | 12 ++++++++ .../resources/db/changelog/view/v_task.sql | 1 + .../authentication/AuthenticateUserTest.java | 2 +- 20 files changed, 90 insertions(+), 58 deletions(-) create mode 100644 src/main/resources/db/changelog/changes/2024.05.01-add-task-deadline.yaml diff --git a/src/main/java/com/febfes/fftmback/domain/dao/RefreshTokenEntity.java b/src/main/java/com/febfes/fftmback/domain/dao/RefreshTokenEntity.java index eb04f0df..740573c4 100644 --- a/src/main/java/com/febfes/fftmback/domain/dao/RefreshTokenEntity.java +++ b/src/main/java/com/febfes/fftmback/domain/dao/RefreshTokenEntity.java @@ -5,7 +5,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.Date; +import java.time.LocalDateTime; @Entity @Table(name = "refresh_token") @@ -29,6 +29,6 @@ public class RefreshTokenEntity extends BaseEntity { private String token; @Column(name = "expiry_date", nullable = false) - private Date expiryDate; + private LocalDateTime expiryDate; } diff --git a/src/main/java/com/febfes/fftmback/domain/dao/TaskEntity.java b/src/main/java/com/febfes/fftmback/domain/dao/TaskEntity.java index a0833866..7b6147fd 100644 --- a/src/main/java/com/febfes/fftmback/domain/dao/TaskEntity.java +++ b/src/main/java/com/febfes/fftmback/domain/dao/TaskEntity.java @@ -10,7 +10,7 @@ import org.hibernate.annotations.Type; import org.hibernate.annotations.UpdateTimestamp; -import java.util.Date; +import java.time.LocalDateTime; @Entity @@ -55,7 +55,10 @@ public class TaskEntity extends OrderedEntity { @Column(name = "update_date") @UpdateTimestamp - private Date updateDate; + private LocalDateTime updateDate; + + @Column(name = "deadline_date") + private LocalDateTime deadlineDate; @Override public String getColumnToFindOrder() { diff --git a/src/main/java/com/febfes/fftmback/domain/dao/TaskView.java b/src/main/java/com/febfes/fftmback/domain/dao/TaskView.java index 107e3de0..0e72a6bf 100644 --- a/src/main/java/com/febfes/fftmback/domain/dao/TaskView.java +++ b/src/main/java/com/febfes/fftmback/domain/dao/TaskView.java @@ -6,7 +6,7 @@ import lombok.*; import lombok.experimental.SuperBuilder; -import java.util.Date; +import java.time.LocalDateTime; @Entity @Table(name = "v_task") @@ -51,5 +51,8 @@ public class TaskView extends OrderedView { private Long filesCounter; @Column(name = "\"updateDate\"") - private Date updateDate; + private LocalDateTime updateDate; + + @Column(name = "\"deadlineDate\"") + private LocalDateTime deadlineDate; } diff --git a/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseEntity.java b/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseEntity.java index 909f99b3..c53f1a5c 100644 --- a/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseEntity.java +++ b/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseEntity.java @@ -5,7 +5,7 @@ import lombok.experimental.SuperBuilder; import org.hibernate.annotations.CreationTimestamp; -import java.util.Date; +import java.time.LocalDateTime; @MappedSuperclass @SuperBuilder @@ -22,5 +22,5 @@ public abstract class BaseEntity { @Column(name = "create_date", updatable = false) @CreationTimestamp - private Date createDate; + private LocalDateTime createDate; } diff --git a/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseView.java b/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseView.java index 8b517f27..246afacb 100644 --- a/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseView.java +++ b/src/main/java/com/febfes/fftmback/domain/dao/abstracts/BaseView.java @@ -5,7 +5,7 @@ import lombok.experimental.SuperBuilder; import org.hibernate.annotations.CreationTimestamp; -import java.util.Date; +import java.time.LocalDateTime; @MappedSuperclass @SuperBuilder @@ -23,5 +23,5 @@ public abstract class BaseView { @Column(name = "\"createDate\"", updatable = false) @CreationTimestamp - private Date createDate; + private LocalDateTime createDate; } diff --git a/src/main/java/com/febfes/fftmback/domain/projection/ProjectForUserProjection.java b/src/main/java/com/febfes/fftmback/domain/projection/ProjectForUserProjection.java index dd476334..60f4d368 100644 --- a/src/main/java/com/febfes/fftmback/domain/projection/ProjectForUserProjection.java +++ b/src/main/java/com/febfes/fftmback/domain/projection/ProjectForUserProjection.java @@ -1,6 +1,6 @@ package com.febfes.fftmback.domain.projection; -import java.util.Date; +import java.time.LocalDateTime; public interface ProjectForUserProjection { @@ -10,7 +10,7 @@ public interface ProjectForUserProjection { String getDescription(); - Date getCreateDate(); + LocalDateTime getCreateDate(); Long getOwnerId(); diff --git a/src/main/java/com/febfes/fftmback/domain/projection/ProjectProjection.java b/src/main/java/com/febfes/fftmback/domain/projection/ProjectProjection.java index 47b583af..cc4fc88b 100644 --- a/src/main/java/com/febfes/fftmback/domain/projection/ProjectProjection.java +++ b/src/main/java/com/febfes/fftmback/domain/projection/ProjectProjection.java @@ -1,6 +1,6 @@ package com.febfes.fftmback.domain.projection; -import java.util.Date; +import java.time.LocalDateTime; public interface ProjectProjection { @@ -10,7 +10,7 @@ public interface ProjectProjection { String getDescription(); - Date getCreateDate(); + LocalDateTime getCreateDate(); Long getOwnerId(); diff --git a/src/main/java/com/febfes/fftmback/dto/ColumnDto.java b/src/main/java/com/febfes/fftmback/dto/ColumnDto.java index c887f46b..22c1c485 100644 --- a/src/main/java/com/febfes/fftmback/dto/ColumnDto.java +++ b/src/main/java/com/febfes/fftmback/dto/ColumnDto.java @@ -4,7 +4,7 @@ import jakarta.validation.constraints.NotBlank; import lombok.Builder; -import java.util.Date; +import java.time.LocalDateTime; @Builder public record ColumnDto( @@ -15,7 +15,7 @@ public record ColumnDto( String name, @Schema(accessMode = Schema.AccessMode.READ_ONLY) - Date createDate, + LocalDateTime createDate, @Schema(description = "Column order on the board. Starts at 1") Integer order, diff --git a/src/main/java/com/febfes/fftmback/dto/OneProjectDto.java b/src/main/java/com/febfes/fftmback/dto/OneProjectDto.java index 0eabfa85..46fb79dc 100644 --- a/src/main/java/com/febfes/fftmback/dto/OneProjectDto.java +++ b/src/main/java/com/febfes/fftmback/dto/OneProjectDto.java @@ -1,13 +1,13 @@ package com.febfes.fftmback.dto; -import java.util.Date; +import java.time.LocalDateTime; import java.util.List; public record OneProjectDto( Long id, String name, String description, - Date createDate, + LocalDateTime createDate, Boolean isFavourite, List members, RoleDto userRoleOnProject diff --git a/src/main/java/com/febfes/fftmback/dto/ProjectDto.java b/src/main/java/com/febfes/fftmback/dto/ProjectDto.java index 6e0218a5..e3130cc6 100644 --- a/src/main/java/com/febfes/fftmback/dto/ProjectDto.java +++ b/src/main/java/com/febfes/fftmback/dto/ProjectDto.java @@ -4,7 +4,7 @@ import jakarta.validation.constraints.NotBlank; import lombok.Builder; -import java.util.Date; +import java.time.LocalDateTime; @Builder public record ProjectDto( @@ -18,7 +18,7 @@ public record ProjectDto( String description, @Schema(accessMode = Schema.AccessMode.READ_ONLY) - Date createDate, + LocalDateTime createDate, @Schema(accessMode = Schema.AccessMode.READ_ONLY) Long ownerId, diff --git a/src/main/java/com/febfes/fftmback/dto/TaskDto.java b/src/main/java/com/febfes/fftmback/dto/TaskDto.java index 59ea6ed2..b0e881cd 100644 --- a/src/main/java/com/febfes/fftmback/dto/TaskDto.java +++ b/src/main/java/com/febfes/fftmback/dto/TaskDto.java @@ -3,26 +3,26 @@ import com.febfes.fftmback.domain.common.TaskPriority; import lombok.Builder; -import java.util.Date; +import java.time.LocalDateTime; import java.util.List; @Builder public record TaskDto( - Long id, - String name, - String description, - Date createDate, - Long projectId, - Long columnId, - TaskPriority priority, - String type, - Long filesCounter, - List files, - UserDto owner, - UserDto assignee, - - Date updateDate + Long id + , String name + , String description + , LocalDateTime createDate + , Long projectId + , Long columnId + , TaskPriority priority + , String type + , Long filesCounter + , List files + , UserDto owner + , UserDto assignee + , LocalDateTime updateDate + , LocalDateTime deadlineDate ) { } diff --git a/src/main/java/com/febfes/fftmback/dto/TaskFileDto.java b/src/main/java/com/febfes/fftmback/dto/TaskFileDto.java index 9682ecca..1255ae7a 100644 --- a/src/main/java/com/febfes/fftmback/dto/TaskFileDto.java +++ b/src/main/java/com/febfes/fftmback/dto/TaskFileDto.java @@ -1,12 +1,12 @@ package com.febfes.fftmback.dto; -import java.util.Date; +import java.time.LocalDateTime; public record TaskFileDto( Long id, - Date createDate, + LocalDateTime createDate, Long userId, diff --git a/src/main/java/com/febfes/fftmback/dto/TaskShortDto.java b/src/main/java/com/febfes/fftmback/dto/TaskShortDto.java index 7fbcba12..a3a5778d 100644 --- a/src/main/java/com/febfes/fftmback/dto/TaskShortDto.java +++ b/src/main/java/com/febfes/fftmback/dto/TaskShortDto.java @@ -2,7 +2,7 @@ import com.febfes.fftmback.domain.common.TaskPriority; -import java.util.Date; +import java.time.LocalDateTime; public record TaskShortDto( Long id, @@ -10,13 +10,14 @@ public record TaskShortDto( String description, Long columnId, Long projectId, - Date createDate, + LocalDateTime createDate, TaskPriority priority, String type, Long filesCounter, UserDto owner, UserDto assignee, - Date updateDate, - Integer order + LocalDateTime updateDate, + Integer order, + LocalDateTime deadlineDate ) { } diff --git a/src/main/java/com/febfes/fftmback/dto/error/ErrorDto.java b/src/main/java/com/febfes/fftmback/dto/error/ErrorDto.java index 9f4eab2a..b835a18f 100644 --- a/src/main/java/com/febfes/fftmback/dto/error/ErrorDto.java +++ b/src/main/java/com/febfes/fftmback/dto/error/ErrorDto.java @@ -1,6 +1,6 @@ package com.febfes.fftmback.dto.error; -import java.util.Date; +import java.time.LocalDateTime; import java.util.Map; public record ErrorDto( @@ -8,7 +8,7 @@ public record ErrorDto( Integer statusCode, StatusError status, ErrorType errorType, - Date timestamp, + LocalDateTime timestamp, String message, Map error ) { diff --git a/src/main/java/com/febfes/fftmback/exception/ControllerAdvisor.java b/src/main/java/com/febfes/fftmback/exception/ControllerAdvisor.java index 808871cd..0d7e3b48 100644 --- a/src/main/java/com/febfes/fftmback/exception/ControllerAdvisor.java +++ b/src/main/java/com/febfes/fftmback/exception/ControllerAdvisor.java @@ -4,7 +4,6 @@ import com.febfes.fftmback.dto.error.ErrorDto; import com.febfes.fftmback.dto.error.ErrorType; import com.febfes.fftmback.dto.error.StatusError; -import com.febfes.fftmback.util.DateUtils; import io.jsonwebtoken.ExpiredJwtException; import io.swagger.v3.oas.annotations.Hidden; import lombok.RequiredArgsConstructor; @@ -20,6 +19,7 @@ import java.util.Map; import static com.febfes.fftmback.dto.error.AuthError.createBaseError; +import static com.febfes.fftmback.util.DateUtils.getCurrentLocalDateTime; import static java.util.Objects.isNull; @RestControllerAdvice @@ -62,7 +62,7 @@ public ErrorDto handleConstraintViolationException( .orElse(Collections.emptyMap()); log.error(LOG_MSG.formatted(ex.getClass().getSimpleName()), ex); return new ErrorDto(HttpStatus.UNPROCESSABLE_ENTITY.value(), StatusError.ARGUMENT_NOT_VALID, - errorType, DateUtils.getCurrentDate(), ex.getMessage(), errorMap); + errorType, getCurrentLocalDateTime(), ex.getMessage(), errorMap); } @ExceptionHandler({ExpiredJwtException.class, TokenExpiredException.class}) @@ -94,7 +94,7 @@ public ErrorDto handleBadCredentialsException( ErrorType errorType = ErrorType.AUTH; log.error(LOG_MSG.formatted(ex.getClass().getSimpleName()), ex); return new ErrorDto(HttpStatus.UNPROCESSABLE_ENTITY.value(), StatusError.BAD_CREDENTIALS, - errorType, DateUtils.getCurrentDate(), ex.getMessage(), + errorType, getCurrentLocalDateTime(), ex.getMessage(), createBaseError(UserEntity.ENTITY_NAME, "password", null, errorType)); } @@ -126,7 +126,7 @@ private ErrorDto createExceptionResponseBody( status.value(), ex.getStatusError(), ex.getErrorType(), - DateUtils.getCurrentDate(), + getCurrentLocalDateTime(), ex.getMessage(), ex.getBaseError() ); @@ -140,7 +140,7 @@ private ErrorDto createExceptionResponseBody( status.value(), StatusError.UNDEFINED, ErrorType.UNDEFINED, - DateUtils.getCurrentDate(), + getCurrentLocalDateTime(), ex.getMessage(), null ); diff --git a/src/main/java/com/febfes/fftmback/service/impl/RefreshTokenServiceImpl.java b/src/main/java/com/febfes/fftmback/service/impl/RefreshTokenServiceImpl.java index d20460d9..ad9f04e0 100644 --- a/src/main/java/com/febfes/fftmback/service/impl/RefreshTokenServiceImpl.java +++ b/src/main/java/com/febfes/fftmback/service/impl/RefreshTokenServiceImpl.java @@ -17,6 +17,8 @@ import java.util.UUID; +import static com.febfes.fftmback.util.DateUtils.getCurrentLocalDateTimePlusSeconds; + @Service @Slf4j @RequiredArgsConstructor @@ -49,7 +51,7 @@ public RefreshTokenEntity getByUserId(Long userId) { @Override public RefreshTokenEntity updateRefreshToken(RefreshTokenEntity refreshToken) { refreshToken.setToken(UUID.randomUUID().toString()); - refreshToken.setExpiryDate(DateUtils.getCurrentDatePlusSeconds(jwtRefreshExpirationDateInSeconds)); + refreshToken.setExpiryDate(getCurrentLocalDateTimePlusSeconds(jwtRefreshExpirationDateInSeconds)); RefreshTokenEntity updatedRefreshToken = refreshTokenRepository.save(refreshToken); log.info("Updated refresh token entity: {}", updatedRefreshToken); return updatedRefreshToken; @@ -60,7 +62,7 @@ public RefreshTokenEntity createRefreshToken(Long userId) { RefreshTokenEntity refreshToken = refreshTokenRepository.save( RefreshTokenEntity.builder() .userEntity(userService.getUserById(userId)) - .expiryDate(DateUtils.getCurrentDatePlusSeconds(jwtRefreshExpirationDateInSeconds)) + .expiryDate(getCurrentLocalDateTimePlusSeconds(jwtRefreshExpirationDateInSeconds)) .token(UUID.randomUUID().toString()) .build() ); diff --git a/src/main/java/com/febfes/fftmback/util/DateUtils.java b/src/main/java/com/febfes/fftmback/util/DateUtils.java index dc1dac0d..9284a318 100644 --- a/src/main/java/com/febfes/fftmback/util/DateUtils.java +++ b/src/main/java/com/febfes/fftmback/util/DateUtils.java @@ -8,26 +8,36 @@ @UtilityClass public class DateUtils { - public static final String STANDARD_DATE_PATTERN = "dd-MM-yyyy HH:mm:ss"; public static Date getCurrentDate() { return new Date(); } + public static LocalDateTime getCurrentLocalDateTime() { + return LocalDateTime.now(); + } + public static Date getCurrentDatePlusSeconds(int seconds) { return new Date(System.currentTimeMillis() + seconds * 1000L); } + public static LocalDateTime getCurrentLocalDateTimePlusSeconds(int seconds) { + return LocalDateTime.now().plusSeconds(seconds); + } + + public static boolean isDateBeforeCurrentDate(Date date) { + return date.before(DateUtils.getCurrentDate()); + } + + public static boolean isDateBeforeCurrentDate(LocalDateTime date) { + return date.isBefore(DateUtils.getCurrentLocalDateTime()); + } + public static LocalDateTime convertDateToLocalDateTime(Date date) { return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); } public static Date convertLocalDateTimeToDate(LocalDateTime dateToConvert) { - return Date.from(dateToConvert.atZone(ZoneId.systemDefault()) - .toInstant()); - } - - public static boolean isDateBeforeCurrentDate(Date date) { - return date.before(DateUtils.getCurrentDate()); + return Date.from(dateToConvert.atZone(ZoneId.systemDefault()).toInstant()); } } diff --git a/src/main/resources/db/changelog/changes/2024.05.01-add-task-deadline.yaml b/src/main/resources/db/changelog/changes/2024.05.01-add-task-deadline.yaml new file mode 100644 index 00000000..5147dedf --- /dev/null +++ b/src/main/resources/db/changelog/changes/2024.05.01-add-task-deadline.yaml @@ -0,0 +1,12 @@ +databaseChangeLog: + - changeSet: + id: 1 + author: IvanShish + comment: "Add task deadline" + changes: + - addColumn: + tableName: task + columns: + - column: + name: deadline_date + type: timestamp diff --git a/src/main/resources/db/changelog/view/v_task.sql b/src/main/resources/db/changelog/view/v_task.sql index 43c939f5..df1b6fb5 100644 --- a/src/main/resources/db/changelog/view/v_task.sql +++ b/src/main/resources/db/changelog/view/v_task.sql @@ -20,5 +20,6 @@ select t.id as "id" and fe.entity_type = 'TASK') as "filesCounter" , t.update_date as "updateDate" , t.entity_order as "entityOrder" + , t.deadline_date as "deadlineDate" from task t ; diff --git a/src/test/java/com/febfes/fftmback/unit/authentication/AuthenticateUserTest.java b/src/test/java/com/febfes/fftmback/unit/authentication/AuthenticateUserTest.java index d6ebe271..0afbe4dd 100644 --- a/src/test/java/com/febfes/fftmback/unit/authentication/AuthenticateUserTest.java +++ b/src/test/java/com/febfes/fftmback/unit/authentication/AuthenticateUserTest.java @@ -69,7 +69,7 @@ void testAuthenticateUser() { refreshToken.setId(FIRST_ID); refreshToken.setToken(TOKEN); refreshToken.setUserEntity(user); - refreshToken.setExpiryDate(DateUtils.getCurrentDate()); + refreshToken.setExpiryDate(DateUtils.getCurrentLocalDateTime()); // Set up the mock objects to return the expected values when(authenticationManager.authenticate(any(Authentication.class))).thenReturn(null); From 404583f4c54c57e05831ae0d8b9014061b2f9a21 Mon Sep 17 00:00:00 2001 From: Ivan Shishkin Date: Fri, 24 May 2024 23:57:11 +0300 Subject: [PATCH 2/2] 191 - deadline finished --- src/main/java/com/febfes/fftmback/dto/EditTaskDto.java | 10 ++++------ .../febfes/fftmback/service/impl/TaskServiceImpl.java | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/febfes/fftmback/dto/EditTaskDto.java b/src/main/java/com/febfes/fftmback/dto/EditTaskDto.java index 9f5a528d..4a401815 100644 --- a/src/main/java/com/febfes/fftmback/dto/EditTaskDto.java +++ b/src/main/java/com/febfes/fftmback/dto/EditTaskDto.java @@ -3,19 +3,17 @@ import com.febfes.fftmback.domain.common.TaskPriority; import jakarta.validation.constraints.NotBlank; +import java.time.LocalDateTime; + public record EditTaskDto( @NotBlank(message = "Invalid Name: Empty name") String name, - String description, - Long assigneeId, - TaskPriority priority, - String type, - - Integer order + Integer order, + LocalDateTime deadlineDate ) { } diff --git a/src/main/java/com/febfes/fftmback/service/impl/TaskServiceImpl.java b/src/main/java/com/febfes/fftmback/service/impl/TaskServiceImpl.java index 460906d5..1ccf2e7f 100644 --- a/src/main/java/com/febfes/fftmback/service/impl/TaskServiceImpl.java +++ b/src/main/java/com/febfes/fftmback/service/impl/TaskServiceImpl.java @@ -105,6 +105,7 @@ public void updateTask(TaskEntity editTask) { task.setProjectId(editTask.getProjectId()); task.setPriority(editTask.getPriority()); task.setAssigneeId(editTask.getAssigneeId()); + task.setDeadlineDate(editTask.getDeadlineDate()); fillTaskType(task, editTask.getTaskType().getName(), editTask.getProjectId()); taskRepository.save(task); orderService.editOrder(task, editTask.getEntityOrder());