From 670fba3b9322db1373078de48a79ada07c25be44 Mon Sep 17 00:00:00 2001
From: Shaikh Rezwan Rafid Ahmad <sa03267@surrey.ac.uk>
Date: Fri, 17 Mar 2023 16:03:44 +0000
Subject: [PATCH] getUser Controller Created

---
 .../server/controllers/appController.js       | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/daily-thought-user-service/server/controllers/appController.js b/daily-thought-user-service/server/controllers/appController.js
index 8936ad6a..7a681b0d 100644
--- a/daily-thought-user-service/server/controllers/appController.js
+++ b/daily-thought-user-service/server/controllers/appController.js
@@ -135,7 +135,22 @@ export async function login(req,res){
 
 export async function getUser(req,res){
 
-    // const { username } = req.params;
+    const { username } = req.params;
 
-    res.json('getUser route')
+    try {
+
+        if(!username) return res.status(501).send({error: "Invalid Username"});
+
+        UserModel.findOne({username}, function(err, user){
+            if(err) return res.status(500).send({err});
+            if(!user) return res.status(501).send({ error: "Couldn't find the User"});
+            
+            const { password, ...rest } = Object.assign({}, user.toJSON());
+
+            return res.status(201).send(rest)
+        })
+
+    }catch(err) {
+        return res.status(404).send({ error: "Cannot find User Data"});
+    }
 }
-- 
GitLab