Merge branch 'feat/BE/Sprint-5' of https://gitlab.com/mbugroup/lti-api into dev/teguh

This commit is contained in:
aguhh18
2025-11-21 10:46:50 +07:00
77 changed files with 1453 additions and 3969 deletions
+13 -13
View File
@@ -9,16 +9,16 @@ import (
// === DTO Structs ===
type AreaBaseDTO struct {
type AreaRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type AreaListDTO struct {
AreaBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
AreaRelationDTO
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type AreaDetailDTO struct {
@@ -27,25 +27,25 @@ type AreaDetailDTO struct {
// === Mapper Functions ===
func ToAreaBaseDTO(e entity.Area) AreaBaseDTO {
return AreaBaseDTO{
func ToAreaRelationDTO(e entity.Area) AreaRelationDTO {
return AreaRelationDTO{
Id: e.Id,
Name: e.Name,
}
}
func ToAreaListDTO(e entity.Area) AreaListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
return AreaListDTO{
AreaBaseDTO: ToAreaBaseDTO(e),
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
AreaRelationDTO: ToAreaRelationDTO(e),
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}
}
+13 -13
View File
@@ -9,7 +9,7 @@ import (
// === DTO Structs ===
type BankBaseDTO struct {
type BankRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Alias string `json:"alias"`
@@ -18,10 +18,10 @@ type BankBaseDTO struct {
}
type BankListDTO struct {
BankBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
BankRelationDTO
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type BankDetailDTO struct {
@@ -30,8 +30,8 @@ type BankDetailDTO struct {
// === Mapper Functions ===
func ToBankBaseDTO(e entity.Bank) BankBaseDTO {
return BankBaseDTO{
func ToBankRelationDTO(e entity.Bank) BankRelationDTO {
return BankRelationDTO{
Id: e.Id,
Name: e.Name,
Alias: e.Alias,
@@ -41,17 +41,17 @@ func ToBankBaseDTO(e entity.Bank) BankBaseDTO {
}
func ToBankListDTO(e entity.Bank) BankListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
return BankListDTO{
BankBaseDTO: ToBankBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
BankRelationDTO: ToBankRelationDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
@@ -9,25 +9,29 @@ import (
// === DTO Structs ===
type CustomerBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
PicId uint `json:"pic_id"`
Type string `json:"type"`
Address string `json:"address"`
Phone string `json:"phone"`
Email string `json:"email"`
AccountNumber string `json:"account_number"`
Balance float64 `json:"balance"`
Pic *userDTO.UserBaseDTO `json:"pic,omitempty"`
type CustomerRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
AccountNumber string `json:"account_number"`
Balance float64 `json:"balance"`
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
}
type CustomerListDTO struct {
CustomerBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
PicId uint `json:"pic_id"`
Type string `json:"type"`
Address string `json:"address"`
Phone string `json:"phone"`
Email string `json:"email"`
AccountNumber string `json:"account_number"`
Balance float64 `json:"balance"`
Pic userDTO.UserRelationDTO `json:"pic"`
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type CustomerDetailDTO struct {
@@ -36,14 +40,36 @@ type CustomerDetailDTO struct {
// === Mapper Functions ===
func ToCustomerBaseDTO(e entity.Customer) CustomerBaseDTO {
var pic *userDTO.UserBaseDTO
func ToCustomerRelationDTO(e entity.Customer) CustomerRelationDTO {
var pic *userDTO.UserRelationDTO
if e.Pic.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.Pic)
mapped := userDTO.ToUserRelationDTO(e.Pic)
pic = &mapped
}
return CustomerBaseDTO{
return CustomerRelationDTO{
Id: e.Id,
Name: e.Name,
Type: e.Type,
AccountNumber: e.AccountNumber,
Pic: pic,
}
}
func ToCustomerListDTO(e entity.Customer) CustomerListDTO {
var createdUser userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = mapped
}
var pic userDTO.UserRelationDTO
if e.Pic.Id != 0 {
mapped := userDTO.ToUserRelationDTO(e.Pic)
pic = mapped
}
return CustomerListDTO{
Id: e.Id,
Name: e.Name,
PicId: e.PicId,
@@ -53,21 +79,9 @@ func ToCustomerBaseDTO(e entity.Customer) CustomerBaseDTO {
Email: e.Email,
AccountNumber: e.AccountNumber,
Pic: pic,
}
}
func ToCustomerListDTO(e entity.Customer) CustomerListDTO {
var createdUser *userDTO.UserBaseDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
createdUser = &mapped
}
return CustomerListDTO{
CustomerBaseDTO: ToCustomerBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
+13 -13
View File
@@ -9,7 +9,7 @@ import (
// === DTO Structs ===
type FcrBaseDTO struct {
type FcrRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
@@ -22,10 +22,10 @@ type FcrStandardDTO struct {
}
type FcrListDTO struct {
FcrBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
FcrRelationDTO
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type FcrDetailDTO struct {
@@ -35,25 +35,25 @@ type FcrDetailDTO struct {
// === Mapper Functions ===
func ToFcrBaseDTO(e entity.Fcr) FcrBaseDTO {
return FcrBaseDTO{
func ToFcrRelationDTO(e entity.Fcr) FcrRelationDTO {
return FcrRelationDTO{
Id: e.Id,
Name: e.Name,
}
}
func ToFcrListDTO(e entity.Fcr) FcrListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
return FcrListDTO{
FcrBaseDTO: ToFcrBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
FcrRelationDTO: ToFcrRelationDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
+13 -13
View File
@@ -9,16 +9,16 @@ import (
// === DTO Structs ===
type FlockBaseDTO struct {
type FlockRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type FlockListDTO struct {
FlockBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
FlockRelationDTO
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type FlockDetailDTO struct {
@@ -27,25 +27,25 @@ type FlockDetailDTO struct {
// === Mapper Functions ===
func ToFlockBaseDTO(e entity.Flock) FlockBaseDTO {
return FlockBaseDTO{
func ToFlockRelationDTO(e entity.Flock) FlockRelationDTO {
return FlockRelationDTO{
Id: e.Id,
Name: e.Name,
}
}
func ToFlockListDTO(e entity.Flock) FlockListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
return FlockListDTO{
FlockBaseDTO: ToFlockBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
FlockRelationDTO: ToFlockRelationDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
@@ -10,25 +10,25 @@ import (
// === DTO Structs ===
type KandangBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Capacity float64 `json:"capacity"`
Location locationDTO.LocationBaseDTO `json:"location,omitempty"`
Pic userDTO.UserBaseDTO `json:"pic,omitempty"`
type KandangRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Capacity float64 `json:"capacity"`
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
Pic *userDTO.UserRelationDTO `json:"pic,omitempty"`
}
type KandangListDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Capacity float64 `json:"capacity"`
Location locationDTO.LocationBaseDTO `json:"location"`
Pic userDTO.UserBaseDTO `json:"pic"`
CreatedUser userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
Capacity float64 `json:"capacity"`
Location locationDTO.LocationRelationDTO `json:"location"`
Pic userDTO.UserRelationDTO `json:"pic"`
CreatedUser userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type KandangDetailDTO struct {
@@ -37,20 +37,20 @@ type KandangDetailDTO struct {
// === Mapper Functions ===
func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
var location locationDTO.LocationBaseDTO
func ToKandangRelationDTO(e entity.Kandang) KandangRelationDTO {
var location *locationDTO.LocationRelationDTO
if e.Location.Id != 0 {
mapped := locationDTO.ToLocationBaseDTO(e.Location)
location = mapped
mapped := locationDTO.ToLocationRelationDTO(e.Location)
location = &mapped
}
var pic userDTO.UserBaseDTO
var pic *userDTO.UserRelationDTO
if e.Pic.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.Pic)
pic = mapped
mapped := userDTO.ToUserRelationDTO(e.Pic)
pic = &mapped
}
return KandangBaseDTO{
return KandangRelationDTO{
Id: e.Id,
Name: e.Name,
Status: e.Status,
@@ -61,21 +61,21 @@ func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
}
func ToKandangListDTO(e entity.Kandang) KandangListDTO {
var location locationDTO.LocationBaseDTO
var location locationDTO.LocationRelationDTO
if e.Location.Id != 0 {
mapped := locationDTO.ToLocationBaseDTO(e.Location)
mapped := locationDTO.ToLocationRelationDTO(e.Location)
location = mapped
}
var pic userDTO.UserBaseDTO
var pic userDTO.UserRelationDTO
if e.Pic.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.Pic)
mapped := userDTO.ToUserRelationDTO(e.Pic)
pic = mapped
}
var createdUser userDTO.UserBaseDTO
var createdUser userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = mapped
}
@@ -7,6 +7,7 @@ import (
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gitlab.com/mbugroup/lti-api.git/internal/utils"
"github.com/gofiber/fiber/v2"
"gorm.io/gorm"
)
@@ -120,9 +121,41 @@ func (r *KandangRepositoryImpl) UpsertProjectFlockKandang(ctx context.Context, p
Where("project_flock_id = ? AND kandang_id = ?", projectFlockID, kandangID).
First(&link).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
var project entity.ProjectFlock
if err := r.db.WithContext(ctx).
Select("id, location_id").
First(&project, projectFlockID).Error; err != nil {
return err
}
var kandang entity.Kandang
if err := r.db.WithContext(ctx).
Select("id, location_id").
First(&kandang, kandangID).Error; err != nil {
return err
}
if kandang.LocationId != project.LocationId {
return fiber.NewError(fiber.StatusBadRequest, "Kandang tidak berada pada lokasi yang sama dengan project flock")
}
// Determine project's period from existing pivot rows so the new kandang
// shares the same period.
var period int
if err := r.db.WithContext(ctx).
Table("project_flock_kandangs").
Where("project_flock_id = ?", projectFlockID).
Select("COALESCE(MAX(period), 0)").
Scan(&period).Error; err != nil {
return err
}
if period <= 0 {
period = 1
}
link = entity.ProjectFlockKandang{
ProjectFlockId: projectFlockID,
KandangId: kandangID,
Period: period,
}
return r.db.WithContext(ctx).Create(&link).Error
}
@@ -10,21 +10,21 @@ import (
// === DTO Structs ===
type LocationBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
type LocationRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
}
type LocationListDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Area *areaDTO.AreaBaseDTO `json:"area"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
Area *areaDTO.AreaRelationDTO `json:"area"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type LocationDetailDTO struct {
@@ -33,14 +33,14 @@ type LocationDetailDTO struct {
// === Mapper Functions ===
func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
var area *areaDTO.AreaBaseDTO
func ToLocationRelationDTO(e entity.Location) LocationRelationDTO {
var area *areaDTO.AreaRelationDTO
if e.Area.Id != 0 {
mapped := areaDTO.ToAreaBaseDTO(e.Area)
mapped := areaDTO.ToAreaRelationDTO(e.Area)
area = &mapped
}
return LocationBaseDTO{
return LocationRelationDTO{
Id: e.Id,
Name: e.Name,
Address: e.Address,
@@ -49,15 +49,15 @@ func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
}
func ToLocationListDTO(e entity.Location) LocationListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
var area *areaDTO.AreaBaseDTO
var area *areaDTO.AreaRelationDTO
if e.Area.Id != 0 {
mapped := areaDTO.ToAreaBaseDTO(e.Area)
mapped := areaDTO.ToAreaRelationDTO(e.Area)
area = &mapped
}
@@ -4,41 +4,39 @@ import (
"time"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
)
// === DTO Structs ===
type NonstockBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Uom *uomDTO.UomBaseDTO `json:"uom,omitempty"`
Flags []string `json:"flags"`
type NonstockRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
Flags []string `json:"flags"`
}
type NonstockListDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Uom *uomDTO.UomBaseDTO `json:"uom"`
Suppliers []supplierDTO.SupplierBaseDTO `json:"suppliers"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
Flags []string `json:"flags"`
Uom *uomDTO.UomRelationDTO `json:"uom"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type NonstockDetailDTO struct {
NonstockListDTO
Flags []string `json:"flags"`
}
// === Mapper Functions ===
func ToNonstockBaseDTO(e entity.Nonstock) NonstockBaseDTO {
var uomRef *uomDTO.UomBaseDTO
func ToNonstockRelationDTO(e entity.Nonstock) NonstockRelationDTO {
var uomRef *uomDTO.UomRelationDTO
if e.Uom.Id != 0 {
mapped := uomDTO.ToUomBaseDTO(e.Uom)
mapped := uomDTO.ToUomRelationDTO(e.Uom)
uomRef = &mapped
}
@@ -47,7 +45,7 @@ func ToNonstockBaseDTO(e entity.Nonstock) NonstockBaseDTO {
flags[i] = f.Name
}
return NonstockBaseDTO{
return NonstockRelationDTO{
Id: e.Id,
Name: e.Name,
Uom: uomRef,
@@ -56,23 +54,18 @@ func ToNonstockBaseDTO(e entity.Nonstock) NonstockBaseDTO {
}
func ToNonstockListDTO(e entity.Nonstock) NonstockListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
var uomRef *uomDTO.UomBaseDTO
var uomRef *uomDTO.UomRelationDTO
if e.Uom.Id != 0 {
mapped := uomDTO.ToUomBaseDTO(e.Uom)
mapped := uomDTO.ToUomRelationDTO(e.Uom)
uomRef = &mapped
}
suppliers := make([]supplierDTO.SupplierBaseDTO, len(e.Suppliers))
for i, s := range e.Suppliers {
suppliers[i] = supplierDTO.ToSupplierBaseDTO(s)
}
flags := make([]string, len(e.Flags))
for i, f := range e.Flags {
flags[i] = f.Name
@@ -81,11 +74,11 @@ func ToNonstockListDTO(e entity.Nonstock) NonstockListDTO {
return NonstockListDTO{
Id: e.Id,
Name: e.Name,
Flags: flags,
Uom: uomRef,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
Suppliers: suppliers,
}
}
@@ -98,13 +91,7 @@ func ToNonstockListDTOs(e []entity.Nonstock) []NonstockListDTO {
}
func ToNonstockDetailDTO(e entity.Nonstock) NonstockDetailDTO {
flags := make([]string, len(e.Flags))
for i, f := range e.Flags {
flags[i] = f.Name
}
return NonstockDetailDTO{
NonstockListDTO: ToNonstockListDTO(e),
Flags: flags,
}
}
@@ -19,6 +19,7 @@ type NonstockRepository interface {
DeleteFlags(ctx context.Context, tx *gorm.DB, nonstockID uint) error
GetFlags(ctx context.Context, nonstockID uint) ([]entity.Flag, error)
IdExists(ctx context.Context, id uint) (bool, error)
IsNonstockAssociatedWithSupplier(ctx context.Context, nonstockID uint, supplierID uint64) (bool, error)
}
type NonstockRepositoryImpl struct {
@@ -62,7 +63,7 @@ func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm
existingMap := make(map[uint]struct{}, len(existing))
for _, rel := range existing {
existingMap[rel.SupplierID] = struct{}{}
existingMap[rel.SupplierId] = struct{}{}
}
incomingMap := make(map[uint]struct{}, len(supplierIDs))
@@ -71,16 +72,16 @@ func (r *NonstockRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm
if _, exists := existingMap[id]; exists {
continue
}
record := entity.NonstockSupplier{NonstockID: nonstockID, SupplierID: id}
record := entity.NonstockSupplier{NonstockId: nonstockID, SupplierId: id}
if err := db.WithContext(ctx).Create(&record).Error; err != nil {
return err
}
}
for _, rel := range existing {
if _, keep := incomingMap[rel.SupplierID]; !keep {
if _, keep := incomingMap[rel.SupplierId]; !keep {
if err := db.WithContext(ctx).
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, rel.SupplierID).
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, rel.SupplierId).
Delete(&entity.NonstockSupplier{}).
Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -175,3 +176,15 @@ func (r *NonstockRepositoryImpl) GetFlags(ctx context.Context, nonstockID uint)
}
return flags, nil
}
func (r *NonstockRepositoryImpl) IsNonstockAssociatedWithSupplier(ctx context.Context, nonstockID uint, supplierID uint64) (bool, error) {
var count int64
if err := r.DB().WithContext(ctx).
Model(&entity.NonstockSupplier{}).
Where("nonstock_id = ? AND supplier_id = ?", nonstockID, supplierID).
Count(&count).
Error; err != nil {
return false, err
}
return count > 0, nil
}
@@ -44,7 +44,8 @@ func (s nonstockService) withRelations(db *gorm.DB) *gorm.DB {
Preload("CreatedUser").
Preload("Uom").
Preload("Flags").
Preload("Suppliers", func(db *gorm.DB) *gorm.DB {
Preload("NonstockSuppliers").
Preload("NonstockSuppliers.Supplier", func(db *gorm.DB) *gorm.DB {
return db.Order("suppliers.name ASC")
})
}
@@ -9,17 +9,17 @@ import (
// === DTO Structs ===
type ProductCategoryBaseDTO struct {
type ProductCategoryRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Code string `json:"code"`
}
type ProductCategoryListDTO struct {
ProductCategoryBaseDTO
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ProductCategoryRelationDTO
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ProductCategoryDetailDTO struct {
@@ -28,8 +28,8 @@ type ProductCategoryDetailDTO struct {
// === Mapper Functions ===
func ToProductCategoryBaseDTO(e entity.ProductCategory) ProductCategoryBaseDTO {
return ProductCategoryBaseDTO{
func ToProductCategoryRelationDTO(e entity.ProductCategory) ProductCategoryRelationDTO {
return ProductCategoryRelationDTO{
Id: e.Id,
Name: e.Name,
Code: e.Code,
@@ -37,17 +37,17 @@ func ToProductCategoryBaseDTO(e entity.ProductCategory) ProductCategoryBaseDTO {
}
func ToProductCategoryListDTO(e entity.ProductCategory) ProductCategoryListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
return ProductCategoryListDTO{
ProductCategoryBaseDTO: ToProductCategoryBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
ProductCategoryRelationDTO: ToProductCategoryRelationDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
@@ -5,93 +5,105 @@ import (
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
productCategoryDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/product-categories/dto"
supplierDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/dto"
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
)
// === DTO Structs ===
type ProductBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Uom *uomDTO.UomBaseDTO `json:"uom,omitempty"`
Flags []string `json:"flags"`
type ProductRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
ProductPrice float64 `gorm:"type:numeric(15,3);not null"`
SellingPrice *float64 `gorm:"type:numeric(15,3)"`
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
Flags *[]string `json:"flags,omitempty"`
}
type ProductListDTO struct {
ProductBaseDTO
Brand string `json:"brand"`
Sku *string `json:"sku,omitempty"`
ProductPrice float64 `json:"product_price"`
SellingPrice *float64 `json:"selling_price,omitempty"`
Tax *float64 `json:"tax,omitempty"`
ExpiryPeriod *int `json:"expiry_period,omitempty"`
ProductCategory *productCategoryDTO.ProductCategoryBaseDTO `json:"product_category,omitempty"`
Suppliers []supplierDTO.SupplierBaseDTO `json:"suppliers"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
Brand string `json:"brand"`
Sku *string `json:"sku,omitempty"`
ProductPrice float64 `json:"product_price"`
SellingPrice *float64 `json:"selling_price,omitempty"`
Tax *float64 `json:"tax,omitempty"`
ExpiryPeriod *int `json:"expiry_period,omitempty"`
Flags []string `json:"flags"`
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
ProductCategory *productCategoryDTO.ProductCategoryRelationDTO `json:"product_category,omitempty"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ProductDetailDTO struct {
ProductListDTO
Flags []string `json:"flags"`
}
// === Mapper Functions ===
func ToProductBaseDTO(e entity.Product) ProductBaseDTO {
func ToProductRelationDTO(e entity.Product) ProductRelationDTO {
flags := make([]string, len(e.Flags))
for i, f := range e.Flags {
flags[i] = f.Name
}
var uomRef *uomDTO.UomBaseDTO
var uomRef *uomDTO.UomRelationDTO
if e.Uom.Id != 0 {
mapped := uomDTO.ToUomBaseDTO(e.Uom)
mapped := uomDTO.ToUomRelationDTO(e.Uom)
uomRef = &mapped
}
return ProductBaseDTO{
Id: e.Id,
Name: e.Name,
Flags: flags,
Uom: uomRef,
return ProductRelationDTO{
Id: e.Id,
Name: e.Name,
ProductPrice: e.ProductPrice,
SellingPrice: e.SellingPrice,
Flags: &flags,
Uom: uomRef,
}
}
func ToProductListDTO(e entity.Product) ProductListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
var categoryRef *productCategoryDTO.ProductCategoryBaseDTO
var categoryRef *productCategoryDTO.ProductCategoryRelationDTO
if e.ProductCategory.Id != 0 {
mapped := productCategoryDTO.ToProductCategoryBaseDTO(e.ProductCategory)
mapped := productCategoryDTO.ToProductCategoryRelationDTO(e.ProductCategory)
categoryRef = &mapped
}
suppliers := make([]supplierDTO.SupplierBaseDTO, len(e.Suppliers))
for i, s := range e.Suppliers {
suppliers[i] = supplierDTO.ToSupplierBaseDTO(s)
flags := make([]string, len(e.Flags))
for i, f := range e.Flags {
flags[i] = f.Name
}
var uomRef *uomDTO.UomRelationDTO
if e.Uom.Id != 0 {
mapped := uomDTO.ToUomRelationDTO(e.Uom)
uomRef = &mapped
}
return ProductListDTO{
Id: e.Id,
Name: e.Name,
Flags: flags,
Uom: uomRef,
Brand: e.Brand,
Sku: e.Sku,
ProductPrice: e.ProductPrice,
SellingPrice: e.SellingPrice,
Tax: e.Tax,
ExpiryPeriod: e.ExpiryPeriod,
ProductBaseDTO: ToProductBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
ProductCategory: categoryRef,
Suppliers: suppliers,
}
}
@@ -104,13 +116,7 @@ func ToProductListDTOs(e []entity.Product) []ProductListDTO {
}
func ToProductDetailDTO(e entity.Product) ProductDetailDTO {
flags := make([]string, len(e.Flags))
for i, f := range e.Flags {
flags[i] = f.Name
}
return ProductDetailDTO{
ProductListDTO: ToProductListDTO(e),
Flags: flags,
}
}
@@ -102,13 +102,13 @@ func (r *ProductRepositoryImpl) IsLinkedToSupplier(ctx context.Context, productI
return count > 0, nil
}
func (r *ProductRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.DB, productID uint, supplierIDs []uint) error {
func (r *ProductRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.DB, productID uint, supplierIds []uint) error {
db := tx
if db == nil {
db = r.DB()
}
if supplierIDs == nil {
if supplierIds == nil {
return db.WithContext(ctx).
Where("product_id = ?", productID).
Delete(&entity.ProductSupplier{}).
@@ -125,25 +125,25 @@ func (r *ProductRepositoryImpl) SyncSuppliersDiff(ctx context.Context, tx *gorm.
existingMap := make(map[uint]struct{}, len(existing))
for _, rel := range existing {
existingMap[rel.SupplierID] = struct{}{}
existingMap[rel.SupplierId] = struct{}{}
}
incomingMap := make(map[uint]struct{}, len(supplierIDs))
for _, id := range supplierIDs {
incomingMap := make(map[uint]struct{}, len(supplierIds))
for _, id := range supplierIds {
incomingMap[id] = struct{}{}
if _, exists := existingMap[id]; exists {
continue
}
record := entity.ProductSupplier{ProductID: productID, SupplierID: id}
record := entity.ProductSupplier{ProductId: productID, SupplierId: id}
if err := db.WithContext(ctx).Create(&record).Error; err != nil {
return err
}
}
for _, rel := range existing {
if _, keep := incomingMap[rel.SupplierID]; !keep {
if _, keep := incomingMap[rel.SupplierId]; !keep {
if err := db.WithContext(ctx).
Where("product_id = ? AND supplier_id = ?", productID, rel.SupplierID).
Where("product_id = ? AND supplier_id = ?", productID, rel.SupplierId).
Delete(&entity.ProductSupplier{}).
Error; err != nil {
return err
@@ -55,7 +55,8 @@ func (s productService) withRelations(db *gorm.DB) *gorm.DB {
Preload("Uom").
Preload("ProductCategory").
Preload("Flags").
Preload("Suppliers", func(db *gorm.DB) *gorm.DB {
Preload("ProductSuppliers").
Preload("ProductSuppliers.Supplier", func(db *gorm.DB) *gorm.DB {
return db.Order("suppliers.name ASC")
})
}
@@ -24,9 +24,10 @@ func NewSupplierController(supplierService service.SupplierService) *SupplierCon
func (u *SupplierController) GetAll(c *fiber.Ctx) error {
query := &validation.Query{
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: c.Query("search", ""),
Page: c.QueryInt("page", 1),
Limit: c.QueryInt("limit", 10),
Search: c.Query("search", ""),
Category: c.Query("category", ""),
}
if query.Page < 1 || query.Limit < 1 {
@@ -71,7 +72,7 @@ func (u *SupplierController) GetOne(c *fiber.Ctx) error {
Code: fiber.StatusOK,
Status: "success",
Message: "Get supplier successfully",
Data: dto.ToSupplierListDTO(*result),
Data: dto.ToSupplierDetailDTO(*result),
})
}
@@ -9,7 +9,7 @@ import (
// === DTO Structs ===
type SupplierBaseDTO struct {
type SupplierRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Alias string `json:"alias"`
@@ -17,30 +17,32 @@ type SupplierBaseDTO struct {
}
type SupplierListDTO struct {
SupplierBaseDTO
Pic string `json:"pic"`
Type string `json:"type"`
Hatchery *string `json:"hatchery,omitempty"`
Phone string `json:"phone"`
Email string `json:"email"`
Address string `json:"address"`
Npwp *string `json:"npwp,omitempty"`
AccountNumber *string `json:"account_number,omitempty"`
Balance float64 `json:"balance"`
DueDate int `json:"due_date"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
SupplierRelationDTO
Pic string `json:"pic"`
Type string `json:"type"`
Hatchery *string `json:"hatchery,omitempty"`
Phone string `json:"phone"`
Email string `json:"email"`
Address string `json:"address"`
Npwp *string `json:"npwp,omitempty"`
AccountNumber *string `json:"account_number,omitempty"`
Balance float64 `json:"balance"`
DueDate int `json:"due_date"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SupplierDetailDTO struct {
SupplierListDTO
Products []SupplierProductDTO `json:"products"`
Nonstocks []SupplierNonstockDTO `json:"nonstocks"`
}
// === Mapper Functions ===
func ToSupplierBaseDTO(e entity.Supplier) SupplierBaseDTO {
return SupplierBaseDTO{
func ToSupplierRelationDTO(e entity.Supplier) SupplierRelationDTO {
return SupplierRelationDTO{
Id: e.Id,
Name: e.Name,
Alias: e.Alias,
@@ -49,27 +51,27 @@ func ToSupplierBaseDTO(e entity.Supplier) SupplierBaseDTO {
}
func ToSupplierListDTO(e entity.Supplier) SupplierListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
return SupplierListDTO{
Pic: e.Pic,
Type: e.Type,
Hatchery: e.Hatchery,
Phone: e.Phone,
Email: e.Email,
Address: e.Address,
Npwp: e.Npwp,
AccountNumber: e.AccountNumber,
Balance: e.Balance,
DueDate: e.DueDate,
SupplierBaseDTO: ToSupplierBaseDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
Pic: e.Pic,
Type: e.Type,
Hatchery: e.Hatchery,
Phone: e.Phone,
Email: e.Email,
Address: e.Address,
Npwp: e.Npwp,
AccountNumber: e.AccountNumber,
Balance: e.Balance,
DueDate: e.DueDate,
SupplierRelationDTO: ToSupplierRelationDTO(e),
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
CreatedUser: createdUser,
}
}
@@ -84,5 +86,7 @@ func ToSupplierListDTOs(e []entity.Supplier) []SupplierListDTO {
func ToSupplierDetailDTO(e entity.Supplier) SupplierDetailDTO {
return SupplierDetailDTO{
SupplierListDTO: ToSupplierListDTO(e),
Products: toSupplierProductDTOs(e.ProductSuppliers),
Nonstocks: toSupplierNonstockDTOs(e.NonstockSuppliers),
}
}
@@ -0,0 +1,50 @@
package dto
import (
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
)
// === DTO Structs ===
type SupplierNonstockDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
Flags []string `json:"flags"`
}
// === Mapper Functions ===
func toSupplierNonstockDTOs(relations []entity.NonstockSupplier) []SupplierNonstockDTO {
if len(relations) == 0 {
return nil
}
result := make([]SupplierNonstockDTO, 0, len(relations))
for _, relation := range relations {
Nonstock := relation.Nonstock
if Nonstock.Id == 0 {
continue
}
flags := make([]string, len(Nonstock.Flags))
for i, f := range Nonstock.Flags {
flags[i] = f.Name
}
var uomRef *uomDTO.UomRelationDTO
if Nonstock.Uom.Id != 0 {
mapped := uomDTO.ToUomRelationDTO(Nonstock.Uom)
uomRef = &mapped
}
result = append(result, SupplierNonstockDTO{
Id: Nonstock.Id,
Name: Nonstock.Name,
Uom: uomRef,
Flags: flags,
})
}
return result
}
@@ -0,0 +1,54 @@
package dto
import (
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
uomDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/uoms/dto"
)
// === DTO Structs ===
type SupplierProductDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
ProductPrice float64 `gorm:"type:numeric(15,3);not null"`
SellingPrice *float64 `gorm:"type:numeric(15,3)"`
Uom *uomDTO.UomRelationDTO `json:"uom,omitempty"`
Flags []string `json:"flags"`
}
// === Mapper Functions ===
func toSupplierProductDTOs(relations []entity.ProductSupplier) []SupplierProductDTO {
if len(relations) == 0 {
return nil
}
result := make([]SupplierProductDTO, 0, len(relations))
for _, relation := range relations {
product := relation.Product
if product.Id == 0 {
continue
}
flags := make([]string, len(product.Flags))
for i, f := range product.Flags {
flags[i] = f.Name
}
var uomRef *uomDTO.UomRelationDTO
if product.Uom.Id != 0 {
mapped := uomDTO.ToUomRelationDTO(product.Uom)
uomRef = &mapped
}
result = append(result, SupplierProductDTO{
Id: product.Id,
Name: product.Name,
ProductPrice: product.ProductPrice,
SellingPrice: product.SellingPrice,
Uom: uomRef,
Flags: flags,
})
}
return result
}
+2 -2
View File
@@ -1,7 +1,7 @@
package suppliers
import (
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
// m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
controller "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/controllers"
supplier "gitlab.com/mbugroup/lti-api.git/internal/modules/master/suppliers/services"
user "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
@@ -13,7 +13,7 @@ func SupplierRoutes(v1 fiber.Router, u user.UserService, s supplier.SupplierServ
ctrl := controller.NewSupplierController(s)
route := v1.Group("/suppliers")
route.Use(m.Auth(u))
// route.Use(m.Auth(u))
route.Get("/", ctrl.GetAll)
route.Post("/", ctrl.CreateOne)
@@ -39,7 +39,12 @@ func NewSupplierService(repo repository.SupplierRepository, validate *validator.
}
func (s supplierService) withRelations(db *gorm.DB) *gorm.DB {
return db.Preload("CreatedUser")
return db.
Preload("CreatedUser").
Preload("ProductSuppliers.Product.Uom").
Preload("ProductSuppliers.Product.Flags").
Preload("NonstockSuppliers.Nonstock.Uom").
Preload("NonstockSuppliers.Nonstock.Flags")
}
func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Supplier, int64, error) {
@@ -47,6 +52,14 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
return nil, 0, err
}
if params.Category != "" {
category := strings.ToUpper(params.Category)
if category != "BOP" && category != "SAPRONAK" {
return nil, 0, fiber.NewError(fiber.StatusBadRequest, "Invalid supplier category")
}
params.Category = category
}
offset := (params.Page - 1) * params.Limit
suppliers, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
@@ -54,6 +67,11 @@ func (s supplierService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entit
if params.Search != "" {
return db.Where("name LIKE ?", "%"+params.Search+"%")
}
if params.Category != "" {
db = db.Where("category LIKE ?", "%"+params.Category+"%")
}
return db.Order("created_at DESC").Order("updated_at DESC")
})
@@ -31,7 +31,8 @@ type Update struct {
}
type Query struct {
Page int `query:"page" validate:"omitempty,number,min=1"`
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
Search string `query:"search" validate:"omitempty,max=50"`
Page int `query:"page" validate:"omitempty,number,min=1"`
Limit int `query:"limit" validate:"omitempty,number,min=1,max=100"`
Search string `query:"search" validate:"omitempty,max=50"`
Category string `query:"category" validate:"omitempty,max=50"`
}
+10 -10
View File
@@ -9,17 +9,17 @@ import (
// === DTO Structs ===
type UomBaseDTO struct {
type UomRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type UomListDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type UomDetailDTO struct {
@@ -28,17 +28,17 @@ type UomDetailDTO struct {
// === Mapper Functions ===
func ToUomBaseDTO(e entity.Uom) UomBaseDTO {
return UomBaseDTO{
func ToUomRelationDTO(e entity.Uom) UomRelationDTO {
return UomRelationDTO{
Id: e.Id,
Name: e.Name,
}
}
func ToUomListDTO(e entity.Uom) UomListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
@@ -12,25 +12,25 @@ import (
// === DTO Structs ===
type WarehouseBaseDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Area *areaDTO.AreaBaseDTO `json:"area,omitempty"`
Location *locationDTO.LocationBaseDTO `json:"location,omitempty"`
Kandang *kandangDTO.KandangBaseDTO `json:"kandang,omitempty"`
type WarehouseRelationDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Area *areaDTO.AreaRelationDTO `json:"area,omitempty"`
Location *locationDTO.LocationRelationDTO `json:"location,omitempty"`
Kandang *kandangDTO.KandangRelationDTO `json:"kandang,omitempty"`
}
type WarehouseListDTO struct {
Id uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Area *areaDTO.AreaBaseDTO `json:"area"`
Location *locationDTO.LocationBaseDTO `json:"location"`
Kandang *kandangDTO.KandangBaseDTO `json:"kandang"`
CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Area *areaDTO.AreaRelationDTO `json:"area"`
Location *locationDTO.LocationRelationDTO `json:"location"`
Kandang *kandangDTO.KandangRelationDTO `json:"kandang"`
CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type WarehouseDetailDTO struct {
@@ -39,26 +39,26 @@ type WarehouseDetailDTO struct {
// === Mapper Functions ===
func ToWarehouseBaseDTO(e entity.Warehouse) WarehouseBaseDTO {
var area *areaDTO.AreaBaseDTO
func ToWarehouseRelationDTO(e entity.Warehouse) WarehouseRelationDTO {
var area *areaDTO.AreaRelationDTO
if e.Area.Id != 0 {
mapped := areaDTO.ToAreaBaseDTO(e.Area)
mapped := areaDTO.ToAreaRelationDTO(e.Area)
area = &mapped
}
var location *locationDTO.LocationBaseDTO
var location *locationDTO.LocationRelationDTO
if e.Location != nil && e.Location.Id != 0 {
mapped := locationDTO.ToLocationBaseDTO(*e.Location)
mapped := locationDTO.ToLocationRelationDTO(*e.Location)
location = &mapped
}
var kandang *kandangDTO.KandangBaseDTO
var kandang *kandangDTO.KandangRelationDTO
if e.Kandang != nil && e.Kandang.Id != 0 {
mapped := kandangDTO.ToKandangBaseDTO(*e.Kandang)
mapped := kandangDTO.ToKandangRelationDTO(*e.Kandang)
kandang = &mapped
}
return WarehouseBaseDTO{
return WarehouseRelationDTO{
Id: e.Id,
Name: e.Name,
Type: e.Type,
@@ -69,27 +69,27 @@ func ToWarehouseBaseDTO(e entity.Warehouse) WarehouseBaseDTO {
}
func ToWarehouseListDTO(e entity.Warehouse) WarehouseListDTO {
var createdUser *userDTO.UserBaseDTO
var createdUser *userDTO.UserRelationDTO
if e.CreatedUser.Id != 0 {
mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
createdUser = &mapped
}
var area *areaDTO.AreaBaseDTO
var area *areaDTO.AreaRelationDTO
if e.Area.Id != 0 {
mapped := areaDTO.ToAreaBaseDTO(e.Area)
mapped := areaDTO.ToAreaRelationDTO(e.Area)
area = &mapped
}
var location *locationDTO.LocationBaseDTO
var location *locationDTO.LocationRelationDTO
if e.Location != nil && e.Location.Id != 0 {
mapped := locationDTO.ToLocationBaseDTO(*e.Location)
mapped := locationDTO.ToLocationRelationDTO(*e.Location)
location = &mapped
}
var kandang *kandangDTO.KandangBaseDTO
var kandang *kandangDTO.KandangRelationDTO
if e.Kandang != nil && e.Kandang.Id != 0 {
mapped := kandangDTO.ToKandangBaseDTO(*e.Kandang)
mapped := kandangDTO.ToKandangRelationDTO(*e.Kandang)
kandang = &mapped
}