Merge branch 'main' of https://github.com/Parpaillax/Ludotheque
This commit is contained in:
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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,32 +12,28 @@ 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;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
55
src/main/java/fr/eni/demo/controller/AddressController.java
Normal file
55
src/main/java/fr/eni/demo/controller/AddressController.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package fr.eni.demo.controller;
|
||||
|
||||
import fr.eni.demo.bll.AdresseService;
|
||||
import fr.eni.demo.bll.StockService;
|
||||
import fr.eni.demo.bo.Adresse;
|
||||
import fr.eni.demo.bo.Stock;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/address")
|
||||
@RequiredArgsConstructor
|
||||
public class AddressController {
|
||||
|
||||
private final AdresseService adresseService;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Map<String, Object>> create(@RequestBody Adresse adresse) {
|
||||
adresseService.add(adresse);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("message", "Adresse added");
|
||||
response.put("status", true);
|
||||
response.put("data", new HashMap<>());
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Map<String, Object>> findById(@PathVariable Long id) {
|
||||
Adresse result = adresseService.findById(id);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("message", "Adresse find");
|
||||
response.put("status", true);
|
||||
response.put("data", result);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@GetMapping("/client/{id}")
|
||||
public ResponseEntity<Map<String, Object>> findByIdClient(@PathVariable Long id) {
|
||||
Adresse result = adresseService.findAdresseByClientId(id);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("message", "Adresse find");
|
||||
response.put("status", true);
|
||||
response.put("data", result);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class ClientController {
|
||||
}
|
||||
|
||||
// Modifier l'address d'un client
|
||||
@PutMapping("/{id}")
|
||||
@PutMapping("/address/{id}")
|
||||
public ResponseEntity<Map<String, Object>> updateAddress(@PathVariable Long id, @RequestBody Adresse adresse) {
|
||||
clientService.updateLocation(id, adresse);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
34
src/main/java/fr/eni/demo/controller/GameTypeController.java
Normal file
34
src/main/java/fr/eni/demo/controller/GameTypeController.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package fr.eni.demo.controller;
|
||||
|
||||
import fr.eni.demo.bll.GameTypeService;
|
||||
import fr.eni.demo.bo.GameType;
|
||||
import fr.eni.demo.bo.Stock;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/gametype")
|
||||
@RequiredArgsConstructor
|
||||
public class GameTypeController {
|
||||
|
||||
private final GameTypeService gameTypeService;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Map<String, Object>> create(@RequestBody GameType gameType) {
|
||||
gameTypeService.add(gameType);
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("message", "Game type create");
|
||||
response.put("status", true);
|
||||
response.put("data", new HashMap<>());
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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> {
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user