mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-116): add project chick in database schema
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
@@ -18,11 +17,16 @@ type ProductWarehouseBaseDTO struct {
|
||||
|
||||
type ProductWarehouseListDTO struct {
|
||||
ProductWarehouseBaseDTO
|
||||
Product *ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
CreatedUser *userDTO.UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Product *ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
CreatedUser *UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UserBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type ProductWarehouseDetailDTO struct {
|
||||
@@ -38,6 +42,24 @@ type ProductBaseDTO struct {
|
||||
}
|
||||
|
||||
type WarehouseBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Kandang *KandangBaseDTO `json:"kandang,omitempty"`
|
||||
Location *LocationBaseDTO `json:"location,omitempty"`
|
||||
Area *AreaBaseDTO `json:"area,omitempty"`
|
||||
}
|
||||
|
||||
type KandangBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type LocationBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type AreaBaseDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
@@ -69,7 +91,6 @@ func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDT
|
||||
if e.Product.Sku != nil {
|
||||
product.Sku = *e.Product.Sku
|
||||
}
|
||||
// Map flags from Product relation
|
||||
if len(e.Product.Flags) > 0 {
|
||||
for _, f := range e.Product.Flags {
|
||||
product.Flags = append(product.Flags, f.Name)
|
||||
@@ -84,12 +105,37 @@ func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDT
|
||||
Id: e.Warehouse.Id,
|
||||
Name: e.Warehouse.Name,
|
||||
}
|
||||
// Map Kandang jika ada
|
||||
if e.Warehouse.Kandang != nil && e.Warehouse.Kandang.Id != 0 {
|
||||
warehouse.Kandang = &KandangBaseDTO{
|
||||
Id: e.Warehouse.Kandang.Id,
|
||||
Name: e.Warehouse.Kandang.Name,
|
||||
}
|
||||
}
|
||||
// Map Location jika ada
|
||||
if e.Warehouse.Location != nil && e.Warehouse.Location.Id != 0 {
|
||||
warehouse.Location = &LocationBaseDTO{
|
||||
Id: e.Warehouse.Location.Id,
|
||||
Name: e.Warehouse.Location.Name,
|
||||
}
|
||||
}
|
||||
|
||||
if &e.Warehouse.Area != nil && e.Warehouse.Area.Id != 0 {
|
||||
warehouse.Area = &AreaBaseDTO{
|
||||
Id: e.Warehouse.Area.Id,
|
||||
Name: e.Warehouse.Area.Name,
|
||||
}
|
||||
}
|
||||
|
||||
dto.Warehouse = &warehouse
|
||||
}
|
||||
|
||||
// Map CreatedUser relation jika ada
|
||||
if e.CreatedUser.Id != 0 {
|
||||
user := userDTO.ToUserBaseDTO(e.CreatedUser)
|
||||
user := UserBaseDTO{
|
||||
Id: e.CreatedUser.Id,
|
||||
Username: e.CreatedUser.Name,
|
||||
}
|
||||
dto.CreatedUser = &user
|
||||
}
|
||||
|
||||
@@ -109,3 +155,24 @@ func ToProductWarehouseDetailDTO(e entity.ProductWarehouse) ProductWarehouseDeta
|
||||
ProductWarehouseListDTO: ToProductWarehouseListDTO(e),
|
||||
}
|
||||
}
|
||||
|
||||
func ToKandangBaseDTO(e entity.Kandang) KandangBaseDTO {
|
||||
return KandangBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToLocationBaseDTO(e entity.Location) LocationBaseDTO {
|
||||
return LocationBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func ToAreaBaseDTO(e entity.Area) AreaBaseDTO {
|
||||
return AreaBaseDTO{
|
||||
Id: e.Id,
|
||||
Name: e.Name,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,12 @@ func NewProductWarehouseService(repo repository.ProductWarehouseRepository, vali
|
||||
|
||||
func (s productWarehouseService) withRelations(db *gorm.DB) *gorm.DB {
|
||||
return db.
|
||||
Preload("Product.Flags").
|
||||
Preload("Product").
|
||||
Preload("Product.Flags").
|
||||
Preload("Warehouse").
|
||||
Preload("Warehouse.Location").
|
||||
Preload("Warehouse.Kandang").
|
||||
Preload("Warehouse.Area").
|
||||
Preload("CreatedUser")
|
||||
}
|
||||
|
||||
@@ -85,6 +88,7 @@ func (s productWarehouseService) GetOne(c *fiber.Ctx, id uint) (*entity.ProductW
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, fiber.NewError(fiber.StatusNotFound, "ProductWarehouse not found")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed get productWarehouse by id: %+v", err)
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user