Update template email
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"enaklo-pos-be/internal/handlers/request"
|
||||
"enaklo-pos-be/internal/handlers/response"
|
||||
"enaklo-pos-be/internal/services"
|
||||
"enaklo-pos-be/internal/utils"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -22,7 +21,7 @@ type Handler struct {
|
||||
func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route := group.Group("/order")
|
||||
|
||||
route.POST("/inquiry", jwt, h.Inquiry)
|
||||
route.POST("/inquiry", h.Inquiry)
|
||||
route.POST("/execute", jwt, h.Execute)
|
||||
route.GET("/history", jwt, h.History)
|
||||
route.GET("/detail", jwt, h.Detail)
|
||||
@@ -104,20 +103,14 @@ func MapOrderToCreateOrderResponse(orderResponse *entity.OrderResponse, req requ
|
||||
|
||||
return response.CreateOrderResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
PaymentType: order.PaymentType,
|
||||
CreatedAt: order.CreatedAt,
|
||||
OrderItems: orderItems,
|
||||
Token: orderResponse.Token,
|
||||
Fee: order.Fee,
|
||||
Total: order.Total,
|
||||
VisitDate: order.VisitDate.Format("2006-01-02"),
|
||||
SiteName: order.Site.Name,
|
||||
BankCode: req.BankCode,
|
||||
BankName: utils.BankName(req.BankCode),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +129,6 @@ func MapOrderToExecuteOrderResponse(orderResponse *entity.ExecuteOrderResponse)
|
||||
|
||||
return response.ExecuteOrderResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
@@ -239,10 +231,6 @@ func (h *Handler) toOrderDetail(order *entity.Order) *response.OrderDetail {
|
||||
|
||||
qrCode := ""
|
||||
|
||||
if order.Status == "PAID" {
|
||||
qrCode = order.RefID
|
||||
}
|
||||
|
||||
var siteName string
|
||||
|
||||
if order.Site != nil {
|
||||
|
||||
@@ -214,7 +214,6 @@ func ConvertToProductResp(resp []*entity.Product) *response.SearchProductSiteRes
|
||||
productResp = append(productResp, response.SearchProductSiteByIDResponse{
|
||||
ID: res.ID,
|
||||
Name: res.Name,
|
||||
SiteID: res.SiteID,
|
||||
Price: res.Price,
|
||||
Description: res.Description,
|
||||
Type: res.Type,
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"enaklo-pos-be/internal/common/errors"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"enaklo-pos-be/internal/handlers/request"
|
||||
"enaklo-pos-be/internal/handlers/response"
|
||||
"enaklo-pos-be/internal/services/v2/order"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
service order.Service
|
||||
}
|
||||
|
||||
func NewOrderHandler(service order.Service) *Handler {
|
||||
return &Handler{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route := group.Group("/order")
|
||||
|
||||
route.POST("/inquiry", jwt, h.Inquiry)
|
||||
route.POST("/execute", jwt, h.Execute)
|
||||
}
|
||||
|
||||
type InquiryRequest struct {
|
||||
CustomerID *int64 `json:"customer_id"`
|
||||
CustomerName string `json:"customer_name" validate:"required_without=CustomerID"`
|
||||
CustomerEmail string `json:"customer_email"`
|
||||
CustomerPhoneNumber string `json:"customer_phone_number"`
|
||||
PaymentMethod string `json:"payment_method" validate:"required"`
|
||||
OrderItems []OrderItemRequest `json:"order_items" validate:"required,min=1,dive"`
|
||||
}
|
||||
|
||||
type OrderItemRequest struct {
|
||||
ProductID int64 `json:"product_id" validate:"required"`
|
||||
Quantity int `json:"quantity" validate:"required,min=1"`
|
||||
}
|
||||
|
||||
type ExecuteRequest struct {
|
||||
PaymentMethod string `json:"payment_method" validate:"required"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func (h *Handler) Inquiry(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
userID := ctx.RequestedBy()
|
||||
partnerID := ctx.GetPartnerID()
|
||||
|
||||
var req InquiryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(req); err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
orderItems := make([]entity.OrderItemRequest, len(req.OrderItems))
|
||||
for i, item := range req.OrderItems {
|
||||
orderItems[i] = entity.OrderItemRequest{
|
||||
ProductID: item.ProductID,
|
||||
Quantity: item.Quantity,
|
||||
}
|
||||
}
|
||||
|
||||
orderReq := &entity.OrderRequest{
|
||||
Source: "POS",
|
||||
CreatedBy: userID,
|
||||
PartnerID: *partnerID,
|
||||
PaymentMethod: req.PaymentMethod,
|
||||
OrderItems: orderItems,
|
||||
CustomerID: req.CustomerID,
|
||||
CustomerName: req.CustomerName,
|
||||
CustomerEmail: req.CustomerEmail,
|
||||
CustomerPhoneNumber: req.CustomerPhoneNumber,
|
||||
}
|
||||
|
||||
result, err := h.service.CreateOrderInquiry(ctx, orderReq)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.MapToInquiryResponse(result),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) Execute(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req ExecuteRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(req); err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.service.ExecuteOrderInquiry(ctx, req.Token, req.PaymentMethod)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.MapToOrderResponse(result),
|
||||
})
|
||||
}
|
||||
@@ -47,21 +47,15 @@ func (h *Handler) Inquiry(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.IsCasheer() {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// override the partner_id
|
||||
req.PartnerID = *ctx.GetPartnerID()
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(req); err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
order, err := h.service.CreateOrder(ctx, req.ToEntity(ctx.RequestedBy()))
|
||||
orderRequest := req.ToEntity(*ctx.GetPartnerID(), ctx.RequestedBy())
|
||||
|
||||
order, err := h.service.CreateOrder(ctx, orderRequest)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
@@ -206,7 +200,6 @@ func MapOrderToCreateOrderResponse(orderResponse *entity.OrderResponse) response
|
||||
|
||||
return response.CreateOrderResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
@@ -215,7 +208,6 @@ func MapOrderToCreateOrderResponse(orderResponse *entity.OrderResponse) response
|
||||
PaymentType: order.PaymentType,
|
||||
CreatedAt: order.CreatedAt,
|
||||
OrderItems: orderItems,
|
||||
Token: orderResponse.Token,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +226,6 @@ func MapOrderToExecuteOrderResponse(orderResponse *entity.ExecuteOrderResponse)
|
||||
|
||||
return response.ExecuteOrderResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
@@ -261,7 +252,6 @@ func MapOrderToExecuteCheckinResponse(order *entity.Order) response.ExecuteCheck
|
||||
|
||||
return response.ExecuteCheckinResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const _oneMB = 1 << 20 // 1MB
|
||||
const _maxUploadSizeMB = 2 * _oneMB
|
||||
const _folderName = "/file"
|
||||
const _folderName = "/public"
|
||||
|
||||
type OssHandler struct {
|
||||
ossService services.OSSService
|
||||
@@ -22,7 +22,7 @@ type OssHandler struct {
|
||||
func (h *OssHandler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route := group.Group("/file")
|
||||
|
||||
route.POST("/upload", h.UploadFile, jwt)
|
||||
route.POST("/upload", h.UploadFile)
|
||||
}
|
||||
|
||||
func NewOssHandler(ossService services.OSSService) *OssHandler {
|
||||
|
||||
@@ -278,7 +278,7 @@ func (h *Handler) toProductResponse(resp *entity.Product) response.Product {
|
||||
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: resp.CreatedAt.Format(time.RFC3339),
|
||||
PartnerID: resp.PartnerID,
|
||||
SiteID: resp.SiteID,
|
||||
Image: resp.Image,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -314,7 +314,6 @@ func (h *Handler) toProductResponseList(products []entity.Product) []response.Pr
|
||||
res = append(res, response.Product{
|
||||
ID: product.ID,
|
||||
PartnerID: product.PartnerID,
|
||||
SiteID: product.SiteID,
|
||||
Name: product.Name,
|
||||
Type: product.Type,
|
||||
Price: product.Price,
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"enaklo-pos-be/internal/common/mycontext"
|
||||
"enaklo-pos-be/internal/constants/transaction"
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
PartnerID int64 `json:"partner_id" validate:"required"`
|
||||
PaymentMethod transaction.PaymentMethod `json:"payment_method" validate:"required"`
|
||||
OrderItems []OrderItem `json:"order_items" validate:"required"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
CustomerPhone string `json:"customer_phone"`
|
||||
CustomerEmail string `json:"customer_email"`
|
||||
PaymentMethod string `json:"payment_method"`
|
||||
OrderItems []OrderItem `json:"order_items"`
|
||||
}
|
||||
|
||||
type CustomerOrder struct {
|
||||
@@ -36,8 +37,6 @@ func (o *CustomerOrder) ToEntity(createdBy int64) *entity.OrderRequest {
|
||||
OrderItems: orderItems,
|
||||
CreatedBy: createdBy,
|
||||
Source: "ONLINE",
|
||||
VisitDate: o.VisitDate,
|
||||
BankCode: o.BankCode,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +81,10 @@ func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
|
||||
|
||||
type OrderItem struct {
|
||||
ProductID int64 `json:"product_id" validate:"required"`
|
||||
Quantity int64 `json:"quantity" validate:"required"`
|
||||
Quantity int `json:"quantity" validate:"required"`
|
||||
}
|
||||
|
||||
func (o *Order) ToEntity(createdBy int64) *entity.OrderRequest {
|
||||
func (o *Order) ToEntity(partnerID, createdBy int64) *entity.OrderRequest {
|
||||
orderItems := make([]entity.OrderItemRequest, len(o.OrderItems))
|
||||
for i, item := range o.OrderItems {
|
||||
orderItems[i] = entity.OrderItemRequest{
|
||||
@@ -95,12 +94,11 @@ func (o *Order) ToEntity(createdBy int64) *entity.OrderRequest {
|
||||
}
|
||||
|
||||
return &entity.OrderRequest{
|
||||
PartnerID: o.PartnerID,
|
||||
PaymentMethod: string(o.PaymentMethod),
|
||||
PartnerID: partnerID,
|
||||
PaymentMethod: o.PaymentMethod,
|
||||
OrderItems: orderItems,
|
||||
CreatedBy: createdBy,
|
||||
Source: "POS",
|
||||
VisitDate: time.Now().Format("2006-01-02"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ type Product struct {
|
||||
IsWeekendTicket bool `json:"is_weekend_ticket"`
|
||||
IsSeasonTicket bool `json:"is_season_ticket"`
|
||||
Status string `json:"status"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Description string `json:"description"`
|
||||
Stock int64 `json:"stock"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
@@ -50,7 +50,6 @@ func (e *Product) ToEntity() *entity.Product {
|
||||
Status: e.Status,
|
||||
Description: e.Description,
|
||||
PartnerID: e.PartnerID,
|
||||
SiteID: e.SiteID,
|
||||
Image: e.Image,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ type SearchSiteByIDResponse struct {
|
||||
}
|
||||
|
||||
type SearchProductSiteByIDResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
SiteID int64 `json:"site_id"`
|
||||
ID int64 `json:"id"`
|
||||
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Price float64 `json:"price"`
|
||||
|
||||
@@ -84,9 +84,6 @@ type OrderBranchRevenue struct {
|
||||
|
||||
type CreateOrderResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
SiteName string `json:"site_name"`
|
||||
VisitDate string `json:"visit_date"`
|
||||
RefID string `json:"ref_id"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
Status string `json:"status"`
|
||||
Amount float64 `json:"amount"`
|
||||
@@ -95,9 +92,6 @@ type CreateOrderResponse struct {
|
||||
PaymentType string `json:"payment_type"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
OrderItems []CreateOrderItemResponse `json:"order_items"`
|
||||
Token string `json:"token"`
|
||||
BankCode string `json:"bank_code"`
|
||||
BankName string `json:"bank_name"`
|
||||
}
|
||||
|
||||
type PrintDetailResponse struct {
|
||||
@@ -117,7 +111,6 @@ type PrintDetailResponse struct {
|
||||
|
||||
type ExecuteOrderResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
RefID string `json:"ref_id"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
Status string `json:"status"`
|
||||
Amount float64 `json:"amount"`
|
||||
@@ -134,7 +127,6 @@ type ExecuteOrderResponse struct {
|
||||
|
||||
type ExecuteCheckinResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
RefID string `json:"ref_id"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
Status string `json:"status"`
|
||||
Amount float64 `json:"amount"`
|
||||
@@ -153,7 +145,7 @@ type CheckingInquiryResponse struct {
|
||||
type CreateOrderItemResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
ItemID int64 `json:"item_id"`
|
||||
Quantity int64 `json:"quantity"`
|
||||
Quantity int `json:"quantity"`
|
||||
Price float64 `json:"price"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"enaklo-pos-be/internal/entity"
|
||||
"time"
|
||||
)
|
||||
|
||||
type OrderInquiryResponse struct {
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
Amount float64 `json:"amount"`
|
||||
Fee float64 `json:"fee"`
|
||||
Total float64 `json:"total"`
|
||||
CustomerID int64 `json:"customer_id"`
|
||||
PaymentType string `json:"payment_type"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
CustomerPhoneNumber string `json:"customer_phone_number"`
|
||||
CustomerEmail string `json:"customer_email"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Items []OrderItemResponse `json:"items"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type OrderItemResponse struct {
|
||||
ProductID int64 `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
Price float64 `json:"price"`
|
||||
Quantity int `json:"quantity"`
|
||||
Subtotal float64 `json:"subtotal"`
|
||||
}
|
||||
|
||||
func mapToOrderItemResponses(items []entity.OrderItem) []OrderItemResponse {
|
||||
result := make([]OrderItemResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
productName := ""
|
||||
if item.Product != nil {
|
||||
productName = item.Product.Name
|
||||
}
|
||||
|
||||
result = append(result, OrderItemResponse{
|
||||
ProductID: item.ItemID,
|
||||
ProductName: productName,
|
||||
Price: item.Price,
|
||||
Quantity: item.Quantity,
|
||||
Subtotal: item.Price * float64(item.Quantity),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func MapToInquiryResponse(result *entity.OrderInquiryResponse) OrderInquiryResponse {
|
||||
resp := OrderInquiryResponse{
|
||||
ID: result.OrderInquiry.ID,
|
||||
Status: result.OrderInquiry.Status,
|
||||
Amount: result.OrderInquiry.Amount,
|
||||
Fee: result.OrderInquiry.Fee,
|
||||
Total: result.OrderInquiry.Total,
|
||||
CustomerID: result.OrderInquiry.CustomerID,
|
||||
PaymentType: result.OrderInquiry.PaymentType,
|
||||
ExpiresAt: result.OrderInquiry.ExpiresAt,
|
||||
CreatedAt: result.OrderInquiry.CreatedAt,
|
||||
Items: mapToOrderItemResponses(result.OrderInquiry.OrderItems),
|
||||
Token: result.Token,
|
||||
CustomerName: result.OrderInquiry.CustomerName,
|
||||
CustomerEmail: result.OrderInquiry.CustomerEmail,
|
||||
CustomerPhoneNumber: result.OrderInquiry.CustomerPhoneNumber,
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
type OrderResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
Status string `json:"status"`
|
||||
Amount float64 `json:"amount"`
|
||||
Fee float64 `json:"fee"`
|
||||
Total float64 `json:"total"`
|
||||
CustomerName string `json:"customer_name,omitempty"`
|
||||
PaymentType string `json:"payment_type"`
|
||||
Source string `json:"source"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||
Items []OrderItemResponse `json:"items"`
|
||||
}
|
||||
|
||||
func MapToOrderResponse(result *entity.OrderResponse) OrderResponse {
|
||||
resp := OrderResponse{
|
||||
ID: result.Order.ID,
|
||||
Status: result.Order.Status,
|
||||
Amount: result.Order.Amount,
|
||||
Fee: result.Order.Fee,
|
||||
Total: result.Order.Total,
|
||||
PaymentType: result.Order.PaymentType,
|
||||
CreatedAt: result.Order.CreatedAt,
|
||||
Items: MapToOrderItemResponses(result.Order.OrderItems),
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func MapToOrderItemResponses(items []entity.OrderItem) []OrderItemResponse {
|
||||
result := make([]OrderItemResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
productName := ""
|
||||
if item.Product != nil {
|
||||
productName = item.Product.Name
|
||||
}
|
||||
|
||||
result = append(result, OrderItemResponse{
|
||||
ProductID: item.ItemID,
|
||||
ProductName: productName,
|
||||
Price: item.Price,
|
||||
Quantity: item.Quantity,
|
||||
Subtotal: item.Price * float64(item.Quantity),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package response
|
||||
type Product struct {
|
||||
ID int64 `json:"id"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
SiteID int64 `json:"site_id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Price float64 `json:"price"`
|
||||
|
||||
Reference in New Issue
Block a user