Skip to content

Commit

Permalink
updating
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandpn committed Oct 12, 2023
1 parent f58bac8 commit ddb7376
Show file tree
Hide file tree
Showing 18 changed files with 596 additions and 59 deletions.
Binary file modified cmd/api/tmp/api.exe
Binary file not shown.
1 change: 0 additions & 1 deletion pkg/api/handler/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,6 @@ func (p *ProductHandler) GetProductByString(ctx *gin.Context) {
name := ctx.Query("name")
count, err1 := helper.StringToUInt(ctx.Query("count"))
pageNumber, err2 := helper.StringToUInt(ctx.Query("page_number"))

err1 = errors.Join(err1, err2)
if err1 != nil {
response := res.ErrorResponse(400, "invalid inputs", err1.Error(), nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/routes/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func AdminRoute(api *gin.RouterGroup,
product.GET("/all/name", ProductHandler.ProductGetByName)
product.GET("/all/price", ProductHandler.ProductGetByPrice)
product.GET("/all/quantity", ProductHandler.ProductGetByQuantity)
product.GET("/get/:name", ProductHandler.GetProductByString) // sort by string
product.GET("/get", ProductHandler.GetProductByString) // sort by string
}
// Category
category := api.Group("/category")
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func UserRoutes(api *gin.RouterGroup,
product.GET("/all/brand", productHandler.ProductGetByBrand)
product.GET("/all/name", productHandler.ProductGetByName)
product.GET("/all/price", productHandler.ProductGetByPrice)
product.GET("/get/:name", productHandler.GetProductByString)
product.GET("/get", productHandler.GetProductByString)

// List all product
product.GET("/all", productHandler.ListProducts)
Expand Down
1 change: 1 addition & 0 deletions pkg/repository/interface/paymentinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ type PaymentRepository interface {
GetPaymentStatusById(id uint) (domain.PaymentStatus, error)
GetAllPaymentStatus() ([]domain.PaymentStatus, error)
// -----------------------
AddPaymentDetail(oid uint, price float64, pmid uint, pstid uint) (uint, error)
}
4 changes: 4 additions & 0 deletions pkg/repository/interface/productinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ type ProductRepository interface {
ProductViewByPid(id uint) (res.ResProductOrder, error) // Find Produdct By Pinfo id
FindAllProductWithQuantity(pagination req.PageNation) ([]res.ProductQtyRes, error) // Find All product with quantity

// updated
FindProductPriceByProductInfoId(id uint) (float64, error)

// product images
AddProductImage(id uint, img string) error
FindImage(img string) (domain.ProductImage, error)
GetProductImage(id uint) (domain.ProductImage, error)

// opration
CreateProduct(product req.ReqProduct) error
Expand Down
14 changes: 13 additions & 1 deletion pkg/repository/interface/userinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ type UserRepository interface {
// Address
AddAddress(ctx context.Context, Uid uint, addres req.ReqAddress) error // Add Address
UpdateAddress(ctx context.Context, Uid uint, address req.ReqAddress) error // Update Address
ListAllAddress(ctx context.Context, Uid uint) ([]res.ResAddress, error) // Delete Address
ListAllAddress( Uid uint) ([]res.ResAddress, error) // get Address
GetAddressByUid(uid uint) (domain.Address, error) // get address
GetUserDefaultAddressId(uid uint) (domain.Address, error) // get default
GetAddressByAdrsId(uid, adrsId uint) (domain.Address, error)

// updated address
MakeAddressDefaultById(id uint) error
AddressRemoveDefaultById(id uint) error
CheckDefaultAddress(uid uint) (bool, error)
FindDefaultAddress(uid uint) (domain.Address, error)
GetAddressByName(name string, uid uint) (domain.Address, error)
GetAddressByHouseName(name string, uid uint) (domain.Address, error)
GetAddressByNumber(number string, uid uint) (domain.Address, error)
GetAddressByPinCode(code string, uid uint) (domain.Address, error)

// wishlist
CreateWishList(id uint) error
Expand Down
117 changes: 112 additions & 5 deletions pkg/repository/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (o *OrderDatabase) AddOrderInfo(orderId,
AdrsId,
CopId uint,
price float64,
status string,
status uint,
payId uint) (uint, error) {

var body domain.OrderInfo
Expand All @@ -68,10 +68,10 @@ func (o *OrderDatabase) AddOrderInfo(orderId,
return body.Id, nil
}

func (o *OrderDatabase) FindAllOrderInfoByUid(uid uint) (domain.OrderInfo, error) {
func (o *OrderDatabase) FindOrderInfoByUid(uid uint) (domain.OrderInfo, error) {

var body domain.OrderInfo
query := `select * from order_infos where user_id =$1`
query := `select * from order_infos where order_id = $1`
err := o.DB.Raw(query, uid).Scan(&body).Error
if err != nil {
return body, err
Expand All @@ -82,7 +82,7 @@ func (o *OrderDatabase) FindAllOrderInfoByUid(uid uint) (domain.OrderInfo, error
func (o *OrderDatabase) AddOrderItem(oid, pfid, qty uint) error {

var body domain.OrderItem
query := `insert into order_items (user_order_id,product_info_id,quantity)values ($1,$2,$3);`
query := `insert into order_items (order_info,product_info_id,quantity)values ($1,$2,$3);`
err := o.DB.Raw(query, oid, pfid, qty).Scan(&body).Error
if err != nil {
return err
Expand All @@ -93,7 +93,8 @@ func (o *OrderDatabase) AddOrderItem(oid, pfid, qty uint) error {
func (o *OrderDatabase) CartAllOrder(orderId, OrderinfoId uint, cart []res.CartDisplay) error {

for _, item := range cart {
query := "INSERT INTO order_items (order_id,order_info,product_info_id, quantity) VALUES ($1, $2,$3,$4);"
query := `INSERT INTO order_items (order_id,order_info,
product_info_id, quantity) VALUES ($1, $2,$3,$4);`

err := o.DB.Exec(query, orderId, OrderinfoId, item.Id, item.Quantity).Error

Expand Down Expand Up @@ -238,3 +239,109 @@ func (pr *OrderDatabase) GetAllOrderStatus() ([]domain.OrderStatus, error) {
}
return body, nil
}

// 01 - 09 - 2023 - Order status updation

func (o *OrderDatabase) ListALlOrderByUid(id uint) ([]domain.OrderInfo, error) {

var body []domain.OrderInfo
fmt.Println("-------- >", id)
query := `SELECT *
FROM order_infos
WHERE order_id = $1
ORDER BY order_time ASC;`
err := o.DB.Raw(query, id).Scan(&body).Error
if err != nil {
return body, err
}
return body, nil

}

func (o *OrderDatabase) UpdateOrderStatusToOrdered(id uint) error {

var body domain.OrderInfo
query := `update order_infos set order_status = 10 where id = $1;`
err := o.DB.Raw(query, id).Scan(&body).Error
if err != nil {
return err
}
return nil
}

func (o *OrderDatabase) UpdateOrderStatusToDelivered(id uint) error {

var body domain.OrderInfo
query := `update order_infos set order_status = 11 where id = $1;`
err := o.DB.Raw(query, id).Scan(&body).Error
if err != nil {
return err
}
return nil
}

func (o *OrderDatabase) UpdateOrderStatusToCancelled(id uint) error {

var body domain.OrderInfo
query := `UPDATE order_infos
SET order_status = 12
WHERE id = $1;`
err := o.DB.Raw(query, id).Scan(&body).Error
if err != nil {
return err
}
return nil
}

func (o *OrderDatabase) UpdateOrderStatusToReturned(id uint) error {

var body domain.OrderInfo
query := `update order_infos set order_status = 12 where id = $1;`
err := o.DB.Raw(query, id).Scan(&body).Error
if err != nil {
return err
}
return nil
}

func (o *OrderDatabase) ListOrderDetailByUid(uid uint) ([]res.OrderDetailByUid, error) {

var body []res.OrderDetailByUid
query := `SELECT
oi.id AS order_info_id,
oi.order_id,
oi.order_time,
a.id AS address_id,
a.house,
a.phone_number,
a.street,
a.city,
a.district,
a.pincode,
a.landmark,
a.name AS address_name,
oi.coupon_code,
ci.code AS coupon_name,
ci.discount_price AS coupon_discount,
oi.total_price,
os.status AS order_status,
pd.total_price AS payment_total_price,
pm.method AS payment_method,
ps.payment_status AS payment_status
FROM user_orders uo
JOIN order_infos oi ON uo.id = oi.order_id
JOIN addresses a ON oi.address_id = a.id
JOIN order_statuses os ON oi.order_status = os.id
JOIN payment_details pd ON oi.id = pd.order_id
JOIN payment_methods pm ON pd.payment_method_id = pm.id
JOIN payment_statuses ps ON pd.payment_status_id = ps.id
LEFT JOIN coupons ci ON oi.coupon_code = ci.id
WHERE uo.user_id = $1;`
err := o.DB.Raw(query, uid).Scan(&body).Error
if err != nil {
return body, err
}
return body, nil
}


22 changes: 22 additions & 0 deletions pkg/repository/payment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package repository

import (
"time"

"github.com/abhinandpn/project-ecom/pkg/domain"
interfaces "github.com/abhinandpn/project-ecom/pkg/repository/interface"
"gorm.io/gorm"
Expand Down Expand Up @@ -142,3 +144,23 @@ func (py *PaymentDatabase) GetAllPaymentStatus() ([]domain.PaymentStatus, error)
}
return body, nil
}

func (p *PaymentDatabase) AddPaymentDetail(oid uint,
price float64,
pmid uint,
pstid uint,
) (uint, error) {

var body domain.PaymentDetail
time := time.Now()
query := `insert into payment_details (order_id,
total_price,
payment_method_id,
payment_status_id,
updated_at)values ($1,$2,$3,$4,$5) returning id;`
err := p.DB.Raw(query, oid, price, pmid, pstid, time).Scan(&body).Error
if err != nil {
return body.Id, err
}
return body.Id, nil
}
Loading

0 comments on commit ddb7376

Please sign in to comment.