mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat[BE]: enhance expense management with location and project flock integration, including updates to migrations, entities, services, and validations
This commit is contained in:
@@ -90,6 +90,12 @@ func (u *ExpenseController) CreateOne(c *fiber.Ctx) error {
|
||||
}
|
||||
req.SupplierID = supplierID
|
||||
|
||||
locationID, err := strconv.ParseUint(c.FormValue("location_id"), 10, 64)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid location_id format")
|
||||
}
|
||||
req.LocationID = locationID
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid multipart form")
|
||||
@@ -106,17 +112,7 @@ func (u *ExpenseController) CreateOne(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Invalid expense_nonstocks JSON: %v", err))
|
||||
}
|
||||
|
||||
if singleExpenseNonstock.KandangID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Field KandangID is required")
|
||||
}
|
||||
|
||||
req.ExpenseNonstocks = []validation.ExpenseNonstock{singleExpenseNonstock}
|
||||
} else {
|
||||
for i, expenseNonstock := range req.ExpenseNonstocks {
|
||||
if expenseNonstock.KandangID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Field KandangID is required for expense_nonstocks[%d]", i))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Field expense_nonstocks is required")
|
||||
@@ -171,6 +167,15 @@ func (u *ExpenseController) UpdateOne(c *fiber.Ctx) error {
|
||||
req.SupplierID = &supplierID
|
||||
}
|
||||
|
||||
locationIDVal := c.FormValue("location_id")
|
||||
if locationIDVal != "" {
|
||||
locationID, err := strconv.ParseUint(locationIDVal, 10, 64)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid location_id format")
|
||||
}
|
||||
req.LocationID = &locationID
|
||||
}
|
||||
|
||||
expenseNonstocksJSON := c.FormValue("expense_nonstocks")
|
||||
if expenseNonstocksJSON != "" {
|
||||
var expenseNonstocks []validation.ExpenseNonstock
|
||||
@@ -178,12 +183,6 @@ func (u *ExpenseController) UpdateOne(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Invalid expense_nonstocks JSON: %v", err))
|
||||
}
|
||||
|
||||
for i, expenseNonstock := range expenseNonstocks {
|
||||
if expenseNonstock.KandangID == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Field KandangID is required for expense_nonstocks[%d]", i))
|
||||
}
|
||||
}
|
||||
|
||||
req.ExpenseNonstocks = &expenseNonstocks
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user