package lab6.rest.service; import lab6.rest.pojo.CommentPOJO; import lab6.rest.pojo.EntryPOJO; import javax.inject.Singleton; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.ArrayList; import java.util.List; @Singleton @Path("/blog") public class Blog { public List entryList = new ArrayList<>(); //Dodanie wpisu @POST @Path("/entry") @Produces(MediaType.APPLICATION_JSON) public void addEntry(EntryPOJO json) throws Exception{ entryList.add(new EntryPOJO(json.getId(),json.getDate(),json.getSubject(),json.getContent())); } //wyswietlanie wszystkich wpisow @GET @Path("/entry") @Produces(MediaType.APPLICATION_JSON) public List showEntry() throws Exception{ return entryList; } //wyswietlanie wpisu o danym id @GET @Path("/entry/{id}") @Produces(MediaType.APPLICATION_JSON) public EntryPOJO showEntryById(@PathParam("id") String id) throws Exception{ if(entryList.isEmpty()){ return null; } else{ for(EntryPOJO entry: entryList){ if(entry.getId().equals(id)){ return entry; } } } return null; } //edycja wpisu o danym id @PUT @Path("/entry/{id}") @Consumes(MediaType.APPLICATION_JSON) public void editEntryById(@PathParam("id") String id, EntryPOJO json) throws Exception{ for (EntryPOJO entry: entryList){ if(entry.getId().equals(id)){ entry.setId(json.getId()); entry.setDate(json.getDate()); entry.setSubject(json.getSubject()); entry.setContent(json.getContent()); } } } //usuwanie wpisu po id @DELETE @Path("/entry/{id}") public void deleteEntryById(@PathParam("id") String id) throws Exception{ int index = -1; for(int i=0; i showComment(@PathParam("id") String id) throws Exception{ int index = -1; for(int i=0; i