Subversion Repositories SmartDukaan

Rev

Rev 35367 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
35079 vikas 1
package com.spice.profitmandi.shopify.services;
2
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
3
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
35504 vikas 4
import com.spice.profitmandi.dao.service.shopify.ShopifyGraphQLService;
35079 vikas 5
import com.spice.profitmandi.shopify.models.ShopifySyncModel;
6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Service;
10
 
11
import java.util.HashMap;
12
import java.util.Map;
13
 
14
@Service
15
public class FofoShopifyService {
16
    private static final Logger logger = LogManager.getLogger(FofoShopifyService.class);
17
 
18
    @Autowired
19
    private FofoStoreRepository fofoStoreRepository;
20
 
21
    @Autowired
22
    private ShopifyGraphQLService shopifyGraphQLService;
23
 
24
    public FofoStore syncStoreToShopify(ShopifySyncModel req) throws Exception {
25
        FofoStore store = fofoStoreRepository.selectByRetailerId(req.getFofoStoreId());
26
        if (store == null) throw new RuntimeException("FofoStore not found: " + req.getFofoStoreId());
27
 
28
        if (req.isSyncLocation()) {
29
            Map<String,String> address = new HashMap<>();
30
            address.put("address1", store.getUserAddress() != null ? store.getUserAddress().getAddressDescription() : "");
31
            address.put("city", store.getUserAddress().getCity() != null ? store.getUserAddress().getCity() : "");
32
            address.put("province", store.getUserAddress().getState() != null ? store.getUserAddress().getState() : "");
33
            address.put("zip", store.getUserAddress().getPinCode() != null ? store.getUserAddress().getPinCode() : "");
34
            address.put("country", "IN");
35
            address.put("phone", store.getUserAddress().getPhoneNumber() != null ? store.getUserAddress().getPhoneNumber() : "");
36
 
37
            String locationGid = shopifyGraphQLService.createLocation(store.getCode(), address);
38
            String numeric = shopifyGraphQLService.extractIdFromGid(locationGid);
35308 amit 39
            //store.setShopifyLocationId(numeric);
35079 vikas 40
        }
41
 
42
        if (req.isSyncCustomer()) {
43
            String email = store.getCode() + "@franchise.example.com";
44
            String customerGid = shopifyGraphQLService.createCustomer(email, store.getCode(), store.getCode());
45
            String numeric = shopifyGraphQLService.extractIdFromGid(customerGid);
35308 amit 46
            //store.setShopifyCustomerId(numeric);
35079 vikas 47
        }
48
 
49
        return store;
50
    }
51
 
52
}