From fd5d82b1be02bb479aad419745d5f5d418a098c4 Mon Sep 17 00:00:00 2001 From: GURUAKASH-MUTHURAJAN Date: Mon, 11 Mar 2024 20:33:58 +0530 Subject: [PATCH] addded home api --- controller/main.go | 17 ++++++----------- models/models.go | 4 ++++ router/main.go | 1 - service/mail.go | 2 +- service/service.go | 1 + 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/controller/main.go b/controller/main.go index 7315f6c..f83c748 100644 --- a/controller/main.go +++ b/controller/main.go @@ -150,13 +150,9 @@ func Inventory(c *gin.Context) { } -var SearchName string -func Getallinventorydata(c *gin.Context) { - fmt.Println(SearchName) - result := service.Search(SearchName) - c.JSON(http.StatusOK, result) -} + + func ValidateToken(c *gin.Context) { var userdata models.Userdata @@ -171,15 +167,14 @@ func ValidateToken(c *gin.Context) { } func Search(c *gin.Context) { - type Search struct { - ProductName string `json:"productName" bson:"productName"` - } - var search Search + var search models.Search if err := c.BindJSON(&search); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"}) return } - SearchName = search.ProductName + result := service.Search(search.ProductName) + c.JSON(http.StatusOK, gin.H{"data":result}) + } func Update(c *gin.Context) { diff --git a/models/models.go b/models/models.go index b0e06a7..88508b8 100644 --- a/models/models.go +++ b/models/models.go @@ -285,3 +285,7 @@ type Block struct { Email string `json:"email" bson:"email"` Collection string `json:"collection" bson:"collection"` } + +type Search struct { + ProductName string `json:"productName" bson:"productName"` +} diff --git a/router/main.go b/router/main.go index b10bf45..2481944 100644 --- a/router/main.go +++ b/router/main.go @@ -44,7 +44,6 @@ func Router() *gin.Engine { router.POST("/inventory", controller.Inventory) router.POST("/search", controller.Search) router.POST("/update", controller.Update) - router.GET("/inventorydata", controller.Getallinventorydata) router.POST("/sellercheck", controller.CheckSeller) router.POST("/deleteproduct", controller.DeleteProduct) router.POST("/deleteproductbyseller", controller.DeleteProductBySeller) diff --git a/service/mail.go b/service/mail.go index 71c8a1d..ec92aee 100644 --- a/service/mail.go +++ b/service/mail.go @@ -56,7 +56,7 @@ func (sender *GmailSender) SendEmail( } func SendEmailforCustomerVerification(toEmail, id, name string) { - sender := NewGmailSender("GURUAKAKSH SM", "guruakash.ec20@bitsathy.ac.in", "snuk gatz ohoa agyt") + sender := NewGmailSender("GURUAKAKSH SM", "guruakash.ec20@bitsathy.ac.in", "") subject := "A test Email" htmlTemplate := ` diff --git a/service/service.go b/service/service.go index 05f5a49..853af4a 100644 --- a/service/service.go +++ b/service/service.go @@ -100,6 +100,7 @@ func Search(productName string) []models.Inventory1 { Inventory = append(Inventory, inventory) } + return Inventory } func Getalldata() []models.Customer {