-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServer.java
More file actions
63 lines (51 loc) · 2.07 KB
/
WebServer.java
File metadata and controls
63 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.ai.reviewer;
import static spark.Spark.*;
import com.google.gson.Gson;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
public class WebServer {
public static void main(String[] args) {
port(4567); // Set the port for the web server
Gson gson = new Gson();
CodeReviewerAgent reviewerAgent = new CodeReviewerAgent();
// Define the /review endpoint
post("/review", (req, res) -> {
res.type("application/json");
// Get the file path from the request
String filePath = req.queryParams("filePath");
if (filePath == null || filePath.isEmpty()) {
res.status(400);
return gson.toJson(Map.of("error", "filePath parameter is required"));
}
File file = new File(filePath);
if (!file.exists() || !file.isFile()) {
res.status(400);
return gson.toJson(Map.of("error", "File not found: " + filePath));
}
// Read the file content
StringBuilder code = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
code.append(line).append("\n");
}
} catch (Exception e) {
res.status(500);
return gson.toJson(Map.of("error", "Error reading file: " + e.getMessage()));
}
// Perform the code review
ReviewResult result = reviewerAgent.reviewCode(file.getName(), code.toString());
// Return the review result as JSON
return gson.toJson(result);
});
// Define a simple health check endpoint
get("/health", (req, res) -> {
res.type("application/json");
return gson.toJson(Map.of("status", "ok"));
});
System.out.println("Web server is running on http://localhost:4567");
}
}