Добавлены условия запроса
This commit is contained in:
@@ -10,6 +10,7 @@ import java.util.UUID;
|
|||||||
@Entity
|
@Entity
|
||||||
public class Car {
|
public class Car {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@@ -21,6 +22,9 @@ public class Car {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer year;
|
private Integer year;
|
||||||
|
|
||||||
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
|
private User user;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
private List<Configuration> configurations;
|
private List<Configuration> configurations;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package org.example.domain.entity;
|
package org.example.domain.entity;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import jdk.jfr.Timestamp;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -10,6 +12,7 @@ import java.util.UUID;
|
|||||||
@Entity
|
@Entity
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@@ -18,9 +21,16 @@ public class Configuration {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Timestamp
|
||||||
|
@Column(nullable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "configurations")
|
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "configurations")
|
||||||
private List<Car> cars;
|
private List<Car> cars;
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "configurations")
|
||||||
|
private List<PreparationWork> preparationWorks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.UUID;
|
|||||||
@Data
|
@Data
|
||||||
public class Feature {
|
public class Feature {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.util.UUID;
|
|||||||
@Data
|
@Data
|
||||||
public class PreparationWork {
|
public class PreparationWork {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.UUID;
|
|||||||
@Data
|
@Data
|
||||||
public class Request {
|
public class Request {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Timestamp
|
@Timestamp
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.util.UUID;
|
|||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.UUID;
|
|||||||
@Data
|
@Data
|
||||||
public class Wish {
|
public class Wish {
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
package org.example.domain.repositories;
|
package org.example.domain.repositories;
|
||||||
|
|
||||||
import org.example.domain.entity.Configuration;
|
import org.example.domain.entity.Configuration;
|
||||||
|
import org.example.domain.entity.Request;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ConfigurationRepository extends JpaRepository<Configuration, Long> {
|
public interface ConfigurationRepository extends JpaRepository<Configuration, Long> {
|
||||||
|
|
||||||
|
@Query("select c from Configuration c " +
|
||||||
|
"join c.cars car " +
|
||||||
|
"where (:userId is null or c.user.id = :userid)" +
|
||||||
|
"and c.user.id = car.user.id " +
|
||||||
|
"and c.createdAt > :dateFrom " +
|
||||||
|
"and c.createdAt < :dateFrom")
|
||||||
|
List<Configuration> findByCreatedAtBetween(LocalDate dateFrom, LocalDate dateTo, Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,17 @@ package org.example.domain.repositories;
|
|||||||
|
|
||||||
import org.example.domain.entity.Request;
|
import org.example.domain.entity.Request;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface RequestRepository extends JpaRepository<Request, Long> {
|
public interface RequestRepository extends JpaRepository<Request, Long> {
|
||||||
List<Request> findByCreatedAtBetween(LocalDate dateFrom, LocalDate dateTo);
|
@Query("select r from Request r " +
|
||||||
|
"join r.preparationWorks p " +
|
||||||
|
"where (:userId is null or r.user.id = :userid)" +
|
||||||
|
"and r.user.id = p.user.id " +
|
||||||
|
"and r.createdAt > :dateFrom " +
|
||||||
|
"and r.createdAt < :dateFrom")
|
||||||
|
List<Request> findByCreatedAtBetween(LocalDate dateFrom, LocalDate dateTo, Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import org.example.domain.repositories.ConfigurationRepository;
|
|||||||
import org.example.exceptions.ObjectNotExistsException;
|
import org.example.exceptions.ObjectNotExistsException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -29,4 +31,8 @@ public class ConfigurationManager {
|
|||||||
public List<Configuration> getAll(){
|
public List<Configuration> getAll(){
|
||||||
return configurationRepository.findAll();
|
return configurationRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Configuration> getAll(LocalDate dateFrom, LocalDate dateTo, Long userId){
|
||||||
|
return configurationRepository.findByCreatedAtBetween(dateFrom, dateTo, userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class RequestManager {
|
|||||||
return requestRepository.findAll();
|
return requestRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Request> getAll(LocalDate dateFrom, LocalDate dateTo){
|
public List<Request> getAll(LocalDate dateFrom, LocalDate dateTo, Long userId){
|
||||||
return requestRepository.findByCreatedAtBetween(dateFrom, dateTo);
|
return requestRepository.findByCreatedAtBetween(dateFrom, dateTo, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user