Changement mongo

This commit is contained in:
mepiphana2023
2025-07-16 10:06:29 +02:00
parent b5fa67fae9
commit ec72d6c850
12 changed files with 68 additions and 100 deletions

View File

@@ -24,17 +24,14 @@ repositories {
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'jakarta.persistence:jakarta.persistence-api:3.1.0'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}

View File

@@ -1,31 +1,29 @@
package fr.eni.demo.bo;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@Builder
@Entity
@Table(name="ADRESSES")
@Document(collection = "address")
public class Adresse {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ADRESSE_ID")
private Integer id;
@Column(name = "STREET",nullable = false, length = 250)
@Field(name = "STREET")
private String rue;
@Column(name = "POSTAL_CODE",nullable = false, length = 5)
@Field(name = "POSTAL_CODE")
private String codePostal;
@Column(name = "CITY",nullable = false, length = 150)
@Field(name = "CITY")
private String ville;
}

View File

@@ -1,7 +1,10 @@
package fr.eni.demo.bo;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.List;
@@ -9,31 +12,27 @@ import java.util.List;
@NoArgsConstructor
@Getter
@Setter
@ToString(exclude = "locations")
@Builder
@Entity
@Table(name="CLIENTS")
@Document(collection = "clients")
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CLIENT_ID")
private Integer id;
@Column(name= "LAST_NAME", nullable = false, length = 90)
@Id
private String id;
@Field(name = "LAST_NAME")
private String nom;
@Column(name= "FIRST_NAME", nullable = false, length = 150)
@Field(name = "FIRST_NAME")
private String prenom;
@Column(nullable = false, unique = true)
@Field(name = "EMAIL")
private String email;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "ADRESSE_ID")
@DBRef
@Field(name = "ADRESSE")
private Adresse adresse;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "CLIENT_ID")
@DBRef
@Field(name = "LOCATIONS")
private List<Location> locations;
}

View File

@@ -1,24 +1,21 @@
package fr.eni.demo.bo;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@Builder
@Entity
@Table(name="GAME_TYPE")
@Document(collection = "game_type")
public class GameType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "GAME_TYPE_ID")
private Integer id;
private String id;
@Column(name="GAME_TYPE_NAME", nullable = false)
@Field(name = "GAME_TYPE_NAME")
private String name;
}

View File

@@ -1,7 +1,10 @@
package fr.eni.demo.bo;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.Date;
@@ -9,29 +12,24 @@ import java.util.Date;
@NoArgsConstructor
@Getter
@Setter
@ToString(exclude = {"client", "stock"})
@Builder
@Entity
@Table(name="LOCATIONS")
@Document(collection = "locations")
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="LOCATION_ID")
private Integer id;
private String id;
@Column(name = "LOCATION_START_DATE", nullable = false)
@Field(name = "LOCATION_START_DATE")
private Date startDate;
@Column(name = "LOCATION_END_DATE")
@Field(name = "LOCATION_END_DATE")
private Date endDate;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "CLIENT_ID", nullable = false)
@DBRef
@Field(name = "CLIENT")
private Client client;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "GAME_ID", nullable = false)
@DBRef
@Field(name = "STOCK")
private Stock stock;
}

View File

@@ -1,8 +1,10 @@
package fr.eni.demo.bo;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.List;
@@ -10,39 +12,30 @@ import java.util.List;
@NoArgsConstructor
@Getter
@Setter
@ToString
@Builder
@Entity
@Table(name="GAME")
@Document(collection = "stock")
public class Stock {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "GAME_ID")
private Integer id;
private String id;
@Column(name="GAME_NAME", nullable = false)
@Field(name = "GAME_NAME")
private String name;
@Column(name="GAME_DESCRIPTION")
@Field(name = "GAME_DESCRIPTION")
private String description;
@Column(name="GAME_REF", nullable = false)
@Field(name = "GAME_REF")
private String ref;
@Column(name="GAME_DAILY_PRICE", nullable = false)
@Field(name = "GAME_DAILY_PRICE")
private Double dailyPrice;
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
@JoinTable(
name = "STOCK_GAME_TYPE",
joinColumns = @JoinColumn(name = "GAME_ID"), // Clé étrangère vers Stock
inverseJoinColumns = @JoinColumn(name = "GAME_TYPE_ID") // Clé étrangère vers GameType
)
@DBRef
@Field(name = "GAME_TYPE")
private List<GameType> gameType;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "GAME_ID")
@DBRef
@Field(name = "LOCATIONS")
private List<Location> locations;
}

View File

@@ -1,9 +1,9 @@
package fr.eni.demo.dal;
import fr.eni.demo.bo.Adresse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AdresseRepository extends JpaRepository<Adresse, Long> {
public interface AdresseRepository extends MongoRepository<Adresse, Long> {
}

View File

@@ -1,13 +1,13 @@
package fr.eni.demo.dal;
import fr.eni.demo.bo.Client;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface ClientRepository extends JpaRepository<Client, Long> {
public interface ClientRepository extends MongoRepository<Client, Long> {
List<Client> findByPrenomIgnoreCaseContainingOrNomIgnoreCaseContaining(String prenom, String nom);
}

View File

@@ -1,9 +1,9 @@
package fr.eni.demo.dal;
import fr.eni.demo.bo.GameType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface GameTypeRepository extends JpaRepository<GameType, Long> {
public interface GameTypeRepository extends MongoRepository<GameType, Long> {
}

View File

@@ -1,9 +1,9 @@
package fr.eni.demo.dal;
import fr.eni.demo.bo.Location;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface LocationRepository extends JpaRepository<Location, Integer> {
public interface LocationRepository extends MongoRepository<Location, Integer> {
}

View File

@@ -1,9 +1,9 @@
package fr.eni.demo.dal;
import fr.eni.demo.bo.Stock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface StockRepository extends JpaRepository<Stock,Long> {
public interface StockRepository extends MongoRepository<Stock,Long> {
}

View File

@@ -1,20 +1,6 @@
spring:
application:
name: ENI-ludotheque
#Connection to DB
datasource:
url: jdbc:sqlserver://localhost;databasename=LUDO_DB;integratedSecurity=false;encrypt=false;trustServerCertificate=false
username: LUDO_USER
password: LUDO_PWD
#Options to DB
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
ddl-auto: create
data:
mongodb: