Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test pull request #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
110 changes: 110 additions & 0 deletions TestsPostman/Tests du projet Mcommerce-Partie1.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"id": "e20a526c-4750-ba3f-c01f-6b7f570c440c",
"name": "Tests du projet Mcommerce-Partie1",
"description": "",
"order": [
"7190f4c8-a0e5-cc30-19dc-96951ad828eb",
"d2fbe76f-dfe2-50b2-fe05-fd7ed051e14e",
"2ace212f-a446-0eac-b384-f665e6a4de22"
],
"folders": [],
"folders_order": [],
"timestamp": 1544620873383,
"owner": "4655740",
"public": false,
"requests": [
{
"id": "2ace212f-a446-0eac-b384-f665e6a4de22",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "http://localhost:9090/Produits",
"queryParams": [],
"pathVariables": {},
"pathVariableData": [],
"preRequestScript": null,
"method": "POST",
"collectionId": "e20a526c-4750-ba3f-c01f-6b7f570c440c",
"data": [],
"dataMode": "raw",
"name": "http://localhost:9090/Produits",
"description": "",
"descriptionFormat": "html",
"time": 1544621611119,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"rawModeData": "{\n\t\"id\":8,\n\t\"nom\":\"lave linge\",\n\t\"prix\":0\n}"
},
{
"id": "7190f4c8-a0e5-cc30-19dc-96951ad828eb",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "http://localhost:9090/AdminProduits",
"queryParams": [],
"pathVariables": {},
"pathVariableData": [],
"preRequestScript": null,
"method": "GET",
"collectionId": "e20a526c-4750-ba3f-c01f-6b7f570c440c",
"data": [],
"dataMode": "raw",
"name": "http://localhost:9090/AdminProduits",
"description": "",
"descriptionFormat": "html",
"time": 1544621116702,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"rawModeData": "{\n\t\"id\":4,\n\t\"nom\":\"lave linge\",\n\t\"prix\":500\n}"
},
{
"id": "d2fbe76f-dfe2-50b2-fe05-fd7ed051e14e",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "http://localhost:9090/Produits/trier",
"queryParams": [],
"pathVariables": {},
"pathVariableData": [],
"preRequestScript": null,
"method": "GET",
"collectionId": "e20a526c-4750-ba3f-c01f-6b7f570c440c",
"data": [],
"dataMode": "raw",
"name": "http://localhost:9090/Produits/trier",
"description": "",
"descriptionFormat": "html",
"time": 1544621180089,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"rawModeData": "{\n\t\"id\":4,\n\t\"nom\":\"lave linge\",\n\t\"prix\":500\n}"
}
]
}
Binary file added TestsPostman/testCalculeMarge.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TestsPostman/testPrix.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TestsPostman/testTrieProduits.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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> findAllByOrderByNomAsc();
}
34 changes: 34 additions & 0 deletions src/main/java/com/ecommerce/microcommerce/model/MargeProduct.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ecommerce.microcommerce.model;

public class MargeProduct {

private Product produit;
private int marge;

public MargeProduct(){
super();
}

public MargeProduct(Product produit, int marge){
this.produit = produit;
this.marge = marge;
}

public Product getProduit() {
return produit;
}

public void setProduit(Product produit) {
this.produit = produit;
}

public int getMarge() {
return marge;
}

public void setMarge(int marge) {
this.marge = marge;
}


}
5 changes: 4 additions & 1 deletion src/main/java/com/ecommerce/microcommerce/model/Product.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ecommerce.microcommerce.model;

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnore;

import org.hibernate.validator.constraints.Length;

import javax.persistence.Entity;
Expand All @@ -19,10 +21,11 @@ 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
@JsonIgnore
private int prixAchat;

//constructeur par défaut
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.ecommerce.microcommerce.web.controller;

import com.ecommerce.microcommerce.dao.ProductDao;
import com.ecommerce.microcommerce.model.MargeProduct;
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;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import javax.validation.Valid;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;


Expand Down Expand Up @@ -69,6 +75,10 @@ public Product afficherUnProduit(@PathVariable int id) {

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

if(product.getPrix() == 0){
throw new ProduitGratuitException("Le produit ne doit pas être gratuit");
}

Product productAdded = productDao.save(product);

if (productAdded == null)
Expand Down Expand Up @@ -103,6 +113,23 @@ public List<Product> testeDeRequetes(@PathVariable int prix) {
return productDao.chercherUnProduitCher(400);
}

@GetMapping(value="/AdminProduits")
public List<MargeProduct> calculerMargeProduit() {

List<MargeProduct> margeProduits = new ArrayList<MargeProduct>();

List<Product> produits = productDao.findAll();

for(Product produit : produits) {
margeProduits.add(new MargeProduct(produit, produit.getPrix()-produit.getPrixAchat()));
}

return margeProduits;
}


@GetMapping(value="/Produits/trier")
public List<Product> trierProduitsParOrdreAlphabetique() {

return productDao.findAllByOrderByNomAsc();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ecommerce.microcommerce.web.exceptions;

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

@ResponseStatus(HttpStatus.PRECONDITION_FAILED)
public class ProduitGratuitException extends RuntimeException {

public ProduitGratuitException(String s) {
super(s);
}

}