diff --git a/starter-project-web-vue2/components/amanz/AddBlog.vue b/starter-project-web-vue2/components/amanz/AddBlog.vue new file mode 100644 index 00000000..24f28e13 --- /dev/null +++ b/starter-project-web-vue2/components/amanz/AddBlog.vue @@ -0,0 +1,119 @@ + + + diff --git a/starter-project-web-vue2/components/amanz/AmanzBlog.vue b/starter-project-web-vue2/components/amanz/AmanzBlog.vue new file mode 100644 index 00000000..051020c2 --- /dev/null +++ b/starter-project-web-vue2/components/amanz/AmanzBlog.vue @@ -0,0 +1,70 @@ + + + diff --git a/starter-project-web-vue2/components/amanz/EditBlog.vue b/starter-project-web-vue2/components/amanz/EditBlog.vue new file mode 100644 index 00000000..3a7663e9 --- /dev/null +++ b/starter-project-web-vue2/components/amanz/EditBlog.vue @@ -0,0 +1,75 @@ + + + diff --git a/starter-project-web-vue2/pages/amanz/_id.vue b/starter-project-web-vue2/pages/amanz/_id.vue new file mode 100644 index 00000000..fe9e14d7 --- /dev/null +++ b/starter-project-web-vue2/pages/amanz/_id.vue @@ -0,0 +1,51 @@ + + + diff --git a/starter-project-web-vue2/pages/amanz/index.vue b/starter-project-web-vue2/pages/amanz/index.vue new file mode 100644 index 00000000..75e414fb --- /dev/null +++ b/starter-project-web-vue2/pages/amanz/index.vue @@ -0,0 +1,30 @@ + + + diff --git a/starter-project-web-vue2/pages/index.vue b/starter-project-web-vue2/pages/index.vue index 95c1f831..b766fc44 100644 --- a/starter-project-web-vue2/pages/index.vue +++ b/starter-project-web-vue2/pages/index.vue @@ -41,7 +41,6 @@ export default { name: 'Amsale Gebrehana', description: 'A2SV G31', link: '/amsale', - }, { name: 'Ruth Getachew', @@ -49,10 +48,14 @@ export default { link: '/ruth', }, { - name: "Keiredin Aman", + name: 'Keiredin Aman', description: 'Summer Intern', - link: - '/keiredin', + link: '/keiredin', + }, + { + name: 'Amanuel Alemayehu', + description: 'Web Team Member', + link: '/amanz', }, ], } diff --git a/starter-project-web-vue2/store/amanz.js b/starter-project-web-vue2/store/amanz.js new file mode 100644 index 00000000..73f42ac7 --- /dev/null +++ b/starter-project-web-vue2/store/amanz.js @@ -0,0 +1,72 @@ +// eslint-disable-next-line no-unused-vars +import axios from 'axios' + +const state = { + blogs: [], + blog: {}, +} + +const getters = { + allBlogs: (state) => state.blogs, +} + +const actions = { + // eslint-disable-next-line no-unused-vars + async fetchBlogs({ commit }) { + const response = await axios.get( + 'https://blog-app-backend.onrender.com/api/articles/all' + ) + commit('setBlogs', response.data) + }, + + async fetchBlogsById({ commit }, id) { + const response = await axios.get( + `https://blog-app-backend.onrender.com/api/articles/${id}` + ) + commit('setBlog', response.data) + }, + + async addBlog({ commit }, newBlog) { + const response = await this.$axios.post( + 'https://blog-app-backend.onrender.com/api/articles', + newBlog + ) + commit('newBlog', response.data) + }, + + async deleteBlog({ commit }, id) { + await this.$axios.delete( + `https://blog-app-backend.onrender.com/api/articles/${id}` + ) + + commit('removeBlog', id) + }, + + async updateBlog({ commit }, updated) { + const response = await this.$axios.put( + `https://blog-app-backend.onrender.com/api/articles/${updated.id}`, + updated + ) + commit('updateBlog', response.data) + }, +} + +const mutations = { + setBlogs: (state, blogs) => (state.blogs = blogs), + newBlog: (state, blog) => state.blogs.unshift(blog), + setBlog: (state, blog) => (state.blog = blog), + // newBlog: (state, blog) => state.blogs.unshift(blog), + removeBlog: (state, id) => + (state.blogs = state.blogs.filter((blogg) => blogg._id !== id)), + // updateBlog: (state, blog) => { + // const index = state.blogs.findIndex((blogg) => blogg._id === blog._id) + + // } +} + +export default { + state, + getters, + actions, + mutations, +}