initialcommit
This commit is contained in:
parent
549ebab4e3
commit
e537cded10
|
@ -0,0 +1,3 @@
|
|||
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
|
|
@ -0,0 +1,53 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
@Path("/mocktail/barkeeper")
|
||||
public class Barkeeper implements ISearch, ICreate {
|
||||
|
||||
@Inject
|
||||
StorageTransport st;
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/getrecipesall")
|
||||
public ArrayList<Mocktail> getRecipesAll() {
|
||||
ArrayList<Mocktail> mts = st.getRecipesAll();
|
||||
return mts;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create")
|
||||
public String createMocktail(Mocktail m) {
|
||||
//Mocktail newMock = new Mocktail(m.name, m.ingredients, m.recipe);
|
||||
this.st.addMocktail(m);
|
||||
return "klappt";
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update")
|
||||
public String updateMocktail(Mocktail m) {
|
||||
if(this.st.updateMocktail(m)) {
|
||||
return "sgeil";
|
||||
}
|
||||
return "nichsogeil";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
/*import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;*/
|
||||
|
||||
public interface ICreate {
|
||||
|
||||
/*@GET
|
||||
@Produces (MediaType.TEXT_PLAIN)*/
|
||||
public String createMocktail(Mocktail m);
|
||||
//public Mocktail[] showRecipesByName(/*@PathParam */String name);
|
||||
//public Mocktail[] showRecipesById(int id);
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;*/
|
||||
|
||||
public interface ISearch {
|
||||
|
||||
/*@GET
|
||||
@Produces (MediaType.TEXT_PLAIN)*/
|
||||
public ArrayList<Mocktail> getRecipesAll();
|
||||
//public Mocktail[] showRecipesByName(/*@PathParam */String name);
|
||||
//public Mocktail[] showRecipesById(int id);
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
public class Mocktail {
|
||||
public long id;
|
||||
public String name;
|
||||
public String ingredients;
|
||||
public String recipe;
|
||||
|
||||
public Mocktail() {
|
||||
|
||||
}
|
||||
|
||||
public Mocktail(long id, String name, String ingredients, String recipe) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.ingredients = ingredients;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
public long getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(long id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getIngredients(){
|
||||
return this.ingredients;
|
||||
}
|
||||
|
||||
public void setIngredients(String ingredients){
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
public String getRecipe(){
|
||||
return this.recipe;
|
||||
}
|
||||
|
||||
public void setRecipe(String recipe){
|
||||
this.recipe = recipe;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//import javax.ws.rs.Path;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
//@Path("/mocktail/storage")
|
||||
public class StorageTransport {
|
||||
|
||||
//private Mocktail[] mocktails;
|
||||
private ArrayList<Mocktail> mocktails;
|
||||
|
||||
public StorageTransport() {
|
||||
/*this.mocktails = new Mocktail[5];
|
||||
this.mocktails[0] = new Mocktail("caipi", "keineahnung", "ruehren");
|
||||
this.mocktails[1] = new Mocktail("caipi2", "keineahnung", "ruehren");
|
||||
this.mocktails[2] = new Mocktail("caipi3", "keineahnung", "ruehren");
|
||||
this.mocktails[3] = new Mocktail("caipi4", "keineahnung", "ruehren");
|
||||
this.mocktails[4] = new Mocktail("caipi5", "keineahnung", "ruehren");*/
|
||||
this.mocktails = new ArrayList<Mocktail>();
|
||||
this.mocktails.add(new Mocktail(0, "caipi", "keineahnung", "ruehren"));
|
||||
this.mocktails.add(new Mocktail(1, "caipi2", "keineahnung", "ruehren"));
|
||||
this.mocktails.add(new Mocktail(2, "caipi3", "keineahnung", "ruehren"));
|
||||
this.mocktails.add(new Mocktail(3, "caipi4", "keineahnung", "ruehren"));
|
||||
this.mocktails.add(new Mocktail(4, "caipi5", "keineahnung", "ruehren"));
|
||||
}
|
||||
|
||||
public ArrayList<Mocktail> getRecipesAll() {
|
||||
return this.mocktails;
|
||||
}
|
||||
|
||||
public boolean addMocktail(Mocktail m) {
|
||||
if(this.mocktails.add(m)){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateMocktail(Mocktail m) {
|
||||
int index = -1;
|
||||
int i = 0;
|
||||
if(this.mocktails.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
while(i < this.mocktails.size()) {
|
||||
if(this.mocktails.get(i).getId() == m.getId()){
|
||||
index = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (index < 0){
|
||||
return false;
|
||||
}
|
||||
this.mocktails.get(index).setName(m.getName());
|
||||
this.mocktails.get(index).setIngredients(m.getIngredients());
|
||||
this.mocktails.get(index).setRecipe(m.getRecipe());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue