Merge branch 'development-before-sso' of https://gitlab.com/mbugroup/lti-api into refactor-to-serve/with-middleware

This commit is contained in:
ragilap
2025-11-03 16:57:10 +07:00
70 changed files with 3089 additions and 1065 deletions
+19
View File
@@ -140,6 +140,23 @@ var ProjectFlockApprovalSteps = map[approvalutils.ApprovalStep]string{
ProjectFlockStepAktif: "Aktif",
}
// -------------------------------------------------------------------
// Recording Approval
// -------------------------------------------------------------------
const (
ApprovalWorkflowRecording approvalutils.ApprovalWorkflowKey = approvalutils.ApprovalWorkflowKey("RECORDINGS")
RecordingStepGradingTelur approvalutils.ApprovalStep = 1
RecordingStepPengajuan approvalutils.ApprovalStep = 2
RecordingStepDisetujui approvalutils.ApprovalStep = 3
)
var RecordingApprovalSteps = map[approvalutils.ApprovalStep]string{
RecordingStepGradingTelur: "Grading-Telur",
RecordingStepPengajuan: "Pengajuan",
RecordingStepDisetujui: "Disetujui",
}
// -------------------------------------------------------------------
// Validators
// -------------------------------------------------------------------
@@ -268,6 +285,8 @@ func IsValidSupplierCategory(v string) bool {
// example use
// Recording helper
/**
if !utils.IsValidFlagType(req.FlagName) {
return fiber.NewError(fiber.StatusBadRequest, "Invalid flag type")
+106
View File
@@ -0,0 +1,106 @@
package recording
import (
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/validations"
)
func MapBodyWeights(recordingID uint, items []validation.BodyWeight) []entity.RecordingBW {
if len(items) == 0 {
return nil
}
result := make([]entity.RecordingBW, 0, len(items))
for _, item := range items {
totalWeight := item.TotalWeight
if totalWeight == nil {
calculated := item.AvgWeight * item.Qty
totalWeight = &calculated
}
result = append(result, entity.RecordingBW{
RecordingId: recordingID,
AvgWeight: item.AvgWeight,
Qty: item.Qty,
TotalWeight: *totalWeight,
})
}
return result
}
func MapStocks(recordingID uint, items []validation.Stock) []entity.RecordingStock {
if len(items) == 0 {
return nil
}
result := make([]entity.RecordingStock, 0, len(items))
for _, item := range items {
var usageAmount float64
if item.Qty != nil {
usageAmount = *item.Qty
}
usagePtr := new(float64)
*usagePtr = usageAmount
pending := item.PendingQty
if pending == nil {
pending = new(float64)
}
result = append(result, entity.RecordingStock{
RecordingId: recordingID,
ProductWarehouseId: item.ProductWarehouseId,
UsageQty: usagePtr,
PendingQty: pending,
})
}
return result
}
func MapDepletions(recordingID uint, items []validation.Depletion) []entity.RecordingDepletion {
if len(items) == 0 {
return nil
}
result := make([]entity.RecordingDepletion, 0, len(items))
for _, item := range items {
result = append(result, entity.RecordingDepletion{
RecordingId: recordingID,
ProductWarehouseId: item.ProductWarehouseId,
Qty: item.Qty,
})
}
return result
}
func MapEggs(recordingID uint, createdBy uint, items []validation.Egg) []entity.RecordingEgg {
if len(items) == 0 {
return nil
}
result := make([]entity.RecordingEgg, 0, len(items))
for _, item := range items {
result = append(result, entity.RecordingEgg{
RecordingId: recordingID,
ProductWarehouseId: item.ProductWarehouseId,
Qty: item.Qty,
CreatedBy: createdBy,
})
}
return result
}
func ToGrams(weight float64) float64 {
if weight <= 0 {
return 0
}
if weight < 10 {
return weight * 1000
}
return weight
}
func GramsToKg(grams float64) float64 {
if grams <= 0 {
return 0
}
return grams / 1000
}
+37 -1
View File
@@ -1,6 +1,9 @@
package utils
import "strings"
import (
"sort"
"strings"
)
// NormalizeTrim returns the input string without leading/trailing whitespace.
func NormalizeTrim(value string) string {
@@ -11,3 +14,36 @@ func NormalizeTrim(value string) string {
func NormalizeUpper(value string) string {
return strings.ToUpper(NormalizeTrim(value))
}
// NormalizeFlag trims whitespace, removes surrounding brackets/quotes and returns upper-case flag
func NormalizeFlag(value string) string {
v := NormalizeTrim(value)
v = strings.Trim(v, "[]\"'")
return strings.ToUpper(v)
}
// ParseFlags parses a raw flags string like "[DOC, PAKAN]" or "DOC,PAKAN"
// and returns a deduplicated, sorted slice of normalized flags (upper-case, trimmed).
func ParseFlags(raw string) []string {
if raw == "" {
return nil
}
parts := strings.Split(raw, ",")
set := make(map[string]struct{}, len(parts))
for _, p := range parts {
f := NormalizeFlag(p)
if f == "" {
continue
}
set[f] = struct{}{}
}
if len(set) == 0 {
return nil
}
res := make([]string, 0, len(set))
for k := range set {
res = append(res, k)
}
sort.Strings(res)
return res
}