enaklo pos backend
This commit is contained in:
parent
04c58658a5
commit
876b46b10c
@ -16,11 +16,11 @@ jwt:
|
|||||||
|
|
||||||
postgresql:
|
postgresql:
|
||||||
host: 103.96.146.124
|
host: 103.96.146.124
|
||||||
port: 1960
|
port: 2010
|
||||||
driver: postgres
|
driver: postgres
|
||||||
db: fortuna-staging
|
db: enaklo-pos-staging
|
||||||
username: fortuna_admin
|
username: admin
|
||||||
password: 'Z4G827t9428QFQ^SZXW#43dB%!4Bmh80'
|
password: '4W^he3^BBBmPisWa$J#2'
|
||||||
ssl-mode: disable
|
ssl-mode: disable
|
||||||
max-idle-connections-in-second: 600
|
max-idle-connections-in-second: 600
|
||||||
max-open-connections-in-second: 600
|
max-open-connections-in-second: 600
|
||||||
|
|||||||
@ -13,8 +13,12 @@ import (
|
|||||||
func NewServer(cfg *config.Config) *Server {
|
func NewServer(cfg *config.Config) *Server {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
|
engine := gin.New()
|
||||||
|
engine.RedirectTrailingSlash = true
|
||||||
|
engine.RedirectFixedPath = true
|
||||||
|
|
||||||
server := &Server{
|
server := &Server{
|
||||||
gin.New(),
|
engine,
|
||||||
}
|
}
|
||||||
|
|
||||||
server.Use(middlewares.Cors())
|
server.Use(middlewares.Cors())
|
||||||
|
|||||||
@ -6,22 +6,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Product struct {
|
type Product struct {
|
||||||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||||||
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
PartnerID int64 `gorm:"type:int;column:partner_id"`
|
||||||
SiteID int64 `gorm:"type:int;column:site_id"`
|
SiteID int64 `gorm:"type:int;column:site_id"`
|
||||||
Name string `gorm:"type:varchar(255);not null;column:name"`
|
Name string `gorm:"type:varchar(255);not null;column:name"`
|
||||||
Type string `gorm:"type:varchar;column:type"`
|
Type string `gorm:"type:varchar;column:type"`
|
||||||
Price float64 `gorm:"type:decimal;column:price"`
|
Price float64 `gorm:"type:decimal;column:price"`
|
||||||
IsWeekendTicket bool `gorm:"type:bool;column:is_weekend_ticket"`
|
Status string `gorm:"type:varchar;column:status"`
|
||||||
IsSeasonTicket bool `gorm:"type:bool;column:is_season_ticket"`
|
Description string `gorm:"type:varchar(255);not null;column:description"`
|
||||||
Status string `gorm:"type:varchar;column:status"`
|
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
||||||
Description string `gorm:"type:varchar(255);not null;column:description"`
|
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
||||||
CreatedAt time.Time `gorm:"autoCreateTime;column:created_at"`
|
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
||||||
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at"`
|
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
||||||
DeletedAt *time.Time `gorm:"column:deleted_at"`
|
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
||||||
CreatedBy int64 `gorm:"type:int;column:created_by"`
|
Image string `gorm:"type:varchar;column:type"`
|
||||||
UpdatedBy int64 `gorm:"type:int;column:updated_by"`
|
|
||||||
Stock int64 `gorm:"type:int;column:stock"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Product) TableName() string {
|
func (Product) TableName() string {
|
||||||
@ -61,22 +59,19 @@ func (ProductDB) TableName() string {
|
|||||||
|
|
||||||
func (e *ProductDB) ToProduct() *Product {
|
func (e *ProductDB) ToProduct() *Product {
|
||||||
return &Product{
|
return &Product{
|
||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
Name: e.Name,
|
Name: e.Name,
|
||||||
Type: e.Type,
|
Type: e.Type,
|
||||||
Price: e.Price,
|
Price: e.Price,
|
||||||
Status: e.Status,
|
Status: e.Status,
|
||||||
Description: e.Description,
|
Description: e.Description,
|
||||||
PartnerID: e.PartnerID,
|
PartnerID: e.PartnerID,
|
||||||
CreatedAt: e.CreatedAt,
|
CreatedAt: e.CreatedAt,
|
||||||
UpdatedAt: e.UpdatedAt,
|
UpdatedAt: e.UpdatedAt,
|
||||||
DeletedAt: e.DeletedAt,
|
DeletedAt: e.DeletedAt,
|
||||||
CreatedBy: e.CreatedBy,
|
CreatedBy: e.CreatedBy,
|
||||||
UpdatedBy: e.UpdatedBy,
|
UpdatedBy: e.UpdatedBy,
|
||||||
SiteID: e.SiteID,
|
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 {
|
func (b *ProductList) ToProductListPOS() []*Product {
|
||||||
var Products []*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 {
|
for _, p := range *b {
|
||||||
if p.Status != "Available" {
|
Products = append(Products, p.ToProduct())
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if isWeekend && p.IsWeekendTicket {
|
|
||||||
Products = append(Products, p.ToProduct())
|
|
||||||
} else if !isWeekend && !p.IsWeekendTicket {
|
|
||||||
Products = append(Products, p.ToProduct())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Products
|
return Products
|
||||||
|
|||||||
@ -212,14 +212,12 @@ func ConvertToProductResp(resp []*entity.Product) *response.SearchProductSiteRes
|
|||||||
partnerID := int64(0)
|
partnerID := int64(0)
|
||||||
for _, res := range resp {
|
for _, res := range resp {
|
||||||
productResp = append(productResp, response.SearchProductSiteByIDResponse{
|
productResp = append(productResp, response.SearchProductSiteByIDResponse{
|
||||||
ID: res.ID,
|
ID: res.ID,
|
||||||
Name: res.Name,
|
Name: res.Name,
|
||||||
SiteID: res.SiteID,
|
SiteID: res.SiteID,
|
||||||
Price: res.Price,
|
Price: res.Price,
|
||||||
IsWeekendTicket: res.IsWeekendTicket,
|
Description: res.Description,
|
||||||
IsSeasonTicket: res.IsSeasonTicket,
|
Type: res.Type,
|
||||||
Description: res.Description,
|
|
||||||
Type: res.Type,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
partnerID = res.PartnerID
|
partnerID = res.PartnerID
|
||||||
|
|||||||
@ -446,12 +446,11 @@ func MapOrderToPrintDetailResponse(order *entity.OrderPrintDetail, casherName st
|
|||||||
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
||||||
for i, item := range order.OrderItems {
|
for i, item := range order.OrderItems {
|
||||||
orderItems[i] = response.CreateOrderItemResponse{
|
orderItems[i] = response.CreateOrderItemResponse{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
ItemID: item.ItemID,
|
ItemID: item.ItemID,
|
||||||
Quantity: item.Quantity,
|
Quantity: item.Quantity,
|
||||||
Price: item.Price,
|
Price: item.Price,
|
||||||
Name: item.Product.Name,
|
Name: item.Product.Name,
|
||||||
IsSeasonTicket: item.Product.IsSeasonTicket,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,9 @@ type Handler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
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("/pos", jwt, h.GetPOSProduct)
|
||||||
route.GET("/list", jwt, h.GetAll)
|
route.GET("/list", jwt, h.GetAll)
|
||||||
route.PUT("/:id", jwt, h.Update)
|
route.PUT("/:id", jwt, h.Update)
|
||||||
@ -56,11 +56,8 @@ func (h *Handler) Create(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
validate := validator.New()
|
req.PartnerID = *ctx.GetPartnerID()
|
||||||
if err := validate.Struct(req); err != nil {
|
req.SiteID = *ctx.GetSiteID()
|
||||||
response.ErrorWrapper(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := h.service.Create(ctx, req.ToEntity())
|
res, err := h.service.Create(ctx, req.ToEntity())
|
||||||
|
|
||||||
@ -272,19 +269,16 @@ func (h *Handler) GetByID(c *gin.Context) {
|
|||||||
|
|
||||||
func (h *Handler) toProductResponse(resp *entity.Product) response.Product {
|
func (h *Handler) toProductResponse(resp *entity.Product) response.Product {
|
||||||
return response.Product{
|
return response.Product{
|
||||||
ID: resp.ID,
|
ID: resp.ID,
|
||||||
Name: resp.Name,
|
Name: resp.Name,
|
||||||
Type: resp.Type,
|
Type: resp.Type,
|
||||||
Price: resp.Price,
|
Price: resp.Price,
|
||||||
Status: resp.Status,
|
Status: resp.Status,
|
||||||
Description: resp.Description,
|
Description: resp.Description,
|
||||||
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
|
||||||
UpdatedAt: resp.CreatedAt.Format(time.RFC3339),
|
UpdatedAt: resp.CreatedAt.Format(time.RFC3339),
|
||||||
PartnerID: resp.PartnerID,
|
PartnerID: resp.PartnerID,
|
||||||
SiteID: resp.SiteID,
|
SiteID: resp.SiteID,
|
||||||
IsSeasonTicket: resp.IsSeasonTicket,
|
|
||||||
IsWeekendTicket: resp.IsWeekendTicket,
|
|
||||||
Stock: resp.Stock,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -312,19 +312,16 @@ func (h *Handler) toProductResponseList(products []entity.Product) []response.Pr
|
|||||||
var res []response.Product
|
var res []response.Product
|
||||||
for _, product := range products {
|
for _, product := range products {
|
||||||
res = append(res, response.Product{
|
res = append(res, response.Product{
|
||||||
ID: product.ID,
|
ID: product.ID,
|
||||||
PartnerID: product.PartnerID,
|
PartnerID: product.PartnerID,
|
||||||
SiteID: product.SiteID,
|
SiteID: product.SiteID,
|
||||||
Name: product.Name,
|
Name: product.Name,
|
||||||
Type: product.Type,
|
Type: product.Type,
|
||||||
Price: product.Price,
|
Price: product.Price,
|
||||||
IsWeekendTicket: product.IsWeekendTicket,
|
Status: product.Status,
|
||||||
IsSeasonTicket: product.IsSeasonTicket,
|
Description: product.Description,
|
||||||
Status: product.Status,
|
CreatedAt: product.CreatedAt.Format(time.RFC3339),
|
||||||
Description: product.Description,
|
UpdatedAt: product.UpdatedAt.Format(time.RFC3339),
|
||||||
CreatedAt: product.CreatedAt.Format(time.RFC3339),
|
|
||||||
UpdatedAt: product.UpdatedAt.Format(time.RFC3339),
|
|
||||||
Stock: product.Stock,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|||||||
@ -30,6 +30,7 @@ func (p *ProductParam) ToEntity() entity.ProductSearch {
|
|||||||
type Product struct {
|
type Product struct {
|
||||||
ID int64 `json:"id,omitempty"`
|
ID int64 `json:"id,omitempty"`
|
||||||
PartnerID int64 `json:"partner_id"`
|
PartnerID int64 `json:"partner_id"`
|
||||||
|
SiteID int64 `json:"site_id"`
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Price float64 `json:"price" validate:"required"`
|
Price float64 `json:"price" validate:"required"`
|
||||||
@ -38,6 +39,7 @@ type Product struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Description string `json:"description" validate:"required"`
|
Description string `json:"description" validate:"required"`
|
||||||
Stock int64 `json:"stock"`
|
Stock int64 `json:"stock"`
|
||||||
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Product) ToEntity() *entity.Product {
|
func (e *Product) ToEntity() *entity.Product {
|
||||||
@ -47,6 +49,8 @@ func (e *Product) ToEntity() *entity.Product {
|
|||||||
Price: e.Price,
|
Price: e.Price,
|
||||||
Status: e.Status,
|
Status: e.Status,
|
||||||
Description: e.Description,
|
Description: e.Description,
|
||||||
Stock: e.Stock,
|
PartnerID: e.PartnerID,
|
||||||
|
SiteID: e.SiteID,
|
||||||
|
Image: e.Image,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,17 +31,14 @@ func (r *Site) ToEntity(createdBy int64) *entity.Site {
|
|||||||
var products []entity.Product
|
var products []entity.Product
|
||||||
for _, p := range r.Products {
|
for _, p := range r.Products {
|
||||||
products = append(products, entity.Product{
|
products = append(products, entity.Product{
|
||||||
ID: p.ID,
|
ID: p.ID,
|
||||||
PartnerID: *r.PartnerID,
|
PartnerID: *r.PartnerID,
|
||||||
Name: p.Name,
|
Name: p.Name,
|
||||||
Type: p.Type,
|
Type: p.Type,
|
||||||
Price: p.Price,
|
Price: p.Price,
|
||||||
IsWeekendTicket: p.IsWeekendTicket,
|
Status: p.Status,
|
||||||
IsSeasonTicket: p.IsSeasonTicket,
|
Description: p.Description,
|
||||||
Status: p.Status,
|
CreatedBy: createdBy,
|
||||||
Description: p.Description,
|
|
||||||
CreatedBy: createdBy,
|
|
||||||
Stock: p.Stock,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -151,12 +151,11 @@ type CheckingInquiryResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CreateOrderItemResponse struct {
|
type CreateOrderItemResponse struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
ItemID int64 `json:"item_id"`
|
ItemID int64 `json:"item_id"`
|
||||||
Quantity int64 `json:"quantity"`
|
Quantity int64 `json:"quantity"`
|
||||||
Price float64 `json:"price"`
|
Price float64 `json:"price"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IsSeasonTicket bool `json:"is_season_ticket"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductDailySales struct {
|
type ProductDailySales struct {
|
||||||
|
|||||||
@ -1,19 +1,17 @@
|
|||||||
package response
|
package response
|
||||||
|
|
||||||
type Product struct {
|
type Product struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
PartnerID int64 `json:"partner_id"`
|
PartnerID int64 `json:"partner_id"`
|
||||||
SiteID int64 `json:"site_id"`
|
SiteID int64 `json:"site_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Price float64 `json:"price"`
|
Price float64 `json:"price"`
|
||||||
IsWeekendTicket bool `json:"is_weekend_ticket"`
|
Status string `json:"status"`
|
||||||
IsSeasonTicket bool `json:"is_season_ticket"`
|
Description string `json:"description"`
|
||||||
Status string `json:"status"`
|
CreatedAt string `json:"created_at"`
|
||||||
Description string `json:"description"`
|
UpdatedAt string `json:"updated_at"`
|
||||||
CreatedAt string `json:"created_at"`
|
Image string `json:"image"`
|
||||||
UpdatedAt string `json:"updated_at"`
|
|
||||||
Stock int64 `json:"stock"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductList struct {
|
type ProductList struct {
|
||||||
|
|||||||
@ -12,7 +12,6 @@ import (
|
|||||||
func Cors() gin.HandlerFunc {
|
func Cors() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
c.Header("Access-Control-Allow-Origin", "*")
|
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-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-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")
|
c.Header("Access-Control-Allow-Methods", "POST,HEAD,PATCH, OPTIONS, GET, PUT, DELETE")
|
||||||
|
|||||||
@ -6,8 +6,6 @@ CREATE TABLE products
|
|||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
type VARCHAR,
|
type VARCHAR,
|
||||||
price decimal,
|
price decimal,
|
||||||
is_weekend_ticket boolean,
|
|
||||||
is_season_ticket boolean,
|
|
||||||
status VARCHAR,
|
status VARCHAR,
|
||||||
description VARCHAR(255) NOT NULL,
|
description VARCHAR(255) NOT NULL,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user