Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions TestsPostman/Mcommerce-partie1-test.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"info": {
"_postman_id": "2c24980d-5517-42f2-a05e-a8ca8acc44cf",
"name": "Mcommerce-partie1-test",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "http://localhost:9090/Produits/trieParOrdreAphabetique",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJKZWFuIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiaWF0IjoxNTY5OTIyNzI4LCJleHAiOjE1Njk5MzEzNjh9.0W5ry_imvQfhvbS_i6FFvF2c5QpQJ_Cye4GcrdkGO6TKJE9Q347pJOKXK2xBRRJ040_WnujeHAc16d-vUKfWMg",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t \n\t\"nom\" : \"Charger\" , \n\t\"prix\" : 0,\n\t\"prixAchat\" : 45\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:9090/Produits/trieParOrdreAphabetique",
"protocol": "http",
"host": [
"localhost"
],
"port": "9090",
"path": [
"Produits",
"trieParOrdreAphabetique"
]
}
},
"response": []
},
{
"name": "http://localhost:9090/AdminProduits",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:9090/AdminProduits",
"protocol": "http",
"host": [
"localhost"
],
"port": "9090",
"path": [
"AdminProduits"
]
}
},
"response": []
},
{
"name": "http://localhost:9090/Produits",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"id\" : 4,\n\t\"nom\" : \"Cahier\" ,\n\t\"prix\" : 0,\n\t\"prixAchat\" : 58\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:9090/Produits",
"protocol": "http",
"host": [
"localhost"
],
"port": "9090",
"path": [
"Produits"
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
}
2 changes: 2 additions & 0 deletions src/main/java/com/ecommerce/microcommerce/dao/ProductDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface ProductDao extends JpaRepository<Product, Integer> {

@Query("SELECT id, nom, prix FROM Product p WHERE p.prix > :prixLimit")
List<Product> chercherUnProduitCher(@Param("prixLimit") int prix);

List<Product> findAllByOrderByNom();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Product {
@Length(min=3, max=20, message = "Nom trop long ou trop court. Et oui messages sont plus stylés que ceux de Spring")
private String nom;

@Min(value = 1)
// @Min(value = 1)
private int prix;

//information que nous ne souhaitons pas exposer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ecommerce.microcommerce.dao.ProductDao;
import com.ecommerce.microcommerce.model.Product;
import com.ecommerce.microcommerce.web.exceptions.ProduitGratuitException;
import com.ecommerce.microcommerce.web.exceptions.ProduitIntrouvableException;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
Expand All @@ -16,7 +17,9 @@

import javax.validation.Valid;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Api( description="API pour es opérations CRUD sur les produits.")
Expand Down Expand Up @@ -69,6 +72,7 @@ public Product afficherUnProduit(@PathVariable int id) {

public ResponseEntity<Void> ajouterProduit(@Valid @RequestBody Product product) {

if(product.getPrix()==0) throw new ProduitGratuitException("Le prix du produit ne doit pas être nul");
Product productAdded = productDao.save(product);

if (productAdded == null)
Expand Down Expand Up @@ -104,5 +108,18 @@ public List<Product> testeDeRequetes(@PathVariable int prix) {
}


@GetMapping("/Produits/trieParOrdreAphabetique")
public List<Product> trierProduitsParOrdreAlphabetique(){
return productDao.findAllByOrderByNom();
}

@GetMapping("/AdminProduits")
public Map<String,Integer> calculerMargeProduit(){
Map<String,Integer> margeProduit = new HashMap<>();
productDao.findAll().forEach(product->{
margeProduit.put(product.toString() , product.getPrix()-product.getPrixAchat());
});
return margeProduit;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ecommerce.microcommerce.web.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
public class ProduitGratuitException extends RuntimeException {
public ProduitGratuitException(String message){
super(message);
}
}