better api paths
This commit is contained in:
@@ -27,6 +27,14 @@ type Department struct {
|
||||
CostCenter string `json:"cost_center"`
|
||||
}
|
||||
|
||||
type GetDepartmentBudget struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type GetDepartmentActual struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type GLAccount struct {
|
||||
ID int `json:"id"`
|
||||
Code string `json:"code"`
|
||||
@@ -35,6 +43,14 @@ type GLAccount struct {
|
||||
FavourHigh bool `json:"favour_high"`
|
||||
}
|
||||
|
||||
type GetGLAccountBudget struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type GetGLAccountActual struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type Budget struct {
|
||||
ID int `json:"id"`
|
||||
FiscalYear int `json:"fiscal_year"`
|
||||
@@ -94,44 +110,64 @@ func (cBudget *CreateBudgetRequest) Valid() []string {
|
||||
}
|
||||
|
||||
type UpdateBudgetRequest struct {
|
||||
ID int `json:"id"`
|
||||
FiscalYear int `json:"fiscal_year"`
|
||||
FiscalPeriod int `json:"fiscal_period"`
|
||||
Version BudgetVersion `json:"version"`
|
||||
DepartmentID int `json:"department_id"`
|
||||
GLAccountID int `json:"gl_account_id"`
|
||||
Amount float64 `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
Notes string `json:"notes"`
|
||||
ChangedBy string `json:"created_by"`
|
||||
ID int // required, not a pointer
|
||||
ChangedBy string // required, not a pointer
|
||||
FiscalYear *int
|
||||
FiscalPeriod *int
|
||||
Version *string
|
||||
DepartmentID *int
|
||||
GLAccountID *int
|
||||
Amount *float64
|
||||
Currency *string
|
||||
Notes *string
|
||||
}
|
||||
|
||||
type DeleteBudgetRequest struct {
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
func (uBudget *UpdateBudgetRequest) Valid() []string {
|
||||
var errs []string
|
||||
|
||||
if uBudget.FiscalYear < 1 || uBudget.FiscalYear > 2200 {
|
||||
errs = append(errs, "fiscal_year must be between 1 and 2200")
|
||||
}
|
||||
if uBudget.FiscalPeriod < 1 || uBudget.FiscalPeriod > 12 {
|
||||
errs = append(errs, "fiscal_period must be between 1 and 12")
|
||||
}
|
||||
if uBudget.Version == "" {
|
||||
errs = append(errs, "version is required")
|
||||
}
|
||||
if uBudget.DepartmentID == 0 {
|
||||
errs = append(errs, "department_id is required")
|
||||
}
|
||||
if uBudget.GLAccountID == 0 {
|
||||
errs = append(errs, "gl_account_id is required")
|
||||
}
|
||||
if uBudget.Amount <= 0 {
|
||||
errs = append(errs, "amount must be greater than 0")
|
||||
}
|
||||
if uBudget.Currency == "" {
|
||||
errs = append(errs, "currency is required")
|
||||
// Always required: identity + audit
|
||||
if uBudget.ID == 0 {
|
||||
errs = append(errs, "id is required")
|
||||
}
|
||||
if uBudget.ChangedBy == "" {
|
||||
errs = append(errs, "created_by is required")
|
||||
errs = append(errs, "changed_by is required")
|
||||
}
|
||||
|
||||
// Validate fields only if they were provided
|
||||
if uBudget.FiscalYear != nil {
|
||||
if *uBudget.FiscalYear < 1 || *uBudget.FiscalYear > 2200 {
|
||||
errs = append(errs, "fiscal_year must be between 1 and 2200")
|
||||
}
|
||||
}
|
||||
if uBudget.FiscalPeriod != nil {
|
||||
if *uBudget.FiscalPeriod < 1 || *uBudget.FiscalPeriod > 12 {
|
||||
errs = append(errs, "fiscal_period must be between 1 and 12")
|
||||
}
|
||||
}
|
||||
if uBudget.Amount != nil && *uBudget.Amount <= 0 {
|
||||
errs = append(errs, "amount must be greater than 0")
|
||||
}
|
||||
if uBudget.Version != nil && *uBudget.Version == "" {
|
||||
errs = append(errs, "version cannot be empty")
|
||||
}
|
||||
if uBudget.Currency != nil && *uBudget.Currency == "" {
|
||||
errs = append(errs, "currency cannot be empty")
|
||||
}
|
||||
|
||||
// At least one field must be set — otherwise there's nothing to do
|
||||
if uBudget.FiscalYear == nil &&
|
||||
uBudget.FiscalPeriod == nil &&
|
||||
uBudget.Version == nil &&
|
||||
uBudget.DepartmentID == nil &&
|
||||
uBudget.GLAccountID == nil &&
|
||||
uBudget.Amount == nil &&
|
||||
uBudget.Currency == nil &&
|
||||
uBudget.Notes == nil {
|
||||
errs = append(errs, "at least one field must be provided to update")
|
||||
}
|
||||
|
||||
return errs
|
||||
|
||||
Reference in New Issue
Block a user