Skip to content

Commit

Permalink
Use Vuex logic to create Events, storing them in db.json
Browse files Browse the repository at this point in the history
  • Loading branch information
pepas24 committed Mar 12, 2019
1 parent 43d3056 commit 706b003
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 38 deletions.
18 changes: 18 additions & 0 deletions db.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@
"name": "Mary Gordon"
}
]
},
{
"id": 972213,
"user": {
"id": "abc123",
"name": "Adam Jahr"
},
"organizer": {
"id": "abc123",
"name": "Adam Jahr"
},
"title": "Plant Trees",
"description": "Go to the forest to plant some trees",
"category": "nature",
"location": "Forest",
"date": "2019-03-14",
"time": "08:10",
"attendees": []
}
]
}
47 changes: 13 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/services/EventService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export default {
},
getEvent(id) {
return apiClient.get('/events/' + id)
},
postEvent(event) {
return apiClient.post('/events', event)
}
}
33 changes: 30 additions & 3 deletions src/store.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import Vue from 'vue'
import Vuex from 'vuex'
import EventService from '@/services/EventService'

Vue.use(Vuex)

export default new Vuex.Store({
state: {},
mutations: {},
actions: {}
state: {
user: {
id: 'abc123',
name: 'Adam Jahr'
},
categories: [
'sustainability',
'nature',
'animal welfare',
'housing',
'education',
'food',
'community'
],
events: []
},
getters: {},
mutations: {
ADD_EVENT(state, event) {
state.events.push(event)
}
},
actions: {
createEvent({ commit }, event) {
return EventService.postEvent(event).then(() => {
commit('ADD_EVENT', event)
})
}
}
})
Loading

0 comments on commit 706b003

Please sign in to comment.