Delete eingefügt

This commit is contained in:
Jockel 2020-11-02 16:45:04 +01:00
parent e537cded10
commit e1c5ca5be0
7 changed files with 38 additions and 19 deletions

View File

@ -1,3 +1,4 @@
curl -w "\n" http://localhost:8080/mocktail/barkeeper/getrecipesall
curl --header "Content-Type: application/json" --request POST --data "{\"id\":\"0\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/barkeeper/create
curl --header "Content-Type: application/json" --request PUT --data "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/barkeeper/update
curl --header "Content-Type: application/json" --request PUT --data "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/barkeeper/update
curl --header "Content-Type: application/json" --request DELETE --data "{\"id\":\"4\"}" http://localhost:8080/mocktail/barkeeper/delete

View File

@ -15,7 +15,7 @@ import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.annotations.jaxrs.PathParam;
@Path("/mocktail/barkeeper")
public class Barkeeper implements ISearch, ICreate {
public class Barkeeper implements ISearch, ICreate, IDelete{
@Inject
StorageTransport st;
@ -49,5 +49,16 @@ public class Barkeeper implements ISearch, ICreate {
return "nichsogeil";
}
@DELETE
@Consumes (MediaType.APPLICATION_JSON)
@Path("/delete")
public String deleteMocktail(Mocktail mocktail) {
System.out.println("index: "+ mocktail.id);
if(this.st.deleteMocktail(mocktail.id)){
return "objekt wurde entfernt";
}
return "Objekt konnte nicht entfernt werden...";
}
}

View File

@ -0,0 +1,9 @@
package de.hsos.swa.ma.api.al;
/**
* IDelete
*/
public interface IDelete {
public String deleteMocktail(Mocktail mocktail);
}

View File

@ -48,4 +48,8 @@ public class Mocktail {
public void setRecipe(String recipe){
this.recipe = recipe;
}
public String toString() {
return "ID: " + this.id + "\nName: " + this.name + "\nZutaten: " + this.ingredients + "\nRezept: " + this.recipe;
}
}

View File

@ -61,4 +61,9 @@ public class StorageTransport {
return true;
}
public boolean deleteMocktail(long index) {
System.out.println("Test... :D");
return this.mocktails.remove(this.mocktails.get((int)index));
}
}

View File

@ -1,16 +0,0 @@
package org.acme.resteasy;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/resteasy/hello")
public class ExampleResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}

View File

@ -1,12 +1,17 @@
package org.acme.resteasy;
import io.quarkus.test.junit.QuarkusTest;
import jdk.internal.jline.internal.TestAccessible;
import org.junit.jupiter.api.Test;
import de.hsos.swa.ma.api.al.Mocktail;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
@QuarkusTest
@Path("/mocktail/barkeeper")
public class ExampleResourceTest {
@Test
@ -16,6 +21,6 @@ public class ExampleResourceTest {
.then()
.statusCode(200)
.body(is("hello"));
}
}
}