<commit_before>import axios from 'axios';

// Products
export const GET_PRODUCTS = 'GET_PRODUCTS';
export const GET_PRODUCT = 'GET_PRODUCT';
export const CREATE_PRODUCT = 'CREATE_PRODUCT';
export const UPDATE_PRODUCT = 'UPDATE_PRODUCT';

export const getProducts = (products) => ({ type: GET_PRODUCTS, receivedProducts: products});
export const getProduct = (product) => ({ type: GET_PRODUCT, receivedProduct: product});
export const createProduct = (product) => ({ type: CREATE_PRODUCT, productToCreate: product});
export const updateProduct = (product) => ({ type: UPDATE_PRODUCT, productToUpdate: product});

//thunk action creators
export const fetchProducts = () => {
    return (dispatch) => {
        axios.get('/api/products')
        .then((res) => res.data)
        .then((products) => {
            dispatch(getProducts(products));
        })
        .catch(function (err) {
            console.error(err);
        });
    };
};<commit_msg>feat(products actions): finished action creators<commit_after>import axios from 'axios';

// Products
export const GET_PRODUCTS = 'GET_PRODUCTS';
export const GET_PRODUCT = 'GET_PRODUCT';
export const CREATE_PRODUCT = 'CREATE_PRODUCT';
export const UPDATE_PRODUCT = 'UPDATE_PRODUCT';

export const getProducts = (products) => ({ type: GET_PRODUCTS, receivedProducts: products});
export const getProduct = (product) => ({ type: GET_PRODUCT, receivedProduct: product});
export const createProduct = (product) => ({ type: CREATE_PRODUCT, productToCreate: product});
export const changeProduct = (product) => ({ type: UPDATE_PRODUCT, productToUpdate: product});

//thunk action creators
export const fetchProducts = () => dispatch => {
        axios.get('/api/products')
        .then(res => dispatch(getProducts(res.data)))
        .catch(err => console.error('Fetching products unsuccessful', err))
}

export const fetchProduct = (id) => dispatch => {
    axios.get(`/api/products/${id}`)
        .then(res => dispatch(getProduct(res.data)))
        .catch(err => console.error('Fetching product unsuccessful', err))
}

export const addProduct = product => dispatch => {
    axios.post('/api/products', product)
        .then(res => dispatch(createProduct(res.data)))
        .catch(err => console.error(`Creating product: ${product} unsuccessful`, err))
}

export const updateProduct = (id, product) => dispatch => {
    axios.put(`/api/products/${id}`, product)
        .then(res => dispatch(changeProduct(res.data)))
        .catch(err => console.error(`Updating product: ${product} unsuccessful`, err))
}
{'fraction_non_alphanumeric': 0.14861165428236214, 'fraction_numerical': 0.0, 'mean_word_length': 4.329166666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1514555', 'n_tokens_mistral': 749, 'n_tokens_neox': 724, 'n_words': 185}