Skip to content

Commit 3c9f096

Browse files
changes in ecommerce module
1 parent 83f3610 commit 3c9f096

File tree

7 files changed

+1765
-1143
lines changed

7 files changed

+1765
-1143
lines changed

controller/ecommerce.go

Lines changed: 105 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func EcommerceProductList(db *gorm.DB, ctx context.Context, limit int, offset in
5454
startingPrice = *filter.StartingPrice.Value()
5555
}
5656

57-
if !filter.EndingPrice.IsSet() {
57+
if filter.EndingPrice.IsSet() {
5858

5959
endingPrice = *filter.EndingPrice.Value()
6060
}
@@ -65,34 +65,34 @@ func EcommerceProductList(db *gorm.DB, ctx context.Context, limit int, offset in
6565
}
6666
}
6767

68-
if categoryName!=""{
68+
if categoryName != "" {
6969

7070
listQuery = listQuery.Where("tbl_categories.category_name = ?", categoryName)
7171

72-
} else if categoryId !=0 {
72+
} else if categoryId != 0 {
7373

7474
listQuery = listQuery.Where("tbl_categories.id = ?", categoryId)
7575
}
7676

77-
if releaseDate!="" {
77+
if releaseDate != "" {
7878

7979
listQuery = listQuery.Where("tbl_ecom_products.created_on >= ?", releaseDate)
8080
}
8181

82-
if startingPrice!=0 && endingPrice!=0 {
82+
if startingPrice != 0 && endingPrice != 0 {
8383

8484
listQuery = listQuery.Where("tbl_ecom_products.product_price between (?) and (?)", startingPrice, endingPrice)
8585

86-
} else if startingPrice!=0 {
86+
} else if startingPrice != 0 {
8787

8888
listQuery = listQuery.Where("tbl_ecom_products.product_price >= ?", startingPrice)
8989

90-
} else if endingPrice!=0 {
90+
} else if endingPrice != 0 {
9191

9292
listQuery = listQuery.Where("tbl_ecom_products.product_price <= ?", endingPrice)
9393
}
9494

95-
if searchKeyword!="" {
95+
if searchKeyword != "" {
9696

9797
listQuery = listQuery.Where("LOWER(TRIM(tbl_ecom_products.product_name)) ILIKE LOWER(TRIM(?))", "%"+searchKeyword+"%")
9898
}
@@ -306,7 +306,7 @@ func EcommerceAddToCart(db *gorm.DB, ctx context.Context, productID *int, produc
306306

307307
var count int64
308308

309-
if err := db.Table("tbl_ecom_carts").Where("is_deleted = 0 and customer_id = ? and product_id = ?", customer_id, productId).Count(&count).Error; err != nil {
309+
if err := db.Debug().Table("tbl_ecom_carts").Where("is_deleted = 0 and customer_id = ? and product_id = ?", customer_id, productId).Count(&count).Error; err != nil {
310310

311311
c.AbortWithError(http.StatusInternalServerError, err)
312312

@@ -315,7 +315,7 @@ func EcommerceAddToCart(db *gorm.DB, ctx context.Context, productID *int, produc
315315

316316
query := db.Table("tbl_ecom_carts")
317317

318-
if count != 0 {
318+
if count > 0 {
319319

320320
query = query.Where("is_deleted = 0 and customer_id = ? and product_id = ?", customer_id, productId).UpdateColumns(map[string]interface{}{"quantity": gorm.Expr("quantity + ?", cart.Quantity), "modified_on": currentTime})
321321

@@ -411,14 +411,14 @@ func EcommerceCartList(db *gorm.DB, ctx context.Context, limit, offset int) (*mo
411411

412412
}
413413

414-
if *cartProduct.ProductYoutubePath != "" {
414+
if cartProduct.ProductYoutubePath != nil {
415415

416416
modified_path := PathUrl + strings.TrimPrefix(*cartProduct.ProductYoutubePath, "/")
417417

418418
cartProduct.ProductYoutubePath = &modified_path
419419
}
420420

421-
if *cartProduct.ProductVimeoPath != "" {
421+
if cartProduct.ProductVimeoPath != nil {
422422

423423
modified_path := PathUrl + strings.TrimPrefix(*cartProduct.ProductVimeoPath, "/")
424424

@@ -515,11 +515,13 @@ func EcommerceProductOrdersList(db *gorm.DB, ctx context.Context, limit int, off
515515

516516
var count int64
517517

518-
query := db.Debug().Table("tbl_ecom_products as p").Joins("inner join tbl_ecom_product_order_details d on d.product_id = p.id").Joins("inner join tbl_ecom_product_orders o on o.id = d.order_id").Joins("inner join tbl_ecom_customers c on c.id = o.customer_id").Joins("inner join tbl_ecom_order_statuses s on s.order_id = o.id").Where("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?", memberid)
518+
query := db.Debug().Table("tbl_ecom_products as p").Joins("inner join tbl_ecom_product_order_details d on d.product_id = p.id").Joins("inner join tbl_ecom_product_orders o on o.id = d.order_id").Joins("inner join tbl_ecom_customers c on c.id = o.customer_id").Where("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?", memberid)
519519

520-
var status, searchKeyword, orderId, startingDate, endingDate string
520+
var (
521+
status, searchKeyword, orderId, startingDate, endingDate string
521522

522-
var startingPrice, endingPrice int
523+
startingPrice, endingPrice, orderHistory, upcomingOrders int
524+
)
523525

524526
if filter != nil {
525527

@@ -558,48 +560,66 @@ func EcommerceProductOrdersList(db *gorm.DB, ctx context.Context, limit int, off
558560
orderId = *filter.OrderID.Value()
559561
}
560562

563+
if filter.OrderHistory.IsSet(){
564+
565+
orderHistory = *filter.OrderHistory.Value()
566+
}
567+
568+
if filter.UpcomingOrders.IsSet(){
569+
570+
upcomingOrders = *filter.UpcomingOrders.Value()
571+
}
572+
561573
}
562574

563-
if status != "" {
575+
if upcomingOrders == 1{
564576

565-
query = query.Where("s.order_status = ?", filter.Status.Value())
577+
query = query.Where("o.status in (?)", []string{"placed", "outofdelivery", "shipped"})
578+
579+
}else if orderHistory==1{
580+
581+
query = query.Where("o.status in (?)", []string{"delivered", "cancelled"})
582+
583+
}else if status != "" {
584+
585+
query = query.Where("o.status = ?", status)
566586
}
567587

568588
if startingPrice != 0 && endingPrice != 0 {
569589

570-
query = query.Where("d.price between ? and ?", filter.StartingPrice.Value(), filter.EndingPrice.Value())
590+
query = query.Where("d.price between ? and ?", startingPrice, endingPrice)
571591

572592
} else if startingPrice != 0 {
573593

574-
query = query.Where("d.price >= ?", filter.StartingPrice.Value())
594+
query = query.Where("d.price >= ?", startingPrice)
575595

576596
} else if endingPrice != 0 {
577597

578-
query = query.Where("d.price <= ?", filter.EndingPrice.Value())
598+
query = query.Where("d.price <= ?", endingPrice)
579599

580600
}
581601

582602
if searchKeyword != "" {
583603

584-
query = query.Where("LOWER(TRIM(p.product_name)) ILIKE LOWER(TRIM(?))", "%"+*filter.SearchKeyword.Value()+"%")
604+
query = query.Where("LOWER(TRIM(p.product_name)) ILIKE LOWER(TRIM(?))", "%"+searchKeyword+"%")
585605
}
586606

587607
if startingDate != "" && endingDate != "" {
588608

589-
query = query.Where("o.created_on between ? and ?", filter.StartingDate.Value(), filter.EndingDate.Value())
609+
query = query.Where("o.created_on between ? and ?", startingDate, endingDate)
590610

591611
} else if startingDate != "" {
592612

593-
query = query.Where("o.created_on >= ?", filter.StartingDate.Value())
613+
query = query.Where("o.created_on >= ?", startingDate)
594614

595615
} else if endingDate != "" {
596616

597-
query = query.Where("o.created_on <= ?", filter.EndingDate.Value())
617+
query = query.Where("o.created_on <= ?", endingDate)
598618
}
599619

600620
if orderId != "" {
601621

602-
query = query.Where("o.uuid = ?", filter.OrderID.Value())
622+
query = query.Where("o.uuid = ?", orderId)
603623
}
604624

605625
if err := query.Count(&count).Error; err != nil {
@@ -644,7 +664,7 @@ func EcommerceProductOrdersList(db *gorm.DB, ctx context.Context, limit int, off
644664

645665
if err := query.Select("p.*").Preload("OrderDetails", func(db *gorm.DB) *gorm.DB {
646666

647-
return db.Debug().Select("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid").Joins("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id").Joins("inner join tbl_ecom_order_payments pm on pm.order_id = o.id")
667+
return db.Debug().Select("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid,o.shipping_address").Joins("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id").Joins("inner join tbl_ecom_order_payments pm on pm.order_id = o.id")
648668

649669
}).Limit(limit).Offset(offset).Find(&orderedProducts).Error; err != nil {
650670

@@ -708,7 +728,7 @@ func EcommerceProductOrderDetails(db *gorm.DB, ctx context.Context, productID *i
708728

709729
var orderedProduct model.EcommerceProduct
710730

711-
query := db.Debug().Table("tbl_ecom_products as p").Joins("inner join tbl_ecom_product_order_details d on d.product_id = p.id").Joins("inner join tbl_ecom_product_orders o on o.id = d.order_id").Joins("inner join tbl_ecom_customers c on c.id = o.customer_id").Joins("inner join tbl_ecom_order_statuses s on s.order_id = o.id").Where("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?", memberid)
731+
query := db.Debug().Table("tbl_ecom_products as p").Joins("inner join tbl_ecom_product_order_details d on d.product_id = p.id").Joins("inner join tbl_ecom_product_orders o on o.id = d.order_id").Joins("inner join tbl_ecom_customers c on c.id = o.customer_id").Where("p.is_deleted = 0 and o.is_deleted = 0 and c.member_id=?", memberid)
712732

713733
if productID != nil {
714734

@@ -721,7 +741,7 @@ func EcommerceProductOrderDetails(db *gorm.DB, ctx context.Context, productID *i
721741

722742
if err := query.Select("p.*").Preload("OrderDetails", func(db *gorm.DB) *gorm.DB {
723743

724-
return db.Debug().Select("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid").Joins("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id").Joins("inner join tbl_ecom_order_payments pm on pm.order_id = o.id")
744+
return db.Debug().Select("tbl_ecom_product_order_details.*,o.status,pm.payment_mode,o.uuid,o.shipping_address").Joins("inner join tbl_ecom_product_orders o on o.id = tbl_ecom_product_order_details.order_id").Joins("inner join tbl_ecom_order_payments pm on pm.order_id = o.id")
725745

726746
}).First(&orderedProduct).Error; err != nil {
727747

@@ -896,7 +916,7 @@ func EcommerceOrderPlacement(db *gorm.DB, ctx context.Context, paymentMode strin
896916
return false, err
897917
}
898918

899-
if err := db.Table("tbl_ecom_carts").Where("is_deleted = 0 and product_id in (?) and customer_id = ?",orderedProductIds,customerId).UpdateColumns(map[string]interface{}{"is_deleted": 1, "deleted_on": currentTime}).Error; err != nil {
919+
if err := db.Table("tbl_ecom_carts").Where("is_deleted = 0 and product_id in (?) and customer_id = ?", orderedProductIds, customerId).UpdateColumns(map[string]interface{}{"is_deleted": 1, "deleted_on": currentTime}).Error; err != nil {
900920

901921
c.AbortWithError(http.StatusInternalServerError, err)
902922

@@ -905,3 +925,59 @@ func EcommerceOrderPlacement(db *gorm.DB, ctx context.Context, paymentMode strin
905925

906926
return true, nil
907927
}
928+
929+
func EcommerceCustomerDetails(db *gorm.DB, ctx context.Context) (*model.CustomerDetails, error) {
930+
931+
c, _ := ctx.Value(ContextKey).(*gin.Context)
932+
933+
memberid, _ := c.Get("memberid")
934+
935+
if memberid == 0 {
936+
937+
err := errors.New("unauthorized access")
938+
939+
c.AbortWithError(http.StatusUnauthorized, err)
940+
941+
return &model.CustomerDetails{}, err
942+
943+
}
944+
945+
var customerDetails model.CustomerDetails
946+
947+
if err := db.Table("tbl_ecom_customers").Where("is_deleted = 0 and member_id = ?", memberid).First(&customerDetails).Error; err != nil {
948+
949+
return &model.CustomerDetails{}, err
950+
}
951+
952+
if customerDetails.ProfileImagePath != nil {
953+
954+
modified_path := PathUrl + strings.TrimPrefix(*customerDetails.ProfileImagePath, "/")
955+
956+
customerDetails.ProfileImagePath = &modified_path
957+
}
958+
959+
if customerDetails.StreetAddress != nil {
960+
961+
houseDetails := strings.Split(*customerDetails.StreetAddress, ",")
962+
963+
customerDetails.HouseNo = &houseDetails[0]
964+
965+
var area string
966+
967+
for index,cut := range houseDetails{
968+
969+
if index == 1{
970+
971+
area = area + cut
972+
973+
}else if index >1{
974+
975+
area = area + "," + cut
976+
}
977+
}
978+
979+
customerDetails.Area = &area
980+
}
981+
982+
return &customerDetails, nil
983+
}

graph/ecommerce.resolvers.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)