Skip to content

Commit

Permalink
add: UpdateOrderStatusAndNote()
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasfisal committed Nov 27, 2024
1 parent 294ad72 commit b1779d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/modules/admin/repositories/order/order_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"go.mongodb.org/mongo-driver/mongo"
"gorm.io/gorm"
"shop/internal/entities"
"shop/internal/modules/admin/requests"
"shop/internal/pkg/pagination"
"strconv"
"strings"
)

type OrderRepository struct {
Expand Down Expand Up @@ -111,3 +113,27 @@ func (oRepo OrderRepository) FindOrderBy(c *gin.Context, orderID int) (entities.

return order, customer, nil
}

func (oRepo OrderRepository) UpdateOrderStatusAndNote(c *gin.Context, orderID int, req requests.UpdateOrderStatus) error {
var order entities.Order
if err := oRepo.db.WithContext(c).Where("id=?", orderID).First(&order).Error; err != nil {
return gorm.ErrRecordNotFound
}

// عدد منفی یک به این معنی هست که که ادمین نمیخواهد حالت پیشفرض وضعیت سفارش را تغییر دهد
if req.Status != -1 {
// بررسی معتبر بودن وضعیت سفارش
//if req.Status < int(entities.OrderPending) || req.Status > int(entities.OrderCompleted) {
// return fmt.Errorf("وضعیت سفارش نامعتبر است")
//}
order.OrderStatus = uint(req.Status)
}
if req.Note != "" {
order.Note = strings.TrimSpace(req.Note)
}

if err := oRepo.db.WithContext(c).Save(&order).Error; err != nil {
return err
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package order
import (
"github.com/gin-gonic/gin"
"shop/internal/entities"
"shop/internal/modules/admin/requests"
"shop/internal/pkg/pagination"
)

type OrderRepositoryInterface interface {
GetOrders(c *gin.Context) (pagination.Pagination, error)
FindOrderBy(c *gin.Context, orderID int) (entities.Order, entities.Customer, error)
UpdateOrderStatusAndNote(c *gin.Context, orderID int, req requests.UpdateOrderStatus) error
}

0 comments on commit b1779d9

Please sign in to comment.