mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Feat[BE-261,265]: add category request body on create on
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user