-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (55 loc) · 1.8 KB
/
main.go
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
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
repository := NewRepository()
reviews, err := repository.GetReviewsData()
if err != nil {
return
}
for _, line := range reviews {
reviews = append(reviews, ReviewData{
Comment: line.Comment,
Class: line.Class, //'1'. sutun
})
}
positiveReview := []string{}
negativeReview := []string{}
for _, item := range reviews { //sadece reviewleri alma ve ayırma
if item.Class == "positive" {
positiveReview = append(positiveReview, item.Comment)
}
if item.Class == "negative" {
negativeReview = append(negativeReview, item.Comment)
}
}
positiveReviewWords := preProcessReviews(positiveReview)
negativeReviewWords := preProcessReviews(negativeReview)
service := NewService(repository, positiveReviewWords, negativeReviewWords)
api := NewAPI(&service)
app := SetupApp(&api)
app.Listen(":3001")
}
func SetupApp(api *API) *fiber.App {
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowCredentials: true,
}))
app.Post("api/analyze", api.AnalyzeTextHandler)
app.Post("/api/comments", api.AddCommentHandler)
app.Get("/api/comments", api.GetCommentsHandler)
app.Get("/api/comments/:id", api.GetCommentHandler)
app.Delete("/api/comments/:id", api.DeleteCommentHandler)
app.Patch("/api/comments/:id", api.UpdateCommentHandler)
app.Post("/api/products", api.AddProductHandler)
app.Get("/api/products", api.GetProductsHandler)
app.Get("/api/products/:id", api.GetProductHandler)
app.Patch("/api/products/:id", api.UpdateProductHandler)
app.Patch("/api/products/:id/comments", api.AddProductCommentHandler)
app.Post("/api/users/register", api.CreateUserHandler)
app.Post("/api/users/login", api.LoginHandler)
app.Get("/api/user", api.UserHandler)
return app
}