Customer Order
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user