diff --git a/starter-project-web-vue2/components/kaleab/KaleabAddArticle.vue b/starter-project-web-vue2/components/kaleab/KaleabAddArticle.vue new file mode 100644 index 0000000..6af9ccb --- /dev/null +++ b/starter-project-web-vue2/components/kaleab/KaleabAddArticle.vue @@ -0,0 +1,68 @@ + + \ No newline at end of file diff --git a/starter-project-web-vue2/components/kaleab/KaleabArticles.vue b/starter-project-web-vue2/components/kaleab/KaleabArticles.vue new file mode 100644 index 0000000..4a34d98 --- /dev/null +++ b/starter-project-web-vue2/components/kaleab/KaleabArticles.vue @@ -0,0 +1,152 @@ + + + diff --git a/starter-project-web-vue2/layouts/default.vue b/starter-project-web-vue2/layouts/default.vue index f25910e..ac530bf 100644 --- a/starter-project-web-vue2/layouts/default.vue +++ b/starter-project-web-vue2/layouts/default.vue @@ -40,6 +40,7 @@ mdi-menu + diff --git a/starter-project-web-vue2/pages/index.vue b/starter-project-web-vue2/pages/index.vue index 642d815..b258557 100644 --- a/starter-project-web-vue2/pages/index.vue +++ b/starter-project-web-vue2/pages/index.vue @@ -81,6 +81,11 @@ export default { name: 'Bisrat Walle', description: 'Software Engineer', link: '/bisrat', + }, + { + name: 'Kaleab Kindu', + description: 'Software Engineer', + link: '/kaleab', } ], } diff --git a/starter-project-web-vue2/pages/kaleab/_id.vue b/starter-project-web-vue2/pages/kaleab/_id.vue new file mode 100644 index 0000000..7f4490c --- /dev/null +++ b/starter-project-web-vue2/pages/kaleab/_id.vue @@ -0,0 +1,69 @@ + + + diff --git a/starter-project-web-vue2/pages/kaleab/index.vue b/starter-project-web-vue2/pages/kaleab/index.vue new file mode 100644 index 0000000..c1f840f --- /dev/null +++ b/starter-project-web-vue2/pages/kaleab/index.vue @@ -0,0 +1,17 @@ + + + diff --git a/starter-project-web-vue2/store/kaleab.js b/starter-project-web-vue2/store/kaleab.js new file mode 100644 index 0000000..5443f73 --- /dev/null +++ b/starter-project-web-vue2/store/kaleab.js @@ -0,0 +1,51 @@ + +export const state = { + articles: [] +}; + + +export const getters = { + allArticles: (state) => state.articles +}; + +export const actions = { + async fetchArticles({ commit }){ + const response = await this.$axios.get("articles/all") + commit("setArticles", response.data) + }, + async addArticles({ commit }, article){ + const response = await this.$axios.post("articles", article) + commit("newArticles", response.data) + }, + + async deleteArticles({ commit }, id){ + await this.$axios.delete(`articles/${id}`) + commit("removeArticles", id) + }, + async updateArticles({ commit }, newArticle){ + + const response = await this.$axios.patch(`articles/${newArticle._id}`, newArticle) + commit("modifyArticles", response.data) + } +}; + +export const mutations = { + setArticles: (state, articles) => (state.articles = articles), + newArticles: (state, article) => (state.articles.unshift(article)), + removeArticles: (state, id) => (state.articles = state.articles.filter((article) => article._id !== id)), + modifyArticles: (state, updateArticle) => { + const index = state.articles.findIndex((article) => article._id === updateArticle._id) + if (index !== -1){ + state.articles.splice(index, 1, updateArticle) + } + } +}; + +export default { + state, + getters, + actions, + mutations +} + +