Commit af868a09 by Patryk Czarnik

ROrders i poprawki

parent 88cf0058
package sklep.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import sklep.model.Order;
public interface OrderRepository extends JpaRepository<Order, Integer> {
}
......@@ -9,12 +9,12 @@ public class JerseyConfig extends ResourceConfig {
* została wywołana metoda register dla wszystkich "resource classes", które wchodzą w skład aplikacji JAX-RS.
* W wersji Springowej nie ma klasy typu Application.
*/
public JerseyConfig() {
register(Hello.class);
register(DataCzas.class);
register(Kalkulator.class);
// register(RProducts.class);
register(RProducts.class);
register(ROrders.class);
}
}
package sklep.rest;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import sklep.model.Order;
import sklep.repository.OrderRepository;
@Path("/orders")
@Produces("application/json")
@Consumes("application/json")
public class ROrders {
@Autowired
private OrderRepository orderRepository;
@GET
public List<Order> readAll() {
return orderRepository.findAll();
}
@Path("/{id}")
@GET
public Order readOne(@PathParam("id") int id) {
Optional<Order> order = orderRepository.findById(id);
if(order.isPresent()) {
return order.get();
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Nie ma zamówienia o numerze " + id);
}
}
}
......@@ -5,7 +5,6 @@ import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.web.bind.annotation.PutMapping;
import sklep.model.Product;
import sklep.repository.ProductRepository;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment