enaklo pos backend

This commit is contained in:
aditya.siregar 2024-12-20 16:52:48 +07:00
parent 04c58658a5
commit 876b46b10c
13 changed files with 101 additions and 130 deletions

View File

@ -16,11 +16,11 @@ jwt:
postgresql:
host: 103.96.146.124
port: 1960
port: 2010
driver: postgres
db: fortuna-staging
username: fortuna_admin
password: 'Z4G827t9428QFQ^SZXW#43dB%!4Bmh80'
db: enaklo-pos-staging
username: admin
password: '4W^he3^BBBmPisWa$J#2'
ssl-mode: disable
max-idle-connections-in-second: 600
max-open-connections-in-second: 600

View File

@ -13,8 +13,12 @@ import (
func NewServer(cfg *config.Config) *Server {
gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.RedirectTrailingSlash = true
engine.RedirectFixedPath = true
server := &Server{
gin.New(),
engine,
}
server.Use(middlewares.Cors())

View File

@ -12,8 +12,6 @@ type Product struct {
Name string `gorm:"type:varchar(255);not null;column:name"`
Type string `gorm:"type:varchar;column:type"`
Price float64 `gorm:"type:decimal;column:price"`
IsWeekendTicket bool `gorm:"type:bool;column:is_weekend_ticket"`
IsSeasonTicket bool `gorm:"type:bool;column:is_season_ticket"`
Status string `gorm:"type:varchar;column:status"`
Description string `gorm:"type:varchar(255);not null;column:description"`
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
@ -21,7 +19,7 @@ type Product struct {
DeletedAt *time.Time `gorm:"column:deleted_at"`
CreatedBy int64 `gorm:"type:int;column:created_by"`
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
Stock int64 `gorm:"type:int;column:stock"`
Image string `gorm:"type:varchar;column:type"`
}
func (Product) TableName() string {
@ -74,9 +72,6 @@ func (e *ProductDB) ToProduct() *Product {
CreatedBy: e.CreatedBy,
UpdatedBy: e.UpdatedBy,
SiteID: e.SiteID,
IsSeasonTicket: e.IsSeasonTicket,
IsWeekendTicket: e.IsWeekendTicket,
Stock: e.Stock,
}
}
@ -94,20 +89,9 @@ func (b *ProductList) ToProductList() []*Product {
func (b *ProductList) ToProductListPOS() []*Product {
var Products []*Product
location, _ := time.LoadLocation("Asia/Jakarta")
today := time.Now().In(location).Weekday()
isWeekend := today == time.Saturday || today == time.Sunday
for _, p := range *b {
if p.Status != "Available" {
continue
}
if isWeekend && p.IsWeekendTicket {
Products = append(Products, p.ToProduct())
} else if !isWeekend && !p.IsWeekendTicket {
Products = append(Products, p.ToProduct())
}
}
return Products

View File

@ -216,8 +216,6 @@ func ConvertToProductResp(resp []*entity.Product) *response.SearchProductSiteRes
Name: res.Name,
SiteID: res.SiteID,
Price: res.Price,
IsWeekendTicket: res.IsWeekendTicket,
IsSeasonTicket: res.IsSeasonTicket,
Description: res.Description,
Type: res.Type,
})

View File

@ -451,7 +451,6 @@ func MapOrderToPrintDetailResponse(order *entity.OrderPrintDetail, casherName st
Quantity: item.Quantity,
Price: item.Price,
Name: item.Product.Name,
IsSeasonTicket: item.Product.IsSeasonTicket,
}
}

View File

@ -19,9 +19,9 @@ type Handler struct {
}
func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
route := group.Group("/product")
route := group.Group("/products")
route.POST("/", jwt, h.Create)
route.POST("/create", jwt, h.Create)
route.GET("/pos", jwt, h.GetPOSProduct)
route.GET("/list", jwt, h.GetAll)
route.PUT("/:id", jwt, h.Update)
@ -56,11 +56,8 @@ func (h *Handler) Create(c *gin.Context) {
return
}
validate := validator.New()
if err := validate.Struct(req); err != nil {
response.ErrorWrapper(c, err)
return
}
req.PartnerID = *ctx.GetPartnerID()
req.SiteID = *ctx.GetSiteID()
res, err := h.service.Create(ctx, req.ToEntity())
@ -282,9 +279,6 @@ func (h *Handler) toProductResponse(resp *entity.Product) response.Product {
UpdatedAt: resp.CreatedAt.Format(time.RFC3339),
PartnerID: resp.PartnerID,
SiteID: resp.SiteID,
IsSeasonTicket: resp.IsSeasonTicket,
IsWeekendTicket: resp.IsWeekendTicket,
Stock: resp.Stock,
}
}

View File

@ -318,13 +318,10 @@ func (h *Handler) toProductResponseList(products []entity.Product) []response.Pr
Name: product.Name,
Type: product.Type,
Price: product.Price,
IsWeekendTicket: product.IsWeekendTicket,
IsSeasonTicket: product.IsSeasonTicket,
Status: product.Status,
Description: product.Description,
CreatedAt: product.CreatedAt.Format(time.RFC3339),
UpdatedAt: product.UpdatedAt.Format(time.RFC3339),
Stock: product.Stock,
})
}
return res

View File

@ -30,6 +30,7 @@ func (p *ProductParam) ToEntity() entity.ProductSearch {
type Product struct {
ID int64 `json:"id,omitempty"`
PartnerID int64 `json:"partner_id"`
SiteID int64 `json:"site_id"`
Name string `json:"name" validate:"required"`
Type string `json:"type"`
Price float64 `json:"price" validate:"required"`
@ -38,6 +39,7 @@ type Product struct {
Status string `json:"status"`
Description string `json:"description" validate:"required"`
Stock int64 `json:"stock"`
Image string `json:"image"`
}
func (e *Product) ToEntity() *entity.Product {
@ -47,6 +49,8 @@ func (e *Product) ToEntity() *entity.Product {
Price: e.Price,
Status: e.Status,
Description: e.Description,
Stock: e.Stock,
PartnerID: e.PartnerID,
SiteID: e.SiteID,
Image: e.Image,
}
}

View File

@ -36,12 +36,9 @@ func (r *Site) ToEntity(createdBy int64) *entity.Site {
Name: p.Name,
Type: p.Type,
Price: p.Price,
IsWeekendTicket: p.IsWeekendTicket,
IsSeasonTicket: p.IsSeasonTicket,
Status: p.Status,
Description: p.Description,
CreatedBy: createdBy,
Stock: p.Stock,
})
}

View File

@ -156,7 +156,6 @@ type CreateOrderItemResponse struct {
Quantity int64 `json:"quantity"`
Price float64 `json:"price"`
Name string `json:"name"`
IsSeasonTicket bool `json:"is_season_ticket"`
}
type ProductDailySales struct {

View File

@ -7,13 +7,11 @@ type Product struct {
Name string `json:"name"`
Type string `json:"type"`
Price float64 `json:"price"`
IsWeekendTicket bool `json:"is_weekend_ticket"`
IsSeasonTicket bool `json:"is_season_ticket"`
Status string `json:"status"`
Description string `json:"description"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Stock int64 `json:"stock"`
Image string `json:"image"`
}
type ProductList struct {

View File

@ -12,7 +12,6 @@ import (
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Origin", "http://localhost:3000")
c.Header("Access-Control-Allow-Credentials", "true")
c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Accept, origin, Referer, Cache-Control, X-Requested-With")
c.Header("Access-Control-Allow-Methods", "POST,HEAD,PATCH, OPTIONS, GET, PUT, DELETE")

View File

@ -6,8 +6,6 @@ CREATE TABLE products
name VARCHAR(255) NOT NULL,
type VARCHAR,
price decimal,
is_weekend_ticket boolean,
is_season_ticket boolean,
status VARCHAR,
description VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),