Search in sources :

Example 1 with ProductCreateDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductCreateDTO in project 2021-msk-food-delivery by netcracker-edu.

the class ProductUtils method createProductCreateDTO.

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

Example 2 with ProductCreateDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductCreateDTO in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceImpl method createProduct.

@Override
public isCreatedDTO createProduct(ProductCreateDTO newProduct) {
    Product product = productMapper.mapToEntity(newProduct);
    product = productRepo.save(product);
    isCreatedDTO createdDTO = new isCreatedDTO();
    createdDTO.setId(product.getId());
    return createdDTO;
}
Also used : Product(com.ncedu.fooddelivery.api.v1.entities.Product) com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO(com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)

Example 3 with ProductCreateDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductCreateDTO 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)

Aggregations

com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)2 ProductCreateDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductCreateDTO)1 Product (com.ncedu.fooddelivery.api.v1.entities.Product)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1