Index: src/main/java/com/example/salonbella/service/ProductService.java
===================================================================
--- src/main/java/com/example/salonbella/service/ProductService.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
+++ src/main/java/com/example/salonbella/service/ProductService.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
@@ -0,0 +1,68 @@
+package com.example.salonbella.service;
+
+import com.example.salonbella.entity.ProductEntity;
+import com.example.salonbella.repository.ProductRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.transaction.Transactional;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Base64;
+import java.util.List;
+import java.util.Optional;
+import java.util.zip.DataFormatException;
+import java.util.zip.Inflater;
+
+@Service
+public class ProductService {
+
+    private final ProductRepository productRepository;
+
+    @Autowired
+    public ProductService(ProductRepository productRepository) {
+        this.productRepository = productRepository;
+    }
+
+    public void addProduct(String name, String category, String price, String description, MultipartFile multipartFile) throws IOException {
+        ProductEntity productEntity = new ProductEntity();
+        productEntity.setName(name);
+        productEntity.setContent(multipartFile.getBytes());
+        productEntity.setDescription(description);
+        productEntity.setCategory(category);
+        productEntity.setPrice(Double.parseDouble(price));
+        productRepository.save(productEntity);
+    }
+
+    public List<ProductEntity> getProducts() {
+        List<ProductEntity> productEntities = productRepository.findAll();
+        for (ProductEntity p : productEntities) {
+            p.setBase64(Base64.getEncoder().encodeToString(p.getContent()));
+        }
+        return productEntities;
+    }
+
+    public byte[] decompressBytes(byte[] data) {
+        Inflater inflater = new Inflater();
+        inflater.setInput(data);
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
+        byte[] buffer = new byte[1024];
+        try {
+            while (!inflater.finished()) {
+                int count = inflater.inflate(buffer);
+                outputStream.write(buffer, 0, count);
+            }
+            outputStream.close();
+        } catch (IOException ioe) {
+        } catch (DataFormatException e) {
+        }
+        return outputStream.toByteArray();
+    }
+
+    @Transactional
+    public void removeProduct(Long id) {
+        Optional<ProductEntity> product = productRepository.findById(id);
+        product.ifPresent(productRepository::delete);
+    }
+}
Index: src/main/java/com/example/salonbella/service/ShoppingCartService.java
===================================================================
--- src/main/java/com/example/salonbella/service/ShoppingCartService.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
+++ src/main/java/com/example/salonbella/service/ShoppingCartService.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
@@ -0,0 +1,62 @@
+package com.example.salonbella.service;
+
+import com.example.salonbella.controller.cart.ShoppingCart;
+import com.example.salonbella.entity.CartDetailEntity;
+import com.example.salonbella.entity.ProductEntity;
+import com.example.salonbella.repository.ProductRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+
+@Service
+public class ShoppingCartService {
+
+    private ShoppingCart shoppingCart;
+    private ProductRepository productRepository;
+
+    @Autowired
+    public ShoppingCartService(ShoppingCart shoppingCart, ProductRepository productRepository) {
+        this.shoppingCart = shoppingCart;
+        this.productRepository = productRepository;
+    }
+
+    public void addProduct(Long id) {
+        shoppingCart.getCartDetails().add(new CartDetailEntity(id, 1));
+    }
+
+    public ShoppingCart getShoppingCart() {
+        return shoppingCart;
+    }
+
+    public List<ProductEntity> getShoppingCartDetails() {
+        List<ProductEntity> productEntities = new ArrayList<>();
+        List<CartDetailEntity> cartDetailEntities = shoppingCart.getCartDetails();
+        for (CartDetailEntity c : cartDetailEntities) {
+            ProductEntity p = productRepository.findById(c.getId()).get();
+            p.setBase64(Base64.getEncoder().encodeToString(p.getContent()));
+            productEntities.add(p);
+        }
+        return productEntities;
+    }
+
+    public void deleteProductFromCart(Long id) {
+        for (CartDetailEntity c : shoppingCart.getCartDetails()) {
+            if (c.getId() == id) {
+                shoppingCart.getCartDetails().remove(c);
+                break;
+            }
+        }
+    }
+
+    public boolean existInCart(Long id) {
+        for (CartDetailEntity c : shoppingCart.getCartDetails()) {
+            if (c.getId() == id) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
Index: src/main/java/com/example/salonbella/service/order/OrderDetail.java
===================================================================
--- src/main/java/com/example/salonbella/service/order/OrderDetail.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
+++ src/main/java/com/example/salonbella/service/order/OrderDetail.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
@@ -0,0 +1,27 @@
+package com.example.salonbella.service.order;
+
+public class OrderDetail {
+    private String name;
+    private int quantity;
+
+    public OrderDetail(String name, int quantity) {
+        this.name = name;
+        this.quantity = quantity;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(int quantity) {
+        this.quantity = quantity;
+    }
+}
Index: src/main/java/com/example/salonbella/service/order/OrderResponse.java
===================================================================
--- src/main/java/com/example/salonbella/service/order/OrderResponse.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
+++ src/main/java/com/example/salonbella/service/order/OrderResponse.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
@@ -0,0 +1,73 @@
+package com.example.salonbella.service.order;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OrderResponse {
+
+    private long id;
+    private String status;
+    private LocalDate localDate;
+    private double total;
+    private List<OrderDetail> orderDetails = new ArrayList<>();
+    private String name;
+    private String surname;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public LocalDate getLocalDate() {
+        return localDate;
+    }
+
+    public void setLocalDate(LocalDate localDate) {
+        this.localDate = localDate;
+    }
+
+    public double getTotal() {
+        return total;
+    }
+
+    public void setTotal(double total) {
+        this.total = total;
+    }
+
+    public List<OrderDetail> getOrderDetails() {
+        return orderDetails;
+    }
+
+    public void setOrderDetails(List<OrderDetail> orderDetails) {
+        this.orderDetails = orderDetails;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getSurname() {
+        return surname;
+    }
+
+    public void setSurname(String surname) {
+        this.surname = surname;
+    }
+}
+
Index: src/main/java/com/example/salonbella/service/order/OrderService.java
===================================================================
--- src/main/java/com/example/salonbella/service/order/OrderService.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
+++ src/main/java/com/example/salonbella/service/order/OrderService.java	(revision e9b70f6947737fd8ec8c5599c2b85b09f0ce2276)
@@ -0,0 +1,157 @@
+package com.example.salonbella.service.order;
+
+import com.example.salonbella.controller.cart.ShoppingCart;
+import com.example.salonbella.entity.CartDetailEntity;
+import com.example.salonbella.entity.OrderEntity;
+import com.example.salonbella.entity.UserEntity;
+import com.example.salonbella.repository.OrderRepository;
+import com.example.salonbella.repository.ProductRepository;
+import com.example.salonbella.repository.UserRepository;
+import com.twilio.Twilio;
+import com.twilio.rest.api.v2010.account.Message;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Service;
+
+import javax.transaction.Transactional;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@Service
+public class OrderService {
+
+    private final UserRepository userRepository;
+    private final ProductRepository productRepository;
+    private final OrderRepository orderRepository;
+    private static final String ACCOUNT_SID = "AC773ecbd8592a5cad8169cd06c3ce6e13";
+    private static final String AUTH_TOKEN = "51247e92a82c11f5a929c4e3ae6c2953";
+
+    @Autowired
+    public OrderService(UserRepository userRepository, ProductRepository productRepository, OrderRepository orderRepository) {
+        this.userRepository = userRepository;
+        this.productRepository = productRepository;
+        this.orderRepository = orderRepository;
+    }
+
+    public void saveOrder(ShoppingCart shoppingCart) {
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+        String username = auth.getName();
+        UserEntity user = userRepository.findByUsername(username);
+        OrderEntity orderEntity = new OrderEntity();
+        orderEntity.setCartDetails(shoppingCart.getCartDetails());
+        orderEntity.setUser(user);
+        orderEntity.setLocalDate(LocalDate.now());
+        orderEntity.setTotal(calculateTotalPrice(shoppingCart));
+        orderEntity.setStatus("PENDING");
+        orderRepository.save(orderEntity);
+    }
+
+    public void changeQuantities(Map<String, String> allParams, ShoppingCart shoppingCart) {
+        for (String id : allParams.keySet()) {
+            for (CartDetailEntity c : shoppingCart.getCartDetails()) {
+                if (c.getId() == Long.parseLong(id)) {
+                    c.setQuantity(Integer.parseInt(allParams.get(id)));
+                    break;
+                }
+            }
+        }
+    }
+
+
+    public double calculateTotalPrice(ShoppingCart shoppingCart) {
+        double total = 0.0;
+        for (CartDetailEntity c : shoppingCart.getCartDetails()) {
+            total += (c.getQuantity() * productRepository.findById(c.getId()).get().getPrice());
+        }
+        return total;
+    }
+
+    public void clearCart(ShoppingCart shoppingCart) {
+        for (int i = 0; i < shoppingCart.getCartDetails().size(); i++) {
+            shoppingCart.getCartDetails().remove(i);
+            i--;
+        }
+    }
+
+    public List<OrderEntity> getUserOrders() {
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+        String username = auth.getName();
+        return makeOrderDetails(username);
+    }
+
+    public List<OrderEntity> makeOrderDetails(String username) {
+        UserEntity user = userRepository.findByUsername(username);
+        List<OrderEntity> orderEntityList = orderRepository.findAllByUser(user);
+        for (OrderEntity order : orderEntityList) {
+            for (CartDetailEntity cartDetailEntity : order.getCartDetails()) {
+                String name = productRepository.findById(cartDetailEntity.getId()).get().getName();
+                int quantity = cartDetailEntity.getQuantity();
+                order.getOrderDetails().add(new OrderDetail(name, quantity));
+            }
+        }
+        return orderEntityList;
+    }
+
+    @Transactional
+    public void cancelOrder(Long id) {
+        Optional<OrderEntity> orderEntity = orderRepository.findById(id);
+        if (orderEntity.isPresent()) {
+            if (getUser().getId().equals(orderEntity.get().getUser().getId())) {
+                orderRepository.delete(orderEntity.get());
+            }
+        }
+    }
+
+    @Transactional
+    public void cancelOrderAdmin(Long id) {
+        Optional<OrderEntity> orderEntity = orderRepository.findById(id);
+        orderEntity.ifPresent(orderRepository::delete);
+    }
+
+    @Transactional
+    public void changeOrderStatus(Long id) {
+        Optional<OrderEntity> orderEntity = orderRepository.findById(id);
+        orderEntity.ifPresent(entity -> entity.setStatus("AWAITING PICKUP"));
+//        Twilio.init(ACCOUNT_SID,AUTH_TOKEN);
+//        Message message = Message.creator(
+//                        new com.twilio.type.PhoneNumber(getUser().getNumber().replaceFirst("0","+389")),
+//                        new com.twilio.type.PhoneNumber("+1 815 567 9673"),
+//                        "YOUR ORDER IS HERE")
+//                .create();
+    }
+
+    public UserEntity getUser() {
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+        String username = auth.getName();
+        UserEntity user = userRepository.findByUsername(username);
+        return user;
+    }
+
+    public List<OrderResponse> getAllOrders() {
+        List<OrderResponse> orderResponses = new ArrayList<>();
+        List<OrderEntity> orderEntities = orderRepository.findAll();
+        for (OrderEntity order : orderEntities) {
+            for (CartDetailEntity cartDetailEntity : order.getCartDetails()) {
+                String name = productRepository.findById(cartDetailEntity.getId()).get().getName();
+                int quantity = cartDetailEntity.getQuantity();
+                order.getOrderDetails().add(new OrderDetail(name, quantity));
+            }
+            OrderResponse orderResponse = new OrderResponse();
+            orderResponse.setId(order.getId());
+            orderResponse.setOrderDetails(order.getOrderDetails());
+            orderResponse.setLocalDate(order.getLocalDate());
+            orderResponse.setStatus(order.getStatus());
+            orderResponse.setTotal(order.getTotal());
+            orderResponse.setName(order.getUser().getName());
+            orderResponse.setSurname(order.getUser().getSurname());
+            orderResponses.add(orderResponse);
+        }
+        return orderResponses;
+    }
+
+}
+
