@@ -39,12 +39,6 @@ public class ComplaintEntity {
|
||||
@JsonIgnore
|
||||
private Violation violation;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "law_case_id")
|
||||
@ToString.Exclude
|
||||
@JsonIgnore
|
||||
private LawCase lawCase;
|
||||
|
||||
@Column(name = "created_at", updatable = false)
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt;
|
||||
@@ -55,4 +49,12 @@ public class ComplaintEntity {
|
||||
|
||||
@Column(name = "not_moderated_file")
|
||||
private Boolean not_moderated_file;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Notification {
|
||||
|
||||
@Column(name = "created_at", updatable = false)
|
||||
@CreatedDate
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime createdAt = LocalDateTime.now();
|
||||
|
||||
@LastModifiedDate
|
||||
@Column(name = "updated_at")
|
||||
@@ -46,4 +46,13 @@ public class Notification {
|
||||
@JoinColumn(name = "user_id")
|
||||
@JsonIgnore
|
||||
private User user;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,13 @@ public class Payment {
|
||||
@JoinColumn(name = "tariff_id")
|
||||
@JsonIgnore
|
||||
private Tariff tariff;
|
||||
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,12 @@ public class UserVerification {
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "status")
|
||||
private ModerationStatus moderationStatus;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,12 @@ public class ViolationNotion {
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.createdAt == null) {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
}
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import ru.soune.nocopy.entity.notification.NotificationStatus;
|
||||
import ru.soune.nocopy.entity.notification.NotificationType;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface NotificationRepository extends JpaRepository<Notification, Long> {
|
||||
@@ -29,12 +30,13 @@ public interface NotificationRepository extends JpaRepository<Notification, Long
|
||||
long countByUserAndStatus(User user, NotificationStatus status);
|
||||
|
||||
@Modifying
|
||||
@Query("UPDATE Notification n SET n.status = :newStatus WHERE n.id IN :ids AND n.user = :user AND " +
|
||||
@Query("UPDATE Notification n SET n.status = :newStatus , n.updatedAt = :updateTime WHERE n.id IN :ids AND n.user = :user AND " +
|
||||
"n.status = :oldStatus")
|
||||
int updateStatus(@Param("ids") List<Long> ids,
|
||||
@Param("user") User user,
|
||||
@Param("oldStatus") NotificationStatus oldStatus,
|
||||
@Param("newStatus") NotificationStatus newStatus);
|
||||
@Param("newStatus") NotificationStatus newStatus,
|
||||
@Param("updateTime") LocalDateTime updateTime);
|
||||
|
||||
Page<Notification> getNotificationsByUser(User user, Pageable pageable);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import ru.soune.nocopy.repository.NotificationRepository;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.user.UserService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -39,6 +40,7 @@ public class NotificationService {
|
||||
|
||||
Notification notification = Notification.builder()
|
||||
.notificationType(notificationType)
|
||||
.createdAt(LocalDateTime.now())
|
||||
.user(userRepository.findById(userId).orElseThrow())
|
||||
.status(NotificationStatus.NEW)
|
||||
.message(message)
|
||||
@@ -110,7 +112,8 @@ public class NotificationService {
|
||||
if (notificationIds == null || notificationIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return notificationRepository.updateStatus(notificationIds, user, NotificationStatus.NEW,
|
||||
NotificationStatus.READIED);
|
||||
NotificationStatus.READIED, LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user