Skip to content

Commit

Permalink
Create method added to API Rest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ttiki committed Jan 1, 2023
1 parent 4214a28 commit a46433c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fr/pau/univ/series/services/EpisodesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Response addEpisode(final MultivaluedMap<String, String> formParams) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Parent season not found").build();
}
// Suite de la méthode avec statut CREATED si OK, INTERNAL_SERVER_ERROR sinon
// Suite de la méthode avec statut CREATED si OK, INTERNAL_SERVER_ERROR sinon
return Response.status(Response.Status.CREATED)
.entity("Episode created").build();
}
Expand Down
25 changes: 24 additions & 1 deletion src/fr/pau/univ/series/services/SaisonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.pau.univ.series.dao.DaoFactory;
import fr.pau.univ.series.exception.DaoException;
import fr.pau.univ.series.model.Saison;
import fr.pau.univ.series.model.Serie;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
Expand Down Expand Up @@ -125,7 +126,29 @@ public Response readSaisonByEpisode(@jakarta.ws.rs.PathParam("id") int idEpisode
@Path("/add")
@Produces(MediaType.APPLICATION_JSON)
public Response addSaison(final MultivaluedMap<String, String> formParams) {
return null;
if (formParams.get("titre") == null || formParams.get("numero") == null ||
formParams.get("serieId") == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Invalid parameters").build();
} else {
Serie s = null;
try {
s = DaoFactory.getInstance().getSerieDao()
.readSerie(Integer.parseInt(formParams.getFirst("saisonId")));
} catch (final DaoException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build();
} catch (final NumberFormatException e) {
return Response.status(Response.Status.BAD_REQUEST)
.entity("saisonId must be an intger").build();
}
if (s == null) {
return Response.status(Response.Status.NOT_FOUND)
.entity("Parent season not found").build();
}
// Suite de la méthode avec statut CREATED si OK, INTERNAL_SERVER_ERROR sinon
return Response.status(Response.Status.CREATED)
.entity("Season created").build();
}
}

}
1 change: 1 addition & 0 deletions src/fr/pau/univ/series/services/SeriesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public Response readSerieByEpisode(@jakarta.ws.rs.PathParam("id") int idEpisode)
@Path("/add")
@Produces(MediaType.APPLICATION_JSON)
public Response addSerie(final MultivaluedMap<String, String> formParams) {
//TODO: à implémenter plus tard.
return null;
}

Expand Down

0 comments on commit a46433c

Please sign in to comment.