aboutsummaryrefslogtreecommitdiff
path: root/handlers
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-10-20 05:10:04 +0530
committerBobby <[email protected]>2025-10-20 05:10:04 +0530
commit3cf9e5b399472ac344b12fb17890b94a66ad5341 (patch)
tree208066ece803bbf8c35fff5fa5648d597e704f5d /handlers
downloadcomplexity-analyzer-3cf9e5b399472ac344b12fb17890b94a66ad5341.tar.xz
complexity-analyzer-3cf9e5b399472ac344b12fb17890b94a66ad5341.zip
add handler for analysing request code
Diffstat (limited to 'handlers')
-rw-r--r--handlers/analyze.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/handlers/analyze.go b/handlers/analyze.go
new file mode 100644
index 0000000..6943981
--- /dev/null
+++ b/handlers/analyze.go
@@ -0,0 +1,49 @@
+package handlers
+
+import (
+ "complexity-analyzer/services"
+
+ "github.com/gofiber/fiber/v2"
+)
+
+type AnalyzeRequest struct {
+ Code string `json:"code"`
+ Language string `json:"language"`
+}
+
+type AnalyzeResponse struct {
+ Complexity string `json:"complexity"`
+ Confidence float64 `json:"confidence"`
+ StaticAnalysis []string `json:"staticAnalysis"`
+ PerformanceData []PerformancePoint `json:"performanceData"`
+ Error string `json:"error,omitempty"`
+}
+
+type PerformancePoint struct {
+ Size int `json:"size"`
+ Time float64 `json:"time"`
+}
+
+func AnalyzeCode(c *fiber.Ctx) error {
+ var req AnalyzeRequest
+ if err := c.BodyParser(&req); err != nil {
+ return c.Status(400).JSON(fiber.Map{
+ "error": "Invalid request body",
+ })
+ }
+
+ if req.Code == "" {
+ return c.Status(400).JSON(fiber.Map{
+ "error": "Code is required",
+ })
+ }
+
+ result, err := services.AnalyzeWithGemini(req.Code, req.Language)
+ if err != nil {
+ return c.Status(500).JSON(fiber.Map{
+ "error": err.Error(),
+ })
+ }
+
+ return c.JSON(result)
+}