-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
213 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import Vue from 'vue' | ||
import Vuex from 'vuex' | ||
import auth from './modules/auth' | ||
import works from './modules/works' | ||
import reviews from './modules/reviews' | ||
import categories from './modules/categories' | ||
Vue.use(Vuex); | ||
|
||
export default new Vuex.Store({ | ||
modules: { | ||
auth | ||
auth, | ||
works, | ||
reviews, | ||
categories | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import axios from '../../customAxios' | ||
import formData from '../../utils/formData'; | ||
|
||
export default { | ||
namespaced: true, | ||
|
||
state: { | ||
works: [] | ||
}, | ||
|
||
mutations: { | ||
setWorks (state, works) { | ||
state.works = works | ||
}, | ||
|
||
addWork (state, work) { | ||
state.works = [...works, work] | ||
}, | ||
|
||
setWork (state, work) { | ||
state.works = state.works.map(item => item.id === work.id ? work : item) | ||
}, | ||
|
||
removeWork (state, workId) { | ||
state.works = state.works.filter(work => work.id !== workId) | ||
} | ||
}, | ||
|
||
actions: { | ||
async loadWorks ({ commit }, userId) { | ||
try { | ||
const { data } = await axios.get(`/works/${userId}`) | ||
commit('setWorks', data) | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
}, | ||
|
||
async saveWork ({ commit }, work) { | ||
try { | ||
const { data } = await axios.post( | ||
'/works', | ||
formData(work), | ||
{ headers: { 'Content-Type': 'multipart/form-data' } | ||
}) | ||
|
||
commit('addWork', data) | ||
} catch (error) { | ||
throw new Error(error) | ||
} | ||
}, | ||
async updateWork ({ commit }, payload) { | ||
try { | ||
const { data } = await axios.post(`/works/${payload.id}`, formData(payload), { headers: { 'Content-Type': 'multipart/form-data' } }) | ||
commit('setWork', data) | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
}, | ||
async deleteWork ({ commit }, workId) { | ||
try { | ||
await axios.delete(`/works/${workId}`) | ||
commit('removeWork', workId) | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default (payload) => { | ||
const formData = new FormData() | ||
|
||
Object.keys(payload).forEach(key => { | ||
formData.append(key, payload[key]) | ||
}) | ||
|
||
return formData; | ||
} |