Compare commits
2 Commits
d962d77a00
...
3d9ad4cff1
| Author | SHA1 | Date |
|---|---|---|
|
|
3d9ad4cff1 | |
|
|
1fe55d516e |
|
|
@ -7,6 +7,7 @@ import (
|
|||
dtodomain "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/dto"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/query"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/inventory_issue/repository"
|
||||
invrequestservice "github.com/Caknoooo/go-gin-clean-starter/modules/inventory_request/service"
|
||||
sequenceservice "github.com/Caknoooo/go-gin-clean-starter/modules/sequence/service"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/pkg/constants"
|
||||
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||
|
|
@ -33,6 +34,7 @@ type inventoryIssueService struct {
|
|||
db *gorm.DB
|
||||
issueRepo repository.InventoryIssueRepository
|
||||
issueLineRepo repository.InventoryIssueLineRepository
|
||||
invRequestService invrequestservice.InventoryRequestService
|
||||
sequenceService sequenceservice.SequenceService
|
||||
log *logrus.Logger
|
||||
}
|
||||
|
|
@ -87,8 +89,8 @@ func (s *inventoryIssueService) GetLinesByIssueId(ctx context.Context, issueId s
|
|||
return dtodomain.ToInventoryIssueLineResponses(lines), nil
|
||||
}
|
||||
|
||||
func NewInventoryIssueService(db *gorm.DB, issueRepo repository.InventoryIssueRepository, issueLineRepo repository.InventoryIssueLineRepository, sequenceService sequenceservice.SequenceService, log *logrus.Logger) InventoryIssueService {
|
||||
return &inventoryIssueService{db: db, issueRepo: issueRepo, issueLineRepo: issueLineRepo, sequenceService: sequenceService, log: log}
|
||||
func NewInventoryIssueService(db *gorm.DB, issueRepo repository.InventoryIssueRepository, issueLineRepo repository.InventoryIssueLineRepository, invRequestService invrequestservice.InventoryRequestService, sequenceService sequenceservice.SequenceService, log *logrus.Logger) InventoryIssueService {
|
||||
return &inventoryIssueService{db: db, issueRepo: issueRepo, issueLineRepo: issueLineRepo, invRequestService: invRequestService, sequenceService: sequenceService, log: log}
|
||||
}
|
||||
|
||||
func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.InventoryIssueCreateRequest) (dtodomain.InventoryIssueResponse, error) {
|
||||
|
|
@ -122,6 +124,14 @@ func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.Invent
|
|||
tx.Rollback()
|
||||
return dtodomain.InventoryIssueResponse{}, err
|
||||
}
|
||||
|
||||
// get inventory request line by InvRequestID
|
||||
invRequestLinesResponse, err := s.invRequestService.GetLinesByRequestId(ctx, invRequestUUID.String())
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return dtodomain.InventoryIssueResponse{}, err
|
||||
}
|
||||
|
||||
issue := entities.TInventoryIssueEntity{
|
||||
DocumentNumber: docNum,
|
||||
DocumentType: req.DocumentType,
|
||||
|
|
@ -138,19 +148,25 @@ func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.Invent
|
|||
tx.Rollback()
|
||||
return dtodomain.InventoryIssueResponse{}, err
|
||||
}
|
||||
// Bulk create lines
|
||||
// Bulk create lines from inv request lines InvRequestID
|
||||
var lines []entities.TInventoryIssueLineEntity
|
||||
for _, lineReq := range req.IssueLines {
|
||||
productUUID, err := uuid.Parse(lineReq.ProductID)
|
||||
if err != nil && lineReq.ProductID != "" {
|
||||
for _, lineReq := range invRequestLinesResponse {
|
||||
productUUID, err := uuid.Parse(lineReq.Product.ID)
|
||||
if err != nil && lineReq.Product.ID != "" {
|
||||
tx.Rollback()
|
||||
return dtodomain.InventoryIssueResponse{}, err
|
||||
}
|
||||
warehouseUUID, err := uuid.Parse(lineReq.WarehouseID)
|
||||
if err != nil && lineReq.WarehouseID != "" {
|
||||
warehouseID := utils.GetWarehouseID(ctx)
|
||||
var warehouseUUID uuid.UUID
|
||||
if warehouseID == "" {
|
||||
warehouseUUID = uuid.Nil
|
||||
} else {
|
||||
warehouseUUID, err = uuid.Parse(warehouseID)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return dtodomain.InventoryIssueResponse{}, err
|
||||
}
|
||||
}
|
||||
clientLineUUID, err := uuid.Parse(lineReq.ClientID)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
|
@ -158,10 +174,10 @@ func (s *inventoryIssueService) Create(ctx context.Context, req dtodomain.Invent
|
|||
}
|
||||
lines = append(lines, entities.TInventoryIssueLineEntity{
|
||||
CurrentStock: lineReq.CurrentStock,
|
||||
MinStock: lineReq.MinStock,
|
||||
RequestQuantity: lineReq.RequestQuantity,
|
||||
IssuedQuantity: lineReq.IssuedQuantity,
|
||||
Remarks: lineReq.Remarks,
|
||||
MinStock: 0,
|
||||
RequestQuantity: lineReq.Quantity,
|
||||
IssuedQuantity: 0,
|
||||
Remarks: "",
|
||||
InvIssueID: created.ID,
|
||||
ProductID: productUUID,
|
||||
WarehouseID: warehouseUUID,
|
||||
|
|
|
|||
|
|
@ -11,13 +11,19 @@ import (
|
|||
|
||||
type MonitoringController interface {
|
||||
HealthCheck(ctx *gin.Context)
|
||||
ReadErrorLog(ctx *gin.Context)
|
||||
ReadRouteLog(ctx *gin.Context)
|
||||
ReadQueryLog(ctx *gin.Context)
|
||||
ReadAppLog(ctx *gin.Context)
|
||||
}
|
||||
|
||||
type monitoringController struct{}
|
||||
|
||||
var validMonths = map[string]bool{
|
||||
"january": true, "february": true, "march": true, "april": true,
|
||||
"may": true, "june": true, "july": true, "august": true,
|
||||
"september": true, "october": true, "november": true, "december": true,
|
||||
}
|
||||
|
||||
// ReadAppLog implements MonitoringController.
|
||||
func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
||||
// Ambil query param 'month', default ke bulan sekarang jika tidak ada
|
||||
|
|
@ -25,9 +31,12 @@ func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
|||
if month == "" {
|
||||
month = time.Now().Format("January") // contoh: "December"
|
||||
} else {
|
||||
// Pastikan format bulan sesuai dengan nama bulan bahasa Inggris
|
||||
// Misal: "december" -> "December"
|
||||
month = strings.Title(strings.ToLower(month))
|
||||
month = strings.ToLower(month)
|
||||
if !validMonths[month] {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid month"})
|
||||
return
|
||||
}
|
||||
month = strings.ToTitle(month)
|
||||
}
|
||||
|
||||
logFile := strings.ToLower(month) + "_app.log" // contoh: "december_app.log"
|
||||
|
|
@ -35,10 +44,6 @@ func (c *monitoringController) ReadAppLog(ctx *gin.Context) {
|
|||
// Cari file log di beberapa lokasi
|
||||
locations := []string{
|
||||
"config/logs/query_log/" + logFile, // lokasi log sesuai permintaan
|
||||
"./logs/" + logFile,
|
||||
"/tmp/" + logFile,
|
||||
"/var/log/" + logFile,
|
||||
"./" + logFile,
|
||||
}
|
||||
|
||||
var content string
|
||||
|
|
@ -81,20 +86,19 @@ func (c *monitoringController) ReadQueryLog(ctx *gin.Context) {
|
|||
if month == "" {
|
||||
month = time.Now().Format("January") // contoh: "December"
|
||||
} else {
|
||||
// Pastikan format bulan sesuai dengan nama bulan bahasa Inggris
|
||||
// Misal: "december" -> "December"
|
||||
month = strings.Title(strings.ToLower(month))
|
||||
month = strings.ToLower(month)
|
||||
if !validMonths[month] {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid month"})
|
||||
return
|
||||
}
|
||||
month = strings.ToTitle(month)
|
||||
}
|
||||
|
||||
logFile := strings.ToLower(month) + "_query.log" // contoh: "december_query.log"
|
||||
|
||||
// Lokasi file log
|
||||
locations := []string{
|
||||
"config/logs/query_log/" + logFile,
|
||||
"./logs/" + logFile,
|
||||
"/tmp/" + logFile,
|
||||
"/var/log/" + logFile,
|
||||
"./" + logFile,
|
||||
"config/logs/query_log/" + logFile, // lokasi log sesuai permintaan
|
||||
}
|
||||
|
||||
var content string
|
||||
|
|
@ -141,14 +145,11 @@ func (c *monitoringController) HealthCheck(ctx *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
func (c *monitoringController) ReadErrorLog(ctx *gin.Context) {
|
||||
func (c *monitoringController) ReadRouteLog(ctx *gin.Context) {
|
||||
logFile := "gin.log"
|
||||
|
||||
// Cari file error di beberapa lokasi
|
||||
locations := []string{
|
||||
"./logs/" + logFile,
|
||||
"/tmp/" + logFile,
|
||||
"/var/log/" + logFile,
|
||||
"./" + logFile,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ func RegisterRoutes(server *gin.Engine) {
|
|||
monitoring := server.Group("/monitoring")
|
||||
{
|
||||
monitoring.GET("/health", monitoringController.HealthCheck)
|
||||
monitoring.GET("/errors", monitoringController.ReadErrorLog)
|
||||
monitoring.GET("/routes", monitoringController.ReadRouteLog)
|
||||
// get log query_log and app_log
|
||||
monitoring.GET("/logs/query", monitoringController.ReadQueryLog)
|
||||
monitoring.GET("/logs/app", monitoringController.ReadAppLog)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const (
|
|||
SUPERADMIN = "superadmin"
|
||||
COMPLETED = "completed"
|
||||
USERID = "user_id"
|
||||
WAREHOUSEID = "warehouse_id"
|
||||
CREATE = "create"
|
||||
UPDATE = "update"
|
||||
DELETE = "delete"
|
||||
|
|
|
|||
|
|
@ -42,6 +42,14 @@ func GetUserID(ctx context.Context) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func GetWarehouseID(ctx context.Context) string {
|
||||
val := ctx.Value(constants.WAREHOUSEID)
|
||||
if id, ok := val.(string); ok {
|
||||
return id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func FillAuditTrail(ctx context.Context, action string) entities.FullAuditTrail {
|
||||
userID := GetUserID(ctx)
|
||||
uid, _ := uuid.Parse(userID)
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ func RegisterDependencies(injector *do.Injector) {
|
|||
inventoryReceiptServ := inventoryReceiptService.NewInventoryReceiptService(db, inventoryReceiptRepository, inventoryReceiptLineRepository, productRepository, uomRepository, inventoryStorageRepository, sequenceServ, log)
|
||||
assignmentServ := assignmentService.NewAssignmentService(db, assignmentRepository, assignmentUserRepository)
|
||||
inventoryRequestServ := inventoryRequestService.NewInventoryRequestService(db, inventoryRequestRepository, inventoryRequestLineRepository, inventoryStorageServ, sequenceServ, log)
|
||||
inventoryIssueServ := inventoryIssueService.NewInventoryIssueService(db, inventoryIssueRepository, inventoryIssueLineRepository, sequenceServ, log)
|
||||
inventoryIssueServ := inventoryIssueService.NewInventoryIssueService(db, inventoryIssueRepository, inventoryIssueLineRepository, inventoryRequestServ, sequenceServ, log)
|
||||
inventoryReturnServ := inventoryReturnService.NewInventoryReturnService(db, inventoryReturnRepository, inventoryReturnLineRepository, inventoryIssueLineRepository, productRepository, sequenceServ, log)
|
||||
inventoryMovementServ := inventoryMovementService.NewInventoryMovementService(db, inventoryMovementRepository, inventoryMovementLineRepository, sequenceServ, log)
|
||||
quarantineServ := quarantineService.NewQuarantineService(db, quarantineRepository, quarantineLineRepository, productRepository, uomRepository, inventoryStorageRepository)
|
||||
|
|
|
|||
Loading…
Reference in New Issue