Commit 4cd6cb08 by Patryk Czarnik

Pierwsze zapytania Jesrsey sklep

parent 340dfca6
package sklep.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import sklep.model.Customer;
public interface CustomerRepository extends JpaRepository<Customer, String> {
}
package sklep.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import sklep.model.Order;
public interface OrderRepository extends JpaRepository<Order, Integer> {
}
package sklep.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import sklep.model.Product;
public interface ProductRepository extends JpaRepository<Product, Integer> {
}
......@@ -14,6 +14,7 @@ public class JerseyConfig extends ResourceConfig {
register(Hello.class);
register(DataCzas.class);
register(Kalkulator.class);
register(RProducts.class);
}
}
package sklep.rest;
import jakarta.ws.rs.*;
import org.springframework.beans.factory.annotation.Autowired;
import sklep.model.Product;
import sklep.repository.ProductRepository;
import java.util.List;
@Path("/products")
@Produces({"application/json"})
public class RProducts {
@Autowired
private ProductRepository productRepository;
@GET
public List<Product> getProducts() {
return productRepository.findAll();
}
@GET
@Path("{id}")
public Product getProduct(@PathParam("id") int id) {
return productRepository.findById(id).orElseThrow(() -> new WebApplicationException(404));
}
}
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