Skip to content

Commit 47a41b2

Browse files
Merge pull request #8 from 0PrashantYadav0/main
Added new features.
2 parents 7519f86 + fa49ff2 commit 47a41b2

File tree

5 files changed

+152
-1
lines changed

5 files changed

+152
-1
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
routes.RecommendationRoutes(r)
2626
routes.ClassroomRoutesStudent(r)
2727
routes.ClassroomRoutesTeacher(r)
28+
routes.StudyfeatRoutes(r)
2829

2930
port := "8080"
3031

internal/controllers/quiz_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
func PostQuizBot() gin.HandlerFunc {
1919
return func(c *gin.Context) {
20-
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
20+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
2121
defer cancel()
2222

2323
var requestBody utils.QuizInput
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package controllers
2+
3+
import (
4+
"backend/internal/config"
5+
"backend/internal/utils"
6+
"context"
7+
"io"
8+
"net/http"
9+
"time"
10+
11+
"github.com/gin-gonic/gin"
12+
)
13+
14+
func PostPdfSummariser() gin.HandlerFunc {
15+
return func(c *gin.Context) {
16+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
17+
defer cancel()
18+
19+
var requestBody utils.PdfSummariserInput
20+
if err := c.BindJSON(&requestBody); err != nil {
21+
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
22+
return
23+
}
24+
25+
pdfurl := requestBody.PdfUrl
26+
req, err := http.NewRequestWithContext(ctx, "POST", config.BaseURL+"/v2/summarise/?pdf_url="+string(pdfurl), nil)
27+
if err != nil {
28+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create request"})
29+
return
30+
}
31+
req.Header.Set("Content-Type", "application/json")
32+
33+
client := &http.Client{}
34+
resp, err := client.Do(req)
35+
if err != nil {
36+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to send request"})
37+
return
38+
}
39+
defer resp.Body.Close()
40+
41+
body, err := io.ReadAll(resp.Body)
42+
if err != nil {
43+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read response"})
44+
return
45+
}
46+
47+
c.Data(resp.StatusCode, "application/json", body)
48+
}
49+
}
50+
51+
func PostYoutubeVideoSummariser() gin.HandlerFunc {
52+
return func(c *gin.Context) {
53+
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Second)
54+
defer cancel()
55+
56+
var requestBody utils.YoutubeVideoSummariserInput
57+
if err := c.BindJSON(&requestBody); err != nil {
58+
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
59+
return
60+
}
61+
62+
youtubeUrl := requestBody.YoutubeUrl
63+
req, err := http.NewRequestWithContext(ctx, "POST", config.BaseURL+"/v2/summarise-youtube/?youtube_url="+string(youtubeUrl), nil)
64+
if err != nil {
65+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create request"})
66+
return
67+
}
68+
req.Header.Set("Content-Type", "application/json")
69+
70+
client := &http.Client{}
71+
resp, err := client.Do(req)
72+
if err != nil {
73+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to send request"})
74+
return
75+
}
76+
defer resp.Body.Close()
77+
78+
body, err := io.ReadAll(resp.Body)
79+
if err != nil {
80+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read response"})
81+
return
82+
}
83+
84+
c.Data(resp.StatusCode, "application/json", body)
85+
}
86+
}
87+
88+
func PostGenerateMindMap() gin.HandlerFunc {
89+
return func(c *gin.Context) {
90+
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
91+
defer cancel()
92+
93+
var requestBody utils.MindMapInput
94+
if err := c.BindJSON(&requestBody); err != nil {
95+
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
96+
return
97+
}
98+
99+
topic := requestBody.Topic
100+
req, err := http.NewRequestWithContext(ctx, "POST", config.BaseURL+"/v2/generate_mindmap/"+string(topic), nil)
101+
if err != nil {
102+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to create request"})
103+
return
104+
}
105+
req.Header.Set("Content-Type", "application/json")
106+
107+
client := &http.Client{}
108+
resp, err := client.Do(req)
109+
if err != nil {
110+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to send request"})
111+
return
112+
}
113+
defer resp.Body.Close()
114+
115+
body, err := io.ReadAll(resp.Body)
116+
if err != nil {
117+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read response"})
118+
return
119+
}
120+
121+
c.Data(resp.StatusCode, "application/json", body)
122+
}
123+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package routes
2+
3+
import (
4+
"backend/internal/controllers"
5+
6+
"github.com/gin-gonic/gin"
7+
)
8+
9+
func StudyfeatRoutes(r *gin.Engine) {
10+
11+
r.POST("/studyfeat/summarise/pdf", controllers.PostPdfSummariser())
12+
r.POST("/studyfeat/summarise/youtube", controllers.PostYoutubeVideoSummariser())
13+
r.POST("/studyfeat/mindmap", controllers.PostGenerateMindMap())
14+
15+
}

internal/utils/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,15 @@ type SignedDetailsTeacher struct {
112112
SchoolCode string
113113
jwt.StandardClaims
114114
}
115+
116+
type PdfSummariserInput struct {
117+
PdfUrl string `json:"pdf_url"`
118+
}
119+
120+
type YoutubeVideoSummariserInput struct {
121+
YoutubeUrl string `json:"youtube_url"`
122+
}
123+
124+
type MindMapInput struct {
125+
Topic string `json:"topic"`
126+
}

0 commit comments

Comments
 (0)