Modif SQL
This commit is contained in:
parent
008669c50f
commit
dc3a6f25c0
7 changed files with 123 additions and 7 deletions
28
pom.xml
28
pom.xml
|
|
@ -30,16 +30,44 @@
|
|||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- Web (REST controllers) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Accès aux bases de données via JDBC -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JPA / Hibernate -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Connecteur MySQL -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Tests -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>annotationProcessor</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -2,19 +2,28 @@ package fr.teamflash.archy.controller;
|
|||
|
||||
import fr.teamflash.archy.dto.userDTO;
|
||||
import fr.teamflash.archy.dto.userDisplayDTO;
|
||||
import fr.teamflash.archy.entity.userEntity;
|
||||
import fr.teamflash.archy.fonction.calcule;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import fr.teamflash.archy.repository.userRepository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
public class userController {
|
||||
|
||||
@Autowired
|
||||
private userRepository userRepository;
|
||||
|
||||
@PostMapping("add")
|
||||
public ResponseEntity afficher (@RequestBody userDTO dto){
|
||||
// calcule l'age
|
||||
|
|
@ -41,4 +50,27 @@ public class userController {
|
|||
return new ResponseEntity(respond, HttpStatusCode.valueOf(200));
|
||||
}
|
||||
|
||||
@GetMapping("get/{id}")
|
||||
public ResponseEntity get(@PathVariable String id) {
|
||||
Integer ID;
|
||||
|
||||
// Vérifie si le paramètre est un entier
|
||||
try {
|
||||
ID = Integer.parseInt(id);
|
||||
} catch (NumberFormatException e) {
|
||||
return new ResponseEntity("ID invalide : ce n'est pas un entier.", HttpStatusCode.valueOf(400));
|
||||
}
|
||||
|
||||
// Recherche dans la base
|
||||
Optional<userEntity> result = userRepository.findById(ID);
|
||||
|
||||
// Vérifie si l'utilisateur existe
|
||||
if (result.isEmpty()) {
|
||||
return new ResponseEntity("Aucun utilisateur trouvé avec l'ID " + ID, HttpStatusCode.valueOf(404));
|
||||
}
|
||||
|
||||
// Retourne l'utilisateur trouvé
|
||||
return new ResponseEntity(result.get(), HttpStatusCode.valueOf(200));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
35
src/main/java/fr/teamflash/archy/entity/userEntity.java
Normal file
35
src/main/java/fr/teamflash/archy/entity/userEntity.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package fr.teamflash.archy.entity;
|
||||
|
||||
import fr.teamflash.archy.fonction.letter;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
@Data
|
||||
public class userEntity {
|
||||
|
||||
@Column(name = "id")
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@Column(name = "nom")
|
||||
private String nom;
|
||||
|
||||
@Column(name = "prenom")
|
||||
private String prenom;
|
||||
|
||||
@Column(name = "date_naissance")
|
||||
private LocalDate dateNaissance;
|
||||
|
||||
public String getNom() {
|
||||
return nom.toUpperCase();
|
||||
}
|
||||
|
||||
public String getPrenom() {
|
||||
return letter.firstLetterCapitalize(prenom);
|
||||
}
|
||||
}
|
||||
13
src/main/java/fr/teamflash/archy/fonction/letter.java
Normal file
13
src/main/java/fr/teamflash/archy/fonction/letter.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package fr.teamflash.archy.fonction;
|
||||
|
||||
public class letter {
|
||||
|
||||
public static String firstLetterCapitalize(String inputString) {
|
||||
if (inputString == null || inputString.isEmpty()) {
|
||||
return inputString;
|
||||
}
|
||||
|
||||
inputString = inputString.toLowerCase();
|
||||
return inputString.substring(0, 1).toUpperCase() + inputString.substring(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package fr.teamflash.archy.repository;
|
||||
|
||||
import fr.teamflash.archy.entity.userEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface userRepository extends JpaRepository<userEntity, Integer> {
|
||||
|
||||
}
|
||||
|
|
@ -1 +1,5 @@
|
|||
spring.application.name=Archy
|
||||
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://lehub.tf:3306/Lan_ipi_archy
|
||||
spring.datasource.username=Lan_ipi_archy
|
||||
spring.datasource.password=Azerty1234.
|
||||
|
|
@ -4,10 +4,4 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class ArchyApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
class ArchyApplicationTests {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue