CWinarski 6 years ago
parent
commit
d8d8c91d71

+ 22
- 6
Client/src/main/java/SimpleShell.java View File

@@ -1,5 +1,5 @@
1
-import okhttp3.Request;
2
-import okhttp3.Response;
1
+
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3 3
 
4 4
 import java.io.BufferedReader;
5 5
 import java.io.IOException;
@@ -12,11 +12,17 @@ public class SimpleShell {
12 12
 
13 13
 
14 14
     public static void prettyPrint(String output) {
15
-        // yep, make an effort to format things nicely, eh?
16
-        System.out.println(output);
15
+        ObjectMapper objectMapper = new ObjectMapper();
16
+        try{
17
+            Object json = objectMapper.readValue(output, Object.class);
18
+            String prettyPrint = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
19
+            System.out.println(prettyPrint);
20
+        } catch (IOException e) {
21
+            e.printStackTrace();
22
+        }
17 23
     }
18 24
     public static void main(String[] args) throws java.io.IOException {
19
-
25
+        ObjectMapper objectMapper = new ObjectMapper();
20 26
         YouAreEll webber = new YouAreEll();
21 27
         String commandLine;
22 28
         BufferedReader console = new BufferedReader
@@ -62,7 +68,7 @@ public class SimpleShell {
62 68
                 // Specific Commands.
63 69
 
64 70
                 // ids
65
-                if (list.contains("ids")) {
71
+                if (list.contains("ids") && list.size() == 1) {
66 72
                     String results = webber.get_ids();
67 73
                     SimpleShell.prettyPrint(results);
68 74
                     continue;
@@ -76,6 +82,16 @@ public class SimpleShell {
76 82
                 }
77 83
                 // you need to add a bunch more.
78 84
 
85
+
86
+                if (list.contains("ids") && list.size() == 3){
87
+                    String name = list.get(1);
88
+                    String gitHubId = list.get(2);
89
+                    User newUserId = new User(name, gitHubId);
90
+                    String newIdInfo = objectMapper.writeValueAsString(newUserId);
91
+                    webber.MakeURLCall("/ids","POST", newIdInfo);
92
+                    continue;
93
+                }
94
+
79 95
                 // create
80 96
                 // send message
81 97
                 //

+ 0
- 1
Client/src/main/java/User.java View File

@@ -49,7 +49,6 @@ public class User {
49 49
                 "userid='" + userid + '\'' +
50 50
                 ", name='" + name + '\'' +
51 51
                 ", githubid='" + githubid + '\'' +
52
-                ", client=" + client +
53 52
                 '}';
54 53
     }
55 54
 }

+ 3
- 5
Client/src/main/java/YouAreEll.java View File

@@ -23,20 +23,18 @@ public class YouAreEll {
23 23
     }
24 24
 
25 25
     public String MakeURLCall(String mainurl, String method, String jpayload) {
26
-
26
+        // put is not implemented
27 27
         String actualUrl = "http://zipcode.rocks:8085" + mainurl;
28 28
 
29 29
         if (method.equals("GET")) {
30
-            Request request = new Request.Builder()
31
-                    .url(actualUrl)
32
-                    .build();
30
+            Request request = new Request.Builder().url(actualUrl).build();
33 31
 
34 32
             try (Response response = client.newCall(request).execute()) {
35 33
                 return response.body().string();
36 34
             } catch (IOException ioe) {
37 35
                 ioe.printStackTrace();
38 36
             }
39
-        } else if (method.equals("PUT")){
37
+        } else if (method.equals("POST")){
40 38
                 RequestBody body = RequestBody.create(JSON, jpayload);
41 39
                 Request request = new Request.Builder()
42 40
                         .url(actualUrl)