Skip to content

Commit

Permalink
updated seller api
Browse files Browse the repository at this point in the history
  • Loading branch information
GURUAKASH-MUTHURAJAN committed Mar 19, 2024
1 parent 20d4879 commit ad159c7
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 60 deletions.
140 changes: 109 additions & 31 deletions controller/Seller.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package controller

import (
"ecommerce/constants"
"ecommerce/models"
"ecommerce/service"
"fmt"
"log"
"net/http"

Expand All @@ -28,44 +26,33 @@ func CheckSeller(c *gin.Context) {
if success {
c.JSON(http.StatusOK, gin.H{"token": token})
return
}
}
if err != nil {
c.JSON(http.StatusOK, gin.H{"error": token})
return
}
if !success{
if !success {
c.JSON(http.StatusOK, gin.H{"message": token})
}


}

// Add Items to inventory
func Inventory(c *gin.Context) {
var inventory models.Inventory
if err := c.BindJSON(&inventory); err != nil {

log.Fatal(err)
log.Println(err)
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
fmt.Println(inventory)
sellerid, err := service.ExtractCustomerID(inventory.SellerId, constants.SecretKey)
if err != nil {
log.Fatal(err)
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid Token : while Extracting"})
}
inventory.SellerId = sellerid
success, err := service.Inventory(inventory)

message, err := service.Inventory(inventory)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal Server Error"})
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
if success {
c.JSON(http.StatusOK, gin.H{"data": success})
} else {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid credentials"})
}
c.JSON(http.StatusOK, gin.H{"message": message})

}

Expand Down Expand Up @@ -94,10 +81,72 @@ func DeleteProductBySeller(c *gin.Context) {

}

// Display Customer Order
// Display Customer All Orders
func Orders(c *gin.Context) {
data := service.Orders()
c.JSON(http.StatusOK, data)
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data, message, err := service.Orders(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})


}

// Display Customer Completed Orders
func CompletedOrders(c *gin.Context) {
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data, message, err := service.CompletedOrders(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})


}

// Display Customer Pending Orders
func PendingOrders(c *gin.Context) {
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data, message, err := service.PendingOrders(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})
}

// Yet to Deliver Orders
func YettoDeliverOrders(c *gin.Context) {
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data, message, err := service.YettoDeliverOrders(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})
}

// Delete Order
Expand All @@ -119,7 +168,7 @@ func DeleteOrder(c *gin.Context) {
}

// Signup Seller
func RegisterSeller(c *gin.Context){
func RegisterSeller(c *gin.Context) {
var register models.Seller
if err := c.BindJSON(&register); err != nil {

Expand All @@ -135,9 +184,8 @@ func RegisterSeller(c *gin.Context){
c.JSON(http.StatusOK, gin.H{"message": message})
}


// Verify Seller Email
func VerifySellerEmail(c *gin.Context){
func VerifySellerEmail(c *gin.Context) {
var register models.VerifyEmail
if err := c.BindJSON(&register); err != nil {

Expand All @@ -153,20 +201,50 @@ func VerifySellerEmail(c *gin.Context){
c.JSON(http.StatusOK, gin.H{"message": message})
}


// Data needed for Seller DrashBoard
func SellerDrashbordDetails(c *gin.Context){
func SellerDrashbordDetails(c *gin.Context) {
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data,message,err := service.SellerDrashbordDetails(token)
if err != nil{
data, message, err := service.SellerDrashbordDetails(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK , gin.H{"error":message})
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})
}

// Get All Products of seller
func GetAllProducts(c *gin.Context){
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data, message, err := service.GetAllProducts(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})
}

//List BuyedCustomer
func BuyedCustomer(c *gin.Context){
var token models.Token
if err := c.BindJSON(&token); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid JSON data"})
return
}
data, message, err := service.GetAllBuyedCustomer(token)
if err != nil {
log.Println(err)
c.JSON(http.StatusOK, gin.H{"error": message})
return
}
c.JSON(http.StatusOK, gin.H{"message": data})
}
7 changes: 1 addition & 6 deletions models/Seller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ type UpdateProduct struct {
New_Value int32 `json:"newvalue" bson:"newvalue"`
}

// Display Customer Order
type Customerorder struct {
Id string `json:"_id" bson:"_id"`
Itemstobuy []Item `json:"itemstobuy" bson:"itemstobuy"`
Address Address `json:"address" bson:"address"`
}



//Seller DrashBoardNeeded Details
Expand Down
7 changes: 6 additions & 1 deletion router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Router() *gin.Engine {
router.POST("/deletefeedback", controller.Deletefeedback)
router.POST("/buynow", controller.BuyNow)
router.POST("/totalamount", controller.TotalAmount)
router.GET("/orders",controller.Orders)
router.POST("/orders",controller.Orders)
router.POST("/deleteorder",controller.DeleteOrder)
router.POST("/customerorders",controller.CustomerOrder)
router.POST("/validatetoken", controller.ValidateToken)
Expand All @@ -74,6 +74,11 @@ func Router() *gin.Engine {
router.POST("/registerseller",controller.RegisterSeller)
router.POST("/verifyselleremail",controller.VerifySellerEmail)
router.POST("/sellerdrashboarddetails",controller.SellerDrashbordDetails)
router.POST("/getallproducts",controller.GetAllProducts)
router.POST("/buyedcustomer",controller.BuyedCustomer)
router.POST("/completedorders",controller.CompletedOrders)
router.POST("/pendingorders",controller.PendingOrders)
router.POST("/yettodeliverorders",controller.YettoDeliverOrders)


return router
Expand Down
Loading

0 comments on commit ad159c7

Please sign in to comment.