Skip to content
Snippets Groups Projects
Commit 55de4ae8 authored by Quentin Barlet's avatar Quentin Barlet :spades:
Browse files

Exercice 01 Done

parent 54f870ad
No related branches found
No related tags found
No related merge requests found
Showing
with 261 additions and 63 deletions
.gitignore 100644 → 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
meta {
name: GET All Student By Group
type: http
seq: 3
}
get {
url: localhost:8080/etudiant/select?groupe=S
body: none
auth: none
}
query {
groupe: S
}
meta {
name: GET All Student
type: http
seq: 1
}
get {
url: localhost:8080/etudiant
body: none
auth: none
}
meta {
name: GET One Student
type: http
seq: 2
}
get {
url: localhost:8080/etudiant/2
body: none
auth: none
}
meta {
name: POST One Student
type: http
seq: 4
}
post {
url: localhost:8080/etudiant
body: json
auth: none
}
body:json {
{
"id": 10,
"prenom": "Bruce",
"nom": "Banner",
"age": 100,
"groupe": "S"
}
}
{
"version": "1",
"name": "R5.09 - TP508",
"type": "collection",
"presets": {
"requestType": "http",
"requestUrl": "localhost:8080"
}
}
\ No newline at end of file
mvnw.cmd 100644 → 100755
File mode changed from 100644 to 100755
pom.xml 100644 → 100755
......@@ -47,6 +47,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
......
package fr.but3.tp508;
import java.util.List;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@RestController
@RequestMapping(value = "etudiant", produces={MediaType.APPLICATION_JSON_VALUE})
public class ControleurEtudiantRest {
@Autowired
private EtudiantRepository etudiantRepository;
@GetMapping
public List<Etudiant> getAllStudent() {
return (List<Etudiant>) this.etudiantRepository.findAll();
}
@PostMapping
public Etudiant saveStudent(@RequestBody Etudiant student) {
Etudiant query_result = this.etudiantRepository.save(student);
return query_result;
}
@GetMapping(value = "/{id}")
ResponseEntity<Etudiant> getOneStudent(@PathVariable int id) {
Optional<Etudiant> query_result = this.etudiantRepository.findById(id);
if(query_result.isPresent()) return ResponseEntity.ok(query_result.get());
return ResponseEntity.notFound().build();
}
@GetMapping(value = "/select")
List<Etudiant> select(@RequestParam String groupe) {
List<Etudiant> students = new ArrayList<>();
this.etudiantRepository.findAllByGroupe(groupe).forEach(students::add);
return students;
}
}
File mode changed from 100644 to 100755
package fr.but3.tp508;
import lombok.Data;
import lombok.ToString;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.GeneratedValue;
@Entity
@ToString
@Data
public class Etudiant {
@GeneratedValue
@Id
int id;
String prenom;
String nom;
int age;
String groupe;
}
package fr.but3.tp508;
import java.util.ArrayList;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface EtudiantRepository extends CrudRepository<Etudiant, Integer> {
public List<Etudiant> findAllByGroupe(String groupe);
}
server.servlet.contextPath=/
spring.datasource.url=jdbc:h2:mem:tp508
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=spring
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.jpa.defer-datasource-initialization=true
logging.level.org.hibernate.SQL=DEBUG
server.error.include-stacktrace=never
insert into etudiant(id, prenom, nom, age, groupe) values (1, 'Albert','Einstein', 52, 'S');
insert into etudiant(id, prenom, nom, age, groupe) values (2, 'John','Wick', 24, 'J');
drop table if exists etudiant;
create table etudiant (
id int not null,
prenom varchar(255) not null,
nom varchar(255) not null,
age int not null,
groupe varchar(1) not null
);
<html>
<head>
</head>
<body>
<h1>Hello World !</h1>
</body>
</html>
File mode changed from 100644 to 100755
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment