Customer Order
This commit is contained in:
@@ -3,7 +3,6 @@ package brevo
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"furtuna-be/internal/entity"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
@@ -77,12 +76,5 @@ func New(conf Config) *ServiceImpl {
|
||||
cfg := brevo.NewConfiguration()
|
||||
cfg.AddDefaultHeader("api-key", conf.GetApiKey())
|
||||
client := brevo.NewAPIClient(cfg)
|
||||
result, resp, err := client.AccountApi.GetAccount(context.Background())
|
||||
if err != nil {
|
||||
fmt.Println("Error when calling AccountApi->get_account: ", err.Error())
|
||||
log.Fatal("error")
|
||||
}
|
||||
fmt.Println("GetAccount Object:", result, " GetAccount Response: ", resp)
|
||||
|
||||
return &ServiceImpl{brevoConn: client}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,14 @@ func (c *ClientService) CreatePayment(order entity.MidtransRequest) (*entity.Mid
|
||||
Client: c.client,
|
||||
}
|
||||
|
||||
paymentMethod := []midtrans.PaymentType{}
|
||||
|
||||
if order.PaymentMethod == "GOPAY" {
|
||||
paymentMethod = append(paymentMethod, midtrans.SourceGopay)
|
||||
}
|
||||
|
||||
snapReq := &midtrans.SnapReq{
|
||||
EnabledPayments: []midtrans.PaymentType{
|
||||
midtrans.SourceGopay,
|
||||
},
|
||||
EnabledPayments: paymentMethod,
|
||||
TransactionDetails: midtrans.TransactionDetails{
|
||||
OrderID: order.PaymentReferenceID,
|
||||
GrossAmt: order.TotalAmount,
|
||||
|
||||
@@ -48,9 +48,13 @@ func (r *OrderRepository) UpdateStatus(ctx context.Context, orderID int64, statu
|
||||
func (r *OrderRepository) FindByID(ctx context.Context, id int64) (*entity.Order, error) {
|
||||
var order entity.Order
|
||||
|
||||
err := r.db.WithContext(ctx).Preload("OrderItems", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("Product")
|
||||
}).First(&order, id).Error
|
||||
err := r.db.WithContext(ctx).
|
||||
Preload("OrderItems", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Preload("Product")
|
||||
}).
|
||||
Preload("User").
|
||||
Preload("Payment").
|
||||
First(&order, id).Error
|
||||
|
||||
if err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when finding order by ID", zap.Error(err))
|
||||
@@ -99,11 +103,15 @@ func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.Or
|
||||
query = query.Where("orders.payment_type = ?", req.PaymentType)
|
||||
}
|
||||
|
||||
if req.CreatedBy != 0 {
|
||||
query = query.Where("orders.created_by = ?", req.CreatedBy)
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
query = query.Where("orders.status = ?", req.Status)
|
||||
}
|
||||
|
||||
if !req.IsAdmin {
|
||||
if !req.IsAdmin && !req.IsCustomer {
|
||||
query = query.Where("orders.partner_id = ?", req.PartnerID)
|
||||
}
|
||||
|
||||
@@ -142,7 +150,7 @@ func (b *OrderRepository) GetAllHystoryOrders(ctx context.Context, req entity.Or
|
||||
query = query.Limit(req.Limit)
|
||||
}
|
||||
|
||||
if err := query.Scan(&orders).Error; err != nil {
|
||||
if err := query.Debug().Scan(&orders).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get all history orders", zap.Error(err))
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@@ -55,6 +55,16 @@ func (b *ProductRepository) GetProductByPartnerIDAndSiteID(ctx context.Context,
|
||||
return products, nil
|
||||
}
|
||||
|
||||
func (b *ProductRepository) GetProductsBySiteID(ctx context.Context, siteID int64) (entity.ProductList, error) {
|
||||
var products []*entity.ProductDB
|
||||
if err := b.db.WithContext(ctx).Where("site_id = ?", siteID).Find(&products).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when finding product by partner ID and site id", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return products, nil
|
||||
}
|
||||
|
||||
func (b *ProductRepository) GetAllProducts(ctx context.Context, req entity.ProductSearch) (entity.ProductList, int, error) {
|
||||
var products []*entity.ProductDB
|
||||
var total int64
|
||||
|
||||
@@ -135,6 +135,7 @@ type Product interface {
|
||||
GetAllProducts(ctx context.Context, req entity.ProductSearch) (entity.ProductList, int, error)
|
||||
DeleteProduct(ctx context.Context, id int64) error
|
||||
GetProductsByIDs(ctx context.Context, ids []int64, partnerID int64) ([]*entity.ProductDB, error)
|
||||
GetProductsBySiteID(ctx context.Context, siteID int64) (entity.ProductList, error)
|
||||
}
|
||||
|
||||
type Order interface {
|
||||
|
||||
@@ -35,11 +35,13 @@ func (r *UserRepository) Create(ctx context.Context, user *entity.UserDB) (*enti
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userRole := user.ToUserRoleDB()
|
||||
if err := tx.Create(userRole).Error; err != nil {
|
||||
tx.Rollback()
|
||||
logError(ctx, "creating user role", err)
|
||||
return nil, err
|
||||
if user.UserType != "CUSTOMER" {
|
||||
userRole := user.ToUserRoleDB()
|
||||
if err := tx.Create(userRole).Error; err != nil {
|
||||
tx.Rollback()
|
||||
logError(ctx, "creating user role", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Commit().Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user