Customer Order
This commit is contained in:
@@ -54,6 +54,11 @@ func (h *AuthHandler) AuthLogin(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if authUser.UserType == "CUSTOMER" {
|
||||
response.ErrorWrapper(c, errors.ErrorUserIsNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
var partner *response.Partner
|
||||
var site *response.SiteName
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package customerauth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"furtuna-be/internal/common/errors"
|
||||
auth2 "furtuna-be/internal/handlers/request"
|
||||
"furtuna-be/internal/handlers/response"
|
||||
"furtuna-be/internal/services"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
service services.Auth
|
||||
userService services.User
|
||||
}
|
||||
|
||||
func (a *AuthHandler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
authRoute := group.Group("/auth")
|
||||
authRoute.POST("/login", a.AuthLogin)
|
||||
authRoute.POST("/forgot-password", a.ForgotPassword)
|
||||
authRoute.POST("/reset-password", jwt, a.ResetPassword)
|
||||
authRoute.POST("/register", a.Register)
|
||||
}
|
||||
|
||||
func NewAuthHandler(service services.Auth, userService services.User) *AuthHandler {
|
||||
return &AuthHandler{
|
||||
service: service,
|
||||
userService: userService,
|
||||
}
|
||||
}
|
||||
|
||||
// AuthLogin handles the authentication process for user login.
|
||||
// @Summary User login
|
||||
// @Description Authenticates a user based on the provided credentials and returns a JWT token.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param bodyParam body auth2.LoginRequest true "User login credentials"
|
||||
// @Success 200 {object} response.BaseResponse{data=response.LoginResponse} "Login successful"
|
||||
// @Failure 400 {object} response.BaseResponse{data=errors.Error} "Bad request"
|
||||
// @Failure 401 {object} response.BaseResponse{data=errors.Error} "Unauthorized"
|
||||
// @Router /api/v1/auth/login [post]
|
||||
// @Tags Auth Login API's
|
||||
func (h *AuthHandler) AuthLogin(c *gin.Context) {
|
||||
var bodyParam auth2.LoginRequest
|
||||
if err := c.ShouldBindJSON(&bodyParam); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
authUser, err := h.service.AuthenticateUser(c, bodyParam.Email, bodyParam.Password)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if authUser.UserType != "CUSTOMER" {
|
||||
response.ErrorWrapper(c, errors.ErrorUserIsNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
resp := response.LoginResponseCustoemr{
|
||||
ID: authUser.ID,
|
||||
Token: authUser.Token,
|
||||
Name: authUser.Name,
|
||||
ResetPassword: authUser.ResetPassword,
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Message: "Login Success",
|
||||
Data: resp,
|
||||
})
|
||||
}
|
||||
|
||||
// ForgotPassword handles the request for password reset.
|
||||
// @Summary Request password reset
|
||||
// @Description Sends a password reset link to the user's email.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param bodyParam body auth2.ForgotPasswordRequest true "User email"
|
||||
// @Success 200 {object} response.BaseResponse "Password reset link sent"
|
||||
// @Failure 400 {object} response.BaseResponse{data=errors.Error} "Bad request"
|
||||
// @Router /api/v1/auth/forgot-password [post]
|
||||
// @Tags Auth Password API's
|
||||
func (h *AuthHandler) ForgotPassword(c *gin.Context) {
|
||||
var bodyParam auth2.ResetPasswordRequest
|
||||
if err := c.ShouldBindJSON(&bodyParam); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err := h.service.SendPasswordResetLink(c, bodyParam.Email)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Message: "Password reset link sent",
|
||||
})
|
||||
}
|
||||
|
||||
// ResetPassword handles the password reset process.
|
||||
// @Summary Reset user password
|
||||
// @Description Resets the user's password using the provided token.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param bodyParam body auth2.ResetPasswordRequest true "Reset password details"
|
||||
// @Success 200 {object} response.BaseResponse "Password reset successful"
|
||||
// @Failure 400 {object} response.BaseResponse{data=errors.Error} "Bad request"
|
||||
// @Router /api/v1/auth/reset-password [post]
|
||||
// @Tags Auth Password API's
|
||||
func (h *AuthHandler) ResetPassword(c *gin.Context) {
|
||||
ctx := auth2.GetMyContext(c)
|
||||
|
||||
var req auth2.ResetPasswordChangeRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
response.ErrorWrapper(c, errors.NewError(
|
||||
errors.ErrorBadRequest.ErrorType(),
|
||||
fmt.Sprintf("invalid request %v", err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
err := h.service.ResetPassword(ctx, req.OldPassword, req.NewPassword)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Message: "Password reset successful",
|
||||
})
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Register(c *gin.Context) {
|
||||
var req auth2.UserRegister
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := auth2.GetMyContext(c)
|
||||
res, err := h.userService.Create(ctx, req.ToEntity())
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := response.UserRegister{
|
||||
ID: res.ID,
|
||||
Name: res.Name,
|
||||
Email: res.Email,
|
||||
Status: string(res.Status),
|
||||
CreatedAt: res.CreatedAt,
|
||||
UpdatedAt: res.UpdatedAt,
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: resp,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
package customerorder
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"furtuna-be/internal/common/errors"
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/handlers/request"
|
||||
"furtuna-be/internal/handlers/response"
|
||||
"furtuna-be/internal/services"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
service services.Order
|
||||
}
|
||||
|
||||
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)
|
||||
route.GET("/history", jwt, h.History)
|
||||
route.GET("/detail", jwt, h.Detail)
|
||||
}
|
||||
|
||||
func NewHandler(service services.Order) *Handler {
|
||||
return &Handler{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) Inquiry(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.CustomerOrder
|
||||
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
|
||||
}
|
||||
|
||||
order, err := h.service.CreateOrder(ctx, req.ToEntity(ctx.RequestedBy()))
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: MapOrderToCreateOrderResponse(order),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) Execute(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.Execute
|
||||
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
|
||||
}
|
||||
|
||||
order, err := h.service.Execute(ctx, req.ToOrderExecuteRequest(ctx.RequestedBy()))
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: MapOrderToExecuteOrderResponse(order),
|
||||
})
|
||||
}
|
||||
|
||||
func MapOrderToCreateOrderResponse(orderResponse *entity.OrderResponse) response.CreateOrderResponse {
|
||||
order := orderResponse.Order
|
||||
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
||||
for i, item := range order.OrderItems {
|
||||
orderItems[i] = response.CreateOrderItemResponse{
|
||||
ID: item.ID,
|
||||
ItemID: item.ItemID,
|
||||
Quantity: item.Quantity,
|
||||
Price: item.Price,
|
||||
Name: item.Product.Name,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func MapOrderToExecuteOrderResponse(orderResponse *entity.ExecuteOrderResponse) response.ExecuteOrderResponse {
|
||||
order := orderResponse.Order
|
||||
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
||||
for i, item := range order.OrderItems {
|
||||
orderItems[i] = response.CreateOrderItemResponse{
|
||||
ID: item.ID,
|
||||
ItemID: item.ItemID,
|
||||
Quantity: item.Quantity,
|
||||
Price: item.Price,
|
||||
Name: item.Product.Name,
|
||||
}
|
||||
}
|
||||
|
||||
return response.ExecuteOrderResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
PaymentType: order.PaymentType,
|
||||
CreatedAt: order.CreatedAt,
|
||||
OrderItems: orderItems,
|
||||
PaymentToken: orderResponse.PaymentToken,
|
||||
RedirectURL: orderResponse.RedirectURL,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderResponse(resp *entity.HistoryOrder) response.HistoryOrder {
|
||||
return response.HistoryOrder{
|
||||
ID: resp.ID,
|
||||
Employee: resp.Employee,
|
||||
Site: resp.Site,
|
||||
Timestamp: resp.Timestamp.Format(time.RFC3339),
|
||||
BookingTime: resp.BookingTime.Format(time.RFC3339),
|
||||
Tickets: resp.Tickets,
|
||||
PaymentType: resp.PaymentType,
|
||||
Status: resp.Status,
|
||||
Amount: resp.Amount,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.OrderParamCustomer) response.HistoryOrderList {
|
||||
var orders []response.HistoryOrder
|
||||
for _, b := range resp {
|
||||
orders = append(orders, h.toHistoryOrderResponse(b))
|
||||
}
|
||||
|
||||
return response.HistoryOrderList{
|
||||
Orders: orders,
|
||||
Total: total,
|
||||
Limit: req.Limit,
|
||||
Offset: req.Offset,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) History(c *gin.Context) {
|
||||
var req request.OrderParamCustomer
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := request.GetMyContext(c)
|
||||
orders, total, err := h.service.GetAllHistoryOrders(ctx, req.ToOrderEntity(ctx))
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: h.toHistoryOrderList(orders, int64(total), req),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) Detail(c *gin.Context) {
|
||||
var req request.OrderParamCustomer
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := request.GetMyContext(c)
|
||||
order, err := h.service.GetByID(ctx, req.ID)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: h.toOrderDetail(order),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) toOrderDetail(order *entity.Order) *response.OrderDetail {
|
||||
if order == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
payment := map[string]string{}
|
||||
paymentLink := ""
|
||||
|
||||
if order.Payment.RequestMetadata != nil && order.Status != "EXPIRED" {
|
||||
json.Unmarshal(order.Payment.RequestMetadata, &payment)
|
||||
paymentLink = payment["payment_redirect_url"]
|
||||
}
|
||||
|
||||
orderDetail := &response.OrderDetail{
|
||||
ID: order.ID,
|
||||
QRCode: order.RefID,
|
||||
FullName: order.User.Name,
|
||||
Email: order.User.Email,
|
||||
PhoneNumber: order.User.PhoneNumber,
|
||||
TotalAmount: order.Amount,
|
||||
CreatedAt: order.CreatedAt,
|
||||
Status: order.Status,
|
||||
PaymentLink: paymentLink,
|
||||
}
|
||||
|
||||
orderDetail.OrderItems = make([]response.OrderDetailItem, len(order.OrderItems))
|
||||
for i, item := range order.OrderItems {
|
||||
orderDetail.OrderItems[i] = response.OrderDetailItem{
|
||||
ItemType: item.ItemType,
|
||||
Description: "",
|
||||
Quantity: int(item.Quantity),
|
||||
UnitPrice: item.Price,
|
||||
TotalPrice: float64(item.Quantity) * item.Price,
|
||||
}
|
||||
}
|
||||
|
||||
return orderDetail
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package discovery
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/entity"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
|
||||
"furtuna-be/internal/common/errors"
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/handlers/request"
|
||||
"furtuna-be/internal/handlers/response"
|
||||
"furtuna-be/internal/services"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
@@ -20,6 +19,8 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
|
||||
route.GET("/home", h.DisoveryHome)
|
||||
route.GET("/search", h.DisoverySearch)
|
||||
route.GET("/site/detail", h.DiscoveryGetByID)
|
||||
route.GET("/site/products", h.DiscoveryProducts)
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +72,52 @@ func (h *Handler) DisoverySearch(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) DiscoveryGetByID(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.DiscoverySearchByID
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := h.service.GetByID(ctx, req.ID)
|
||||
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: ConvertEntityToGetByIDResp(res),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) DiscoveryProducts(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.DiscoverySearchByID
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := h.service.GetProductsByID(ctx, req.ID)
|
||||
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: ConvertToProductResp(res),
|
||||
})
|
||||
}
|
||||
|
||||
func ConvertEntityToResponse(entityResp *entity.DiscoverySearchResp) *response.ExploreResponse {
|
||||
// Convert ExploreRegions
|
||||
exploreRegions := make([]response.Region, len(entityResp.ExploreRegions))
|
||||
@@ -132,3 +179,52 @@ func ConvertEntityToSearchResponse(entityResp *entity.DiscoverySearchResp, total
|
||||
Offset: req.Offset,
|
||||
}
|
||||
}
|
||||
|
||||
func ConvertEntityToGetByIDResp(resp *entity.Site) *response.SearchSiteByIDResponse {
|
||||
if resp == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &response.SearchSiteByIDResponse{
|
||||
ID: resp.ID,
|
||||
Name: resp.Name,
|
||||
Image: resp.Image,
|
||||
Address: resp.Address,
|
||||
LocationLink: resp.LocationLink,
|
||||
Description: resp.Description,
|
||||
Highlight: resp.Highlight,
|
||||
ContactPerson: resp.ContactPerson,
|
||||
TnC: resp.TnC,
|
||||
AdditionalInfo: resp.AdditionalInfo,
|
||||
PartnerID: resp.PartnerID,
|
||||
}
|
||||
}
|
||||
|
||||
func ConvertToProductResp(resp []*entity.Product) *response.SearchProductSiteResponse {
|
||||
if resp == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var productResp []response.SearchProductSiteByIDResponse
|
||||
|
||||
partnerID := int64(0)
|
||||
for _, res := range resp {
|
||||
productResp = append(productResp, response.SearchProductSiteByIDResponse{
|
||||
ID: res.ID,
|
||||
Name: res.Name,
|
||||
SiteID: res.SiteID,
|
||||
Price: res.Price,
|
||||
IsWeekendTicket: res.IsWeekendTicket,
|
||||
IsSeasonTicket: res.IsSeasonTicket,
|
||||
Description: res.Description,
|
||||
Type: res.Type,
|
||||
})
|
||||
|
||||
partnerID = res.PartnerID
|
||||
}
|
||||
|
||||
return &response.SearchProductSiteResponse{
|
||||
Product: productResp,
|
||||
PartnerID: partnerID,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ type DiscoveryHomeParam struct {
|
||||
Discover string `form:"discover" json:"discover" example:"0"`
|
||||
}
|
||||
|
||||
type DiscoverySearchByID struct {
|
||||
ID int64 `form:"id" json:"id" example:"0"`
|
||||
}
|
||||
|
||||
func (d *DiscoveryHomeParam) ToEntity() *entity.DiscoverySearch {
|
||||
if d.Limit == 0 {
|
||||
d.Limit = 10
|
||||
|
||||
@@ -12,6 +12,30 @@ type Order struct {
|
||||
OrderItems []OrderItem `json:"order_items" validate:"required"`
|
||||
}
|
||||
|
||||
type CustomerOrder struct {
|
||||
PartnerID int64 `json:"partner_id" validate:"required"`
|
||||
PaymentMethod transaction.PaymentMethod `json:"payment_method" validate:"required"`
|
||||
OrderItems []OrderItem `json:"order_items" validate:"required"`
|
||||
}
|
||||
|
||||
func (o *CustomerOrder) ToEntity(createdBy int64) *entity.OrderRequest {
|
||||
orderItems := make([]entity.OrderItemRequest, len(o.OrderItems))
|
||||
for i, item := range o.OrderItems {
|
||||
orderItems[i] = entity.OrderItemRequest{
|
||||
ProductID: item.ProductID,
|
||||
Quantity: item.Quantity,
|
||||
}
|
||||
}
|
||||
|
||||
return &entity.OrderRequest{
|
||||
PartnerID: o.PartnerID,
|
||||
PaymentMethod: string(o.PaymentMethod),
|
||||
OrderItems: orderItems,
|
||||
CreatedBy: createdBy,
|
||||
Source: "ONLINE",
|
||||
}
|
||||
}
|
||||
|
||||
type OrderParam struct {
|
||||
PaymentType string `form:"payment_type" json:"payment_type" example:"CASH"`
|
||||
StartDate string `form:"start_date" json:"start_date"`
|
||||
@@ -56,6 +80,7 @@ func (o *Order) ToEntity(createdBy int64) *entity.OrderRequest {
|
||||
PaymentMethod: string(o.PaymentMethod),
|
||||
OrderItems: orderItems,
|
||||
CreatedBy: createdBy,
|
||||
Source: "POS",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,3 +96,25 @@ func (e Execute) ToOrderExecuteRequest(createdBy int64) *entity.OrderExecuteRequ
|
||||
Token: e.Token,
|
||||
}
|
||||
}
|
||||
|
||||
type OrderParamCustomer struct {
|
||||
ID int64 `form:"id" json:"id" example:"10"`
|
||||
Limit int `form:"limit" json:"limit" example:"10"`
|
||||
Offset int `form:"offset" json:"offset" example:"0"`
|
||||
}
|
||||
|
||||
func (o *OrderParamCustomer) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
|
||||
if o.Limit == 0 {
|
||||
o.Limit = 10
|
||||
}
|
||||
|
||||
return entity.OrderSearch{
|
||||
PartnerID: ctx.GetPartnerID(),
|
||||
SiteID: ctx.GetSiteID(),
|
||||
IsAdmin: ctx.IsAdmin(),
|
||||
Limit: o.Limit,
|
||||
Offset: o.Offset,
|
||||
CreatedBy: ctx.RequestedBy(),
|
||||
IsCustomer: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,3 +72,30 @@ func (p *UserParam) ToEntity(ctx mycontext.Context) entity.UserSearch {
|
||||
Offset: p.Offset,
|
||||
}
|
||||
}
|
||||
|
||||
type UserRegister struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
PhoneNumber string `json:"phone_number" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
func (e *UserRegister) Validate() error {
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(e); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserRegister) ToEntity() *entity.User {
|
||||
return &entity.User{
|
||||
Name: u.Name,
|
||||
Email: u.Email,
|
||||
PhoneNumber: u.PhoneNumber,
|
||||
Password: u.Password,
|
||||
RoleID: role.Customer,
|
||||
UserType: "CUSTOMER",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,13 @@ type LoginResponse struct {
|
||||
PartnerLicense *PartnerLicense `json:"partner_license,omitempty"`
|
||||
}
|
||||
|
||||
type LoginResponseCustoemr struct {
|
||||
ID int64 `json:"id"`
|
||||
Token string `json:"token"`
|
||||
Name string `json:"name"`
|
||||
ResetPassword bool `json:"reset_password"`
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
ID int64 `json:"id"`
|
||||
Role string `json:"role_name"`
|
||||
|
||||
@@ -47,3 +47,35 @@ type SiteSeach struct {
|
||||
ImageURL string `json:"imageUrl"`
|
||||
Regency string `json:"regency"`
|
||||
}
|
||||
|
||||
type SearchSiteByIDResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
Image string `json:"image"`
|
||||
Address string `json:"address"`
|
||||
LocationLink string `json:"location_link"`
|
||||
Description string `json:"description"`
|
||||
Highlight string `json:"highlight"`
|
||||
ContactPerson string `json:"contact_person"`
|
||||
TnC string `json:"tn_c"`
|
||||
AdditionalInfo string `json:"additional_info"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type SearchProductSiteByIDResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
SiteID int64 `json:"site_id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Price float64 `json:"price"`
|
||||
IsWeekendTicket bool `json:"is_weekend_ticket"`
|
||||
IsSeasonTicket bool `json:"is_season_ticket"`
|
||||
Description string `json:"description"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
}
|
||||
|
||||
type SearchProductSiteResponse struct {
|
||||
Product []SearchProductSiteByIDResponse `json:"product"`
|
||||
PartnerID int64 `json:"partner_id"`
|
||||
}
|
||||
|
||||
@@ -124,3 +124,24 @@ type PaymentDistribution struct {
|
||||
PaymentType string `json:"payment_type"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type OrderDetail struct {
|
||||
ID int64 `json:"id"` // Order ID
|
||||
QRCode string `json:"qr_code"` // QR code data (can be a URL or base64 string)
|
||||
FullName string `json:"full_name"` // Customer's full name
|
||||
Email string `json:"email"` // Customer's email address
|
||||
PhoneNumber string `json:"phone_number"` // Customer's phone number
|
||||
OrderItems []OrderDetailItem `json:"order_items"` // List of ordered items
|
||||
TotalAmount float64 `json:"total_amount"` // Total amount paid
|
||||
CreatedAt time.Time `json:"created_at"` // Order creation time
|
||||
Status string `json:"status"`
|
||||
PaymentLink string `json:"payment_link"`
|
||||
}
|
||||
|
||||
type OrderDetailItem struct {
|
||||
ItemType string `json:"item_type"`
|
||||
Description string `json:"description"`
|
||||
Quantity int `json:"quantity"` // Quantity of the item
|
||||
UnitPrice float64 `json:"unit_price"` // Price per unit
|
||||
TotalPrice float64 `json:"total_price"` // Total price for this item (Quantity * UnitPrice)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package response
|
||||
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -19,3 +21,12 @@ type UserList struct {
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
type UserRegister struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user