Premier commit
This commit is contained in:
commit
30dc8cbce7
43 changed files with 1979 additions and 0 deletions
|
|
@ -0,0 +1,12 @@
|
|||
package com.mpaiement;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MpaiementApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MpaiementApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.mpaiement.dao;
|
||||
|
||||
import com.mpaiement.model.Paiement;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PaiementDao extends JpaRepository<Paiement, Integer>{
|
||||
|
||||
Paiement findByidCommande(int idCommande);
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package com.mpaiement.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Paiement {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Column(unique = true)
|
||||
private Integer idCommande;
|
||||
|
||||
private Integer montant;
|
||||
|
||||
private Long numeroCarte;
|
||||
|
||||
public Paiement() {
|
||||
}
|
||||
|
||||
public Paiement(int id, Integer idCommande, Integer montant, Long numeroCarte) {
|
||||
this.id = id;
|
||||
this.idCommande = idCommande;
|
||||
this.montant = montant;
|
||||
this.numeroCarte = numeroCarte;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getIdCommande() {
|
||||
return idCommande;
|
||||
}
|
||||
|
||||
public void setIdCommande(Integer idCommande) {
|
||||
this.idCommande = idCommande;
|
||||
}
|
||||
|
||||
public Integer getMontant() {
|
||||
return montant;
|
||||
}
|
||||
|
||||
public void setMontant(Integer montant) {
|
||||
this.montant = montant;
|
||||
}
|
||||
|
||||
public Long getNumeroCarte() {
|
||||
return numeroCarte;
|
||||
}
|
||||
|
||||
public void setNumeroCarte(Long numeroCarte) {
|
||||
this.numeroCarte = numeroCarte;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Paiement{" +
|
||||
"id=" + id +
|
||||
", idCommande=" + idCommande +
|
||||
", montant=" + montant +
|
||||
", numeroCarte=" + numeroCarte +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.mpaiement.web.controller;
|
||||
|
||||
import com.mpaiement.dao.PaiementDao;
|
||||
import com.mpaiement.model.Paiement;
|
||||
import com.mpaiement.web.exceptions.PaiementExistantException;
|
||||
import com.mpaiement.web.exceptions.PaiementImpossibleException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
public class PaiementController {
|
||||
|
||||
@Autowired
|
||||
PaiementDao paiementDao;
|
||||
|
||||
@PostMapping(value = "/paiement")
|
||||
public ResponseEntity<Paiement> payerUneCommande(@RequestBody Paiement paiement){
|
||||
|
||||
|
||||
//Vérifions s'il y a déjà un paiement enregistré pour cette commande
|
||||
Paiement paiementExistant = paiementDao.findByidCommande(paiement.getIdCommande());
|
||||
if(paiementExistant != null) throw new PaiementExistantException("Cette commande est déjà payée");
|
||||
|
||||
//Enregistrer le paiement
|
||||
Paiement nouveauPaiement = paiementDao.save(paiement);
|
||||
|
||||
|
||||
if(nouveauPaiement == null) throw new PaiementImpossibleException("Erreur, impossible d'établir le paiement, réessayez plus tard");
|
||||
|
||||
|
||||
|
||||
//TODO Nous allons appeler le Microservice Commandes ici pour lui signifier que le paiement est accepté
|
||||
|
||||
return new ResponseEntity<Paiement>(nouveauPaiement, HttpStatus.CREATED);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.mpaiement.web.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.CONFLICT)
|
||||
public class PaiementExistantException extends RuntimeException {
|
||||
|
||||
public PaiementExistantException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.mpaiement.web.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public class PaiementImpossibleException extends RuntimeException {
|
||||
|
||||
|
||||
public PaiementImpossibleException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
server.port 9003
|
||||
|
||||
#Configurations H2
|
||||
spring.jpa.show-sql=true
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
#défini l'encodage pour data.sql
|
||||
spring.datasource.sql-script-encoding=UTF-8
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.mpaiement;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class MpaiementApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue