Skip to content
Snippets Groups Projects
Commit a8acd8da authored by Thomas Truffin's avatar Thomas Truffin
Browse files

tp3 terminée

parent 1a1387e1
No related branches found
No related tags found
No related merge requests found
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="jersey-tva" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -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/myapp/";
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 fr.ulille.iut.tva.service.TauxTva;
public class DetailDTO {
private double montantTotal;
private double montantTva;
private double somme;
private String tauxLabel;
private double tauxValue;
public DetailDTO(){}
public DetailDTO(double somme , String tauxLabel ){
getTaux(tauxLabel);
getMontant(somme);
}
public double getMontantTotal() {
return montantTotal;
}
public void setMontantTotal(double montantTotal) {
this.montantTotal = montantTotal;
}
public double getMontantTva() {
return montantTva;
}
public void setMontantTva(double montantTva) {
this.montantTva = montantTva;
}
public double getSomme() {
return somme;
}
public void setSomme(double somme) {
this.somme = somme;
}
public String getTauxLabel() {
return tauxLabel;
}
public void setTauxLabel(String tauxLabel) {
this.tauxLabel = tauxLabel;
}
public double getTauxValue() {
return tauxValue;
}
public void setTauxValue(double tauxValue) {
this.tauxValue = tauxValue;
}
private void getMontant(double somme){
this.somme=somme;
this.montantTva=(this.tauxValue / 100 ) * somme;
this.montantTotal=somme + montantTva;
}
private void getTaux(String tauxlabel) {
TauxTva taux=TauxTva.valueOf(tauxlabel.toUpperCase());
this.tauxLabel=taux.name();
this.tauxValue=taux.taux;
}
}
package fr.ulille.iut.tva.dto;
import fr.ulille.iut.tva.service.TauxTva;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
@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 double getTaux(){
return taux;
}
public void setLabel(String label){
this.label=label;
}
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());
}
}
package fr.ulille.iut.tva.ressource;
import fr.ulille.iut.tva.dto.DetailDTO;
import fr.ulille.iut.tva.dto.InfoTauxDto;
import fr.ulille.iut.tva.service.CalculTva;
import fr.ulille.iut.tva.service.TauxTva;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.MediaType;
import java.util.ArrayList;
/**
* TvaRessource
*/
@Path("tva")
public class TvaRessource {
private CalculTva calculTva = new CalculTva();
@GET
@Path("tauxpardefaut")
public double getValeurTauxParDefaut() {
return TauxTva.NORMAL.taux;
}
@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("{niveauTva}")
public double getMontantTotal(@PathParam("niveauTva") String taux , @QueryParam("somme") int somme){
try {
return calculTva.calculerMontant(TauxTva.fromString(taux.toUpperCase()),somme);
}catch (Exception e){
throw new NiveauTvaInexistantException();
}
}
@GET
@Path("lestaux")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ArrayList<InfoTauxDto> getInfoTaux(){
ArrayList<InfoTauxDto> result=new ArrayList<>();
for(TauxTva t:TauxTva.values()){
result.add(new InfoTauxDto(t.name() , t.taux));
}
return result;
}
@GET
@Path("detail/{taux}")
public DetailDTO getDetail(@PathParam("taux") String taux , @QueryParam("somme") double somme){
return new DetailDTO(somme,taux);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment