Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tdatIT committed Jul 10, 2024
1 parent 19ed532 commit 828f648
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module latipe-order-service-v2

go 1.20
go 1.21

toolchain go1.22.2

require (
github.com/Pacific73/gorm-cache v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions internal/infrastructure/persistence/order/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (g GormRepository) FindAll(ctx context.Context, query *pagable.Query) ([]en
Preload("OrderItem").
Preload("Delivery").
Where(whereState).
Order("created_at desc").
Limit(query.GetLimit()).Offset(query.GetOffset()).
Find(&orders).Error
}, ctx)
Expand Down Expand Up @@ -152,6 +153,7 @@ func (g GormRepository) FindOrderByStoreID(ctx context.Context, storeId string,
Where("orders.store_id=?", storeId).
Where(whereState).
Where(likeState).
Order("created_at desc").
Limit(query.GetLimit()).Offset(query.GetOffset()).
Find(&orders).Error

Expand Down
25 changes: 19 additions & 6 deletions internal/services/commands/orderCmd/order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"latipe-order-service-v2/internal/domain/dto/order/store"
"latipe-order-service-v2/internal/domain/entities/order"
"latipe-order-service-v2/internal/domain/msgDTO"
"latipe-order-service-v2/internal/infrastructure/adapter/deliveryserv"
"latipe-order-service-v2/internal/infrastructure/adapter/storeserv"
dto2 "latipe-order-service-v2/internal/infrastructure/adapter/storeserv/dto"
voucherConst "latipe-order-service-v2/internal/infrastructure/adapter/vouchersev/dto"
Expand Down Expand Up @@ -41,15 +42,16 @@ type orderCommandService struct {
deliveryGrpc deliverygrpc.DeliveryServiceClient
userGrpc usergrpc.UserServiceClient
//rest call
storeServ storeserv.Service
storeServ storeserv.Service
deliveryServ deliveryserv.Service
}

func NewOrderCommandService(cfg *config.Config, orderRepo order.OrderRepository,
commissionRepo order.CommissionRepository,
cacheEngine *cacheV9.CacheEngine, publisher *publishMsg.PublisherTransactionMessage,
voucherGrpc vouchergrpc.VoucherServiceClient, productGrpc productgrpc.ProductServiceClient,
deliveryGrpc deliverygrpc.DeliveryServiceClient, userGrpc usergrpc.UserServiceClient, notifyPub *publishMsg.NotificationMessagePublisher,
storeServ storeserv.Service) OrderCommandUsecase {
storeServ storeserv.Service, deliveryServ deliveryserv.Service) OrderCommandUsecase {
return orderCommandService{
orderRepo: orderRepo,
commissionRepo: commissionRepo,
Expand All @@ -61,6 +63,7 @@ func NewOrderCommandService(cfg *config.Config, orderRepo order.OrderRepository,
productGrpc: productGrpc,
userGrpc: userGrpc,
storeServ: storeServ,
deliveryServ: deliveryServ,
notifyPub: notifyPub,
}
}
Expand Down Expand Up @@ -358,13 +361,15 @@ func (o orderCommandService) StoreUpdateOrderStatus(ctx context.Context, dto *st
}

var bodyContent string
deliMessage := false

switch dto.Status {
case order.ORDER_PREPARED:
if err := o.orderRepo.UpdateStatus(ctx, orderDAO.OrderID, order.ORDER_PREPARED); err != nil {
return err
}

deliMessage = true
bodyContent = fmt.Sprintf("Xin chào, đơn hàng của bạn đã được cửa hàng xác nhận #[%v]", orderDAO.OrderID)
case order.ORDER_CANCEL_BY_STORE:
if err := o.orderRepo.UpdateStatus(ctx, orderDAO.OrderID, order.ORDER_CANCEL_BY_STORE,
Expand All @@ -377,13 +382,21 @@ func (o orderCommandService) StoreUpdateOrderStatus(ctx context.Context, dto *st
return errors.OrderCannotUpdate
}

userNoti := msgDTO.NewNotificationMessage(msgDTO.NOTIFY_USER, orderDAO.UserId, "[Latipe] Thông báo tình trạng đơn hàng", bodyContent, orderDAO.Thumbnail)

//send message to user
userNoti := msgDTO.NewNotificationMessage(msgDTO.NOTIFY_USER, orderDAO.UserId, "[Latipe] Thông báo tình trạng đơn hàng", bodyContent, orderDAO.Thumbnail)
if err := o.notifyPub.NotifyToUser(userNoti); err != nil {
return err
log.Error(err)
}
// send to deli
if deliMessage {
var err error
deliNoti := msgDTO.NewNotificationMessage(msgDTO.NOTIFY_USER, orderDAO.Delivery.DeliveryId, "[Latipe] Thông báo tình trạng đơn hàng",
fmt.Sprintf("Bạn có đơn hàng chờ vận chuyển [%v]", strings.ToUpper(orderDAO.OrderID)),
orderDAO.Thumbnail)
if err = o.notifyPub.NotifyToUser(deliNoti); err != nil {
log.Error(err)
}
}

return nil
}

Expand Down
11 changes: 2 additions & 9 deletions internal/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 828f648

Please sign in to comment.