Skip to content
Snippets Groups Projects
Commit 7bcb1fd9 authored by remy.piazza.etu's avatar remy.piazza.etu
Browse files

Sauvegarde

parent 1a1387e1
No related branches found
No related tags found
No related merge requests found
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version> <version>3.8.1</version>
<inherited>true</inherited> <inherited>true</inherited>
<configuration> <configuration>
<release>11</release> <release>11</release>
......
...@@ -16,7 +16,7 @@ import java.util.logging.Logger; ...@@ -16,7 +16,7 @@ import java.util.logging.Logger;
*/ */
public class Main { public class Main {
// Base URI the Grizzly HTTP server will listen on // Base URI the Grizzly HTTP server will listen on
public static final String BASE_URI = "http://localhost:8080/myapp/"; public static final String BASE_URI = "http://localhost:8080/api/v1/";
/** /**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application. * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
......
package fr.ulille.iut.tva.dto;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class InfoTauxDto {
private String label;
private double taux;
public InfoTauxDto() {}
public InfoTauxDto(String label, double taux) {
this.label = label;
this.taux = taux;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public double getTaux() {
return taux;
}
public void setTaux(double taux) {
this.taux = taux;
}
}
package fr.ulille.iut.tva.ressource;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
public class NiveauTvaInexistantException extends WebApplicationException {
private static final long serialVersionUID = 939875418210403804L;
public NiveauTvaInexistantException() {
super(Response.status(Response.Status.NOT_ACCEPTABLE).entity("Niveau de TVA inexistant").build());
}
}
\ No newline at end of file
package fr.ulille.iut.tva.ressource; package fr.ulille.iut.tva.ressource;
import java.util.ArrayList;
import java.util.List;
import fr.ulille.iut.tva.dto.InfoTauxDto;
import fr.ulille.iut.tva.service.CalculTva; import fr.ulille.iut.tva.service.CalculTva;
import fr.ulille.iut.tva.service.TauxTva; import fr.ulille.iut.tva.service.TauxTva;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
/** /**
* TvaRessource * TvaRessource
*/ */
@Path("tva")
public class TvaRessource { public class TvaRessource {
private CalculTva calculTva = new CalculTva(); private CalculTva calculTva = new CalculTva();
@GET
@Path("tauxpardefaut")
public double getValeurTauxParDefaut() {
try {
return TauxTva.NORMAL.taux;
} catch (Exception e) {
throw new NiveauTvaInexistantException();
}
}
@GET
@Path("valeur/{niveauTva}")
public double getValeurTaux(@PathParam("niveauTva") String niveau) {
try {
return TauxTva.valueOf(niveau.toUpperCase()).taux;
} catch (Exception e) {
throw new NiveauTvaInexistantException();
}
}
@GET
@Path("/{montantTotal}")
public double getMontantTotal(@PathParam("montantTotal") String niveau, @QueryParam("somme") int somme) {
return (new CalculTva()).calculerMontant(TauxTva.valueOf(niveau.toUpperCase()) , somme);
}
@GET
@Path("lestaux")
public List<InfoTauxDto> getInfoTaux() {
ArrayList<InfoTauxDto> result = new ArrayList<InfoTauxDto>();
for ( TauxTva t : TauxTva.values() ) {
result.add(new InfoTauxDto(t.name(), t.taux));
}
return result;
}
@GET
@Path("details/{taux}")
public List<String> getDetail(@PathParam("taux") String niveau, @QueryParam("somme") int somme) {
List<String> res = new ArrayList<String>();
double montantTotal = (new CalculTva()).calculerMontant(TauxTva.valueOf(niveau.toUpperCase()) , somme);
res.add("Montant total: " + montantTotal ) ;
double montantTVA = somme * (TauxTva.valueOf(niveau.toUpperCase()).taux / 100);
res.add("Montant TVA: " + montantTVA );
res.add("Somme: " + somme);
res.add("tauxLabel: " + TauxTva.valueOf(niveau.toUpperCase()) );
res.add("tauxValue: " + TauxTva.valueOf(niveau.toUpperCase()).taux );
return res;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment