Search in sources :

Example 36 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductUtils method createProductUpdateDTO.

public static ProductUpdateDTO createProductUpdateDTO(Product p) {
    ProductUpdateDTO productDTO = new ProductUpdateDTO();
    productDTO.setDescription(p.getDescription());
    productDTO.setPrice(p.getPrice());
    productDTO.setName(p.getName());
    productDTO.setWeight(p.getWeight());
    productDTO.setExpirationDays(p.getExpirationDays());
    return productDTO;
}
Also used : ProductUpdateDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductUpdateDTO)

Example 37 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductController method createProduct.

@PostMapping("/api/v1/product")
@PreAuthorize("hasAuthority('ADMIN')")
public isCreatedDTO createProduct(@Valid @RequestBody ProductCreateDTO newProduct) {
    isCreatedDTO createdDTO = productService.createProduct(newProduct);
    log.debug("Created product with id: " + createdDTO.getId());
    return createdDTO;
}
Also used : com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO(com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 38 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project C-DAC-Notes by shreeshailaya.

the class CategoryCriteria method main.

public static void main(String[] args) {
    StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build();
    Metadata metadata = new MetadataSources(registry).getMetadataBuilder().build();
    SessionFactory sf = metadata.getSessionFactoryBuilder().build();
    System.out.println("session factory created");
    Session session = sf.openSession();
    // create criteria builder
    CriteriaBuilder builder = session.getCriteriaBuilder();
    // create criteria query
    CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
    // specify root ie from clause
    Root<Product> from = query.from(Product.class);
    // specify select clause, where clause
    query.multiselect(from.get("description"), from.get("name")).where(builder.equal(from.get("id"), 1));
    // create query from criteria provided
    Query q = session.createQuery(query);
    List<Object[]> ques = q.getResultList();
    for (Object[] qu : ques) System.out.println(qu[0] + " : ");
}
Also used : SessionFactory(org.hibernate.SessionFactory) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Product(entities.Product) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session)

Example 39 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project ADS_Senac by Renan-Paiva93.

the class mediaProduto method main.

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    // indicar vetor tipo do vetor com N Elementos
    Product[] vect = new Product[n];
    // for (int i = 0; i < n; i++)
    for (int i = 0; i < vect.length; i++) {
        sc.nextLine();
        String name = sc.nextLine();
        double price = sc.nextDouble();
        // estanciar para novo produto e apontar para os objetos
        vect[i] = new Product(name, price);
    }
    // média dos preços
    double soma = 0;
    for (int i = 0; i < vect.length; i++) {
        soma += vect[i].getPrice();
    }
    // média
    double avg = soma / vect.length;
    System.out.printf("average price = %.2f%n", avg);
}
Also used : Scanner(java.util.Scanner) Product(entities.Product)

Aggregations

Product (com.ncedu.fooddelivery.api.v1.entities.Product)17 Test (org.junit.jupiter.api.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)10 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)9 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)9 Product (entities.Product)9 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)8 SearchProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 Point (com.vividsolutions.jts.geom.Point)5 Pageable (org.springframework.data.domain.Pageable)5 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)3 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)3 PageImpl (org.springframework.data.domain.PageImpl)3 com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)2 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)2 ProductAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.ProductAvailabilityEx)2