Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public IAdressRepository addresses() {
try {
return new AddressRepository(connection, new AdressMapper(), uow);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/library/examples/AddressRepositoryExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public static void execute(Connection connection, IDatabaseCatalog catalog){
catalog.addresses().add(adress);
catalog.addresses().add(adress);
catalog.addresses().add(adress);

System.out.println("Count: "+ catalog.addresses().count());
System.out.println("last id: "+ catalog.addresses().lastId());

List<Address> addressWithCity = catalog.addresses().withCity("Gdansk");
List<Address> addressWithPostal = catalog.addresses().withPostal("80-041");
//List<Address> addressWithCity = catalog.addresses().withCity("Gdansk");
//List<Address> addressWithPostal = catalog.addresses().withPostal("80-041");

List<Address> adresses = catalog.addresses().getPage(1, 2);

Expand Down
48 changes: 47 additions & 1 deletion src/main/java/library/web/rest/AdressesResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
Expand All @@ -13,16 +17,18 @@
import javax.ejb.Stateless;

import library.dao.repositories.IAdressRepository;
import library.dao.repositories.IDatabaseCatalog;
import library.dao.repositories.impl.HsqlCatalogFactory;
import library.domain.Address;

@Path("/adresses")
@Stateless
public class AdressesResources {
IAdressRepository _addresses;

IDatabaseCatalog _library;
public AdressesResources() {
_addresses = new HsqlCatalogFactory().library().addresses();
_library = new HsqlCatalogFactory().library();
}


Expand All @@ -44,4 +50,44 @@ public Response get(@PathParam("id") int id){
return Response.status(404).build();
return Response.ok(address).build();
}

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addAddress(Address address){
_addresses.add(address);
_library.saveChanges();
return Response.ok().build();
}

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{id}")
public Response updateAddress(@PathParam("id") int id ,Address address){

Address a = _addresses.get(id);
if(a ==null)
return Response.status(404).build();
address.setId(id);
_addresses.update(address);
_library.saveChanges();
return Response.ok().build();
}

@DELETE
@Path("/{id}")
public Response deleteAddress(@PathParam("id") int id){
Address a = _addresses.get(id);
if(a==null)
return Response.status(404).build();
_addresses.delete(a);
_library.saveChanges();
return Response.noContent().build();
}

@GET
@Path("/status")
@Produces(MediaType.TEXT_HTML)
public String test(){
return "OK";
}
}