Skip to content
Snippets Groups Projects
Commit 2a1a43a3 authored by Hugo Dutoit's avatar Hugo Dutoit
Browse files

finiiii

parent 6140180a
Branches master
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ import java.util.logging.Logger;
*/
public class Main {
// Base URI the Grizzly HTTP server will listen on
public static final String BASE_URI = "http://localhost:8080/api/v1/";
public static final String BASE_URI = "http://localhost:8080/api/v1";
/**
* 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;
}
}
\ No newline at end of file
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
......@@ -3,7 +3,10 @@ package fr.ulille.iut.tva.ressource;
import fr.ulille.iut.tva.service.CalculTva;
import fr.ulille.iut.tva.service.TauxTva;
import jakarta.ws.rs.*;
import java.util.List;
import java.util.ArrayList;
import fr.ulille.iut.tva.dto.InfoTauxDto;
import jakarta.ws.rs.core.MediaType;
/**
* TvaRessource
*/
......@@ -14,6 +17,45 @@ public class TvaRessource {
@GET
@Path("tauxpardefaut")
public double getValeurTauxParDefaut() {
return TauxTva.NORMAL.taux;
return TauxTva.NORMAL.taux;
}
@GET
@Path("valeur/{niveauTva}")
public double getValeurTaux(@PathParam("niveauTva") String niveau)throws NiveauTvaInexistantException{
try {
return TauxTva.valueOf(niveau.toUpperCase()).taux;
}
catch ( Exception ex ) {
throw new NiveauTvaInexistantException();
}
}
@GET
@Path("total/{niveauTva}")
public double getTotal(@PathParam("niveauTva")String niveau,@QueryParam("somme")double somme){
try{
return calculTva.calculerMontant(TauxTva.valueOf(niveau.toUpperCase()),somme);
}
catch ( Exception ex ) {
throw new NiveauTvaInexistantException();
}
}
@GET
@Path("lestaux")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
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<InfoTauxDto> getDetail(@PathParam("taux")String niveau,@QueryParam("somme")double somme) {
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment