fedect1 / graduation-project-fedect1

graduation-project-fedect1 created by GitHub Classroom
MIT License
1 stars 0 forks source link

#CleanCode Frontend #15

Open Dr4gon opened 1 year ago

Dr4gon commented 1 year ago

@fedect1 You have a very clean and consistent separation of concerns 😍

FeedView.vue

  methods: {
    ...mapActions(usePostHandler, ['createPost', 'fetchPosts']),
    async submitPost(bodyPost) {
      await this.createPost(bodyPost)
    }
  },

I see that you took the feedback about the parameters in the REST path to heart.

postHandler.js

   actions: {
    async fetchPosts() {
      this.posts = (await axios.get('/posts')).data
    },
    async fetchPostById(postId) {
      this.post = (await axios.get(`/posts/${postId}`)).data
    },
    async createPost(bodyPost) {
      this.post = (await axios.post('/posts', { bodyPost })).data
    },
    async createComment(postId, text, user) {
      this.comment = (await axios.post(`/posts/${postId}/comments`, { text, user })).data
    },
    async fetchComments(postId) {
      this.comments = (await axios.get(`/posts/${postId}/comments`)).data
    },
    async likePost(postId, userId) {
      this.like = (await axios.post(`/posts/${postId}/likes`, { userId })).data
    },
    async dislikePost(postId, userId) {
      this.like = (await axios.delete(`/posts/unlike/${postId}/${userId}`)).data
    },
    async deletePost(postId, userId) {
      await axios.delete(`/posts/${postId}/${userId}`)
    },
    async deleteComment(postId, commentId, userId) {
      await axios.delete(`/posts/${postId}/comments/${commentId}/${userId}`)
    }
  }