feat: add component_codes management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-11 11:00:46 +07:00
parent bf20286f04
commit 9ea72b4eea
14 changed files with 1562 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package mapper
import (
"wm-backend/internal/models"
db "wm-backend/sqlc_gen"
"encoding/json"
"github.com/jackc/pgx/v5/pgtype"
)
func ToDomainComponentCode(r db.ComponentCode) *models.ComponentCode {
return &models.ComponentCode{
ID: r.ID,
ComponentID: r.ComponentID,
Code: r.Code,
CodeType: r.CodeType.String,
IsPrimary: r.IsPrimary,
Metadata: json.RawMessage(r.Metadata),
CreatedAt: r.CreatedAt,
}
}
func ToModelComponentCode(r *models.ComponentCode) *db.CreateComponentCodeParams {
return &db.CreateComponentCodeParams{
ComponentID: r.ComponentID,
Code: r.Code,
CodeType: pgtype.Text{
String: r.CodeType,
Valid: r.CodeType != "",
},
IsPrimary: r.IsPrimary,
Metadata: []byte(r.Metadata),
CreatedAt: r.CreatedAt,
}
}
func ToUpdateModelComponentCode(r *models.ComponentCode) *db.UpdateComponentCodeParams {
var metadata []byte
if len(r.Metadata) > 0 {
metadata = []byte(r.Metadata)
}
return &db.UpdateComponentCodeParams{
Code: r.Code,
ComponentID: r.ComponentID,
CodeType: pgtype.Text{
String: r.CodeType,
Valid: r.CodeType != "",
},
IsPrimary: r.IsPrimary,
Metadata: metadata,
ID: r.ID,
}
}