Feat[BE-261,265]: add category request body on create on

This commit is contained in:
aguhh18
2025-11-20 08:27:02 +07:00
parent 105b20c333
commit 4c7e5b0731
4 changed files with 206 additions and 28 deletions
+31 -7
View File
@@ -1,11 +1,13 @@
package dto
import (
"encoding/json"
"fmt"
"time"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
approvalDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/approvals/dto"
locationDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/locations/dto"
nonstockDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/nonstocks/dto"
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
@@ -14,12 +16,14 @@ import (
// === Base DTO ===
type ExpenseBaseDTO struct {
Id uint64 `json:"id"`
ReferenceNumber string `json:"reference_number"`
PoNumber *string `json:"po_number,omitempty"`
Category string `json:"category"`
ExpenseDate time.Time `json:"expense_date"`
GrandTotal float64 `json:"grand_total"`
Id uint64 `json:"id"`
ReferenceNumber string `json:"reference_number"`
PoNumber *string `json:"po_number"`
Category string `json:"category"`
Documents []string `json:"documents,omitempty"`
ExpenseDate time.Time `json:"expense_date"`
GrandTotal float64 `json:"grand_total"`
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
}
// === List DTO (untuk GetAll) ===
@@ -110,13 +114,33 @@ func getStringValue(s *string) string {
// === Mapper Functions ===
func ToExpenseBaseDTO(e *entity.Expense) ExpenseBaseDTO {
var documents []string
var location *locationDTO.LocationBaseDTO
// Parse document paths from JSON if available
if e.DocumentPath.Valid && e.DocumentPath.String != "" {
if err := json.Unmarshal([]byte(e.DocumentPath.String), &documents); err == nil {
// Successfully parsed documents
}
}
// Get location from the first kandang if available
if len(e.Nonstocks) > 0 && e.Nonstocks[0].ProjectFlockKandang != nil {
if e.Nonstocks[0].ProjectFlockKandang.Kandang.Location.Id != 0 {
mapped := locationDTO.ToLocationBaseDTO(e.Nonstocks[0].ProjectFlockKandang.Kandang.Location)
location = &mapped
}
}
return ExpenseBaseDTO{
Id: e.Id,
ReferenceNumber: getStringValue(e.ReferenceNumber),
PoNumber: e.PoNumber,
PoNumber: e.PoNumber, // Keep as pointer to allow null in JSON
Category: e.Category,
Documents: documents,
ExpenseDate: e.ExpenseDate,
GrandTotal: e.GrandTotal,
Location: location,
}
}