2022-09-01 22:32:03 +00:00
|
|
|
package mappers
|
|
|
|
|
|
|
|
import (
|
2022-09-24 19:33:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/ent"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/types"
|
2022-09-01 22:32:03 +00:00
|
|
|
)
|
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
func ToItemAttachment(attachment *ent.Attachment) *types.ItemAttachment {
|
|
|
|
return &types.ItemAttachment{
|
|
|
|
ID: attachment.ID,
|
|
|
|
CreatedAt: attachment.CreatedAt,
|
|
|
|
UpdatedAt: attachment.UpdatedAt,
|
2022-09-24 19:33:38 +00:00
|
|
|
Type: attachment.Type.String(),
|
2022-09-12 22:47:27 +00:00
|
|
|
Document: types.DocumentOut{
|
|
|
|
ID: attachment.Edges.Document.ID,
|
|
|
|
Title: attachment.Edges.Document.Title,
|
|
|
|
Path: attachment.Edges.Document.Path,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
func ToItemSummary(item *ent.Item) *types.ItemSummary {
|
2022-09-03 09:17:48 +00:00
|
|
|
var location *types.LocationSummary
|
|
|
|
if item.Edges.Location != nil {
|
|
|
|
location = ToLocationSummary(item.Edges.Location)
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels []*types.LabelSummary
|
|
|
|
if item.Edges.Label != nil {
|
|
|
|
labels = MapEach(item.Edges.Label, ToLabelSummary)
|
|
|
|
}
|
|
|
|
|
2022-09-01 22:32:03 +00:00
|
|
|
return &types.ItemSummary{
|
|
|
|
ID: item.ID,
|
|
|
|
Name: item.Name,
|
|
|
|
Description: item.Description,
|
|
|
|
CreatedAt: item.CreatedAt,
|
|
|
|
UpdatedAt: item.UpdatedAt,
|
2022-09-03 09:17:48 +00:00
|
|
|
|
2022-09-12 22:47:27 +00:00
|
|
|
Quantity: item.Quantity,
|
|
|
|
Insured: item.Insured,
|
|
|
|
|
|
|
|
// Warranty
|
|
|
|
LifetimeWarranty: item.LifetimeWarranty,
|
|
|
|
WarrantyExpires: item.WarrantyExpires,
|
|
|
|
WarrantyDetails: item.WarrantyDetails,
|
|
|
|
|
2022-09-03 09:17:48 +00:00
|
|
|
// Edges
|
|
|
|
Location: location,
|
|
|
|
Labels: labels,
|
|
|
|
|
|
|
|
// Identification
|
|
|
|
SerialNumber: item.SerialNumber,
|
|
|
|
ModelNumber: item.ModelNumber,
|
|
|
|
Manufacturer: item.Manufacturer,
|
|
|
|
|
|
|
|
// Purchase
|
|
|
|
PurchaseTime: item.PurchaseTime,
|
|
|
|
PurchaseFrom: item.PurchaseFrom,
|
|
|
|
PurchasePrice: item.PurchasePrice,
|
|
|
|
|
|
|
|
// Sold
|
|
|
|
SoldTime: item.SoldTime,
|
|
|
|
SoldTo: item.SoldTo,
|
|
|
|
SoldPrice: item.SoldPrice,
|
|
|
|
SoldNotes: item.SoldNotes,
|
|
|
|
|
|
|
|
// Extras
|
|
|
|
Notes: item.Notes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ToItemSummaryErr(item *ent.Item, err error) (*types.ItemSummary, error) {
|
|
|
|
return ToItemSummary(item), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func ToItemOut(item *ent.Item) *types.ItemOut {
|
2022-09-12 22:47:27 +00:00
|
|
|
var attachments []*types.ItemAttachment
|
|
|
|
if item.Edges.Attachments != nil {
|
|
|
|
attachments = MapEach(item.Edges.Attachments, ToItemAttachment)
|
|
|
|
}
|
|
|
|
|
2022-09-03 09:17:48 +00:00
|
|
|
return &types.ItemOut{
|
|
|
|
ItemSummary: *ToItemSummary(item),
|
2022-09-12 22:47:27 +00:00
|
|
|
Attachments: attachments,
|
2022-09-01 22:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-03 09:17:48 +00:00
|
|
|
|
|
|
|
func ToItemOutErr(item *ent.Item, err error) (*types.ItemOut, error) {
|
|
|
|
return ToItemOut(item), err
|
|
|
|
}
|