From 5eba558daab4a9c3686210b203b3f0aa34571405 Mon Sep 17 00:00:00 2001
From: Rizwan <rk00436@surrey.ac.uk>
Date: Sun, 18 Apr 2021 17:30:09 +0100
Subject: [PATCH] Created graphql adapter classes for the 3 microservices in
 the project

---
 .../graphql/adapters/CommentsService.js       | 28 ++++++++++++++
 .../graphql/adapters/PostsService.js          | 38 +++++++++++++++++++
 .../graphql/adapters/UsersService.js          | 32 ++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 apollo-gateway/graphql/adapters/CommentsService.js
 create mode 100644 apollo-gateway/graphql/adapters/PostsService.js
 create mode 100644 apollo-gateway/graphql/adapters/UsersService.js

diff --git a/apollo-gateway/graphql/adapters/CommentsService.js b/apollo-gateway/graphql/adapters/CommentsService.js
new file mode 100644
index 0000000..a89b8fd
--- /dev/null
+++ b/apollo-gateway/graphql/adapters/CommentsService.js
@@ -0,0 +1,28 @@
+import axios from 'axios';
+
+const COMMENTS_SERVICE_URI = "http://localhost:5003";
+
+export default class PostsService {
+  static async fetchAllPostComments({ postId }) {
+    const { data } = await axios.get(`${COMMENTS_SERVICE_URI}/comments/post/${postId}`);
+    return data;
+  }
+
+  static async getCommentById({ id }) {
+    const { data } = await axios.get(`${COMMENTS_SERVICE_URI}/comments/${id}`);
+    return data;
+  }
+
+  static async deleteCommentById({ id }) {
+    await axios.delete(`${COMMENTS_SERVICE_URI}/comments/${id}`);
+  }
+
+  static async createComment(comment) {
+    const { data } = await axios.post(`${COMMENTS_SERVICE_URI}/comments/`, comment);
+    return data;
+  }
+
+  static async deleteAllPostComments({ postId }) {
+    await axios.delete(`${COMMENTS_SERVICE_URI}/comments/post/${postId}`);
+  }
+}
\ No newline at end of file
diff --git a/apollo-gateway/graphql/adapters/PostsService.js b/apollo-gateway/graphql/adapters/PostsService.js
new file mode 100644
index 0000000..d0df8d6
--- /dev/null
+++ b/apollo-gateway/graphql/adapters/PostsService.js
@@ -0,0 +1,38 @@
+import axios from 'axios';
+
+const POSTS_SERVICE_URI = "http://localhost:5002";
+
+export default class PostsService {
+  static async fetchAllPosts() {
+    const { data } = await axios.get(`${POSTS_SERVICE_URI}/posts/`);
+    return data;
+  }
+
+  static async getPostById({ id }) {
+    const { data } = await axios.get(`${POSTS_SERVICE_URI}/posts/${id}`);
+    return data;
+  }
+
+  static async createPost(post) {
+    const { data } = await axios.post(`${POSTS_SERVICE_URI}/posts/`, post);
+    return data;
+  }
+
+  static async deletePost({ id }) {
+    await axios.delete(`${POSTS_SERVICE_URI}/posts/${id}`);
+  }
+
+  static async likePost({ postId, userId }) {
+    await axios.patch(`${POSTS_SERVICE_URI}/posts/${postId}/like/${userId}`)
+  }
+
+  static async addCommentId({ commentId, postId }) {
+    const { data } = await axios.patch(`${POSTS_SERVICE_URI}/posts/${postId}/comment/${commentId}`);
+    return data;
+  }
+
+  static async deleteCommentId({ commentId, postId }) {
+    const { data } = await axios.delete(`${POSTS_SERVICE_URI}/posts/${postId}/comment/${commentId}`);
+    return data;
+  }
+}
\ No newline at end of file
diff --git a/apollo-gateway/graphql/adapters/UsersService.js b/apollo-gateway/graphql/adapters/UsersService.js
new file mode 100644
index 0000000..aca9cd3
--- /dev/null
+++ b/apollo-gateway/graphql/adapters/UsersService.js
@@ -0,0 +1,32 @@
+import axios from 'axios';
+
+const USERS_SERVICE_URI = "http://localhost:5001/user";
+
+export default class UsersService {
+  static async signup({ name, email, password }) {
+    const { data } = await axios.post(`${USERS_SERVICE_URI}/signup`, {
+      name,
+      email,
+      password
+    });
+    return data;
+  }
+
+  static async signin({ email, password }) {
+    const { data } = await axios.post(`${USERS_SERVICE_URI}/signin`, {
+      email,
+      password
+    });
+    return data;
+  }
+
+  static async checkUserEmail({ email }) {
+    const { data } = await axios.get(`${USERS_SERVICE_URI}/user/check/${email}`);
+    return data;
+  }
+
+  static async getUserById({ id }) {
+    const { data } = await axios.get(`${USERS_SERVICE_URI}/user/${id}`);
+    return data;
+  }
+}
\ No newline at end of file
-- 
GitLab