51 lines
1021 B
Go
51 lines
1021 B
Go
package transfer
|
|
|
|
import (
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
"gitea.pena/PenaSide/discount/internal/models"
|
|
"gitea.pena/PenaSide/discount/internal/proto/discount"
|
|
)
|
|
|
|
func AuditModelToProto(model *models.Audit) *discount.Audit {
|
|
proto := discount.Audit{}
|
|
|
|
if model == nil {
|
|
return &proto
|
|
}
|
|
|
|
proto.CreatedAt = timestamppb.New(model.CreatedAt)
|
|
proto.UpdatedAt = timestamppb.New(model.UpdatedAt)
|
|
|
|
if model.DeletedAt != nil {
|
|
proto.DeletedAt = timestamppb.New(*model.DeletedAt)
|
|
proto.Deleted = true
|
|
}
|
|
|
|
return &proto
|
|
}
|
|
|
|
func AuditProtoToModel(proto *discount.Audit) *models.Audit {
|
|
model := models.Audit{}
|
|
|
|
if proto == nil {
|
|
return &model
|
|
}
|
|
|
|
if proto.GetCreatedAt() != nil {
|
|
model.CreatedAt = proto.GetCreatedAt().AsTime()
|
|
}
|
|
|
|
if proto.GetUpdatedAt() != nil {
|
|
model.UpdatedAt = proto.GetUpdatedAt().AsTime()
|
|
}
|
|
|
|
if proto.GetDeletedAt() != nil {
|
|
deletedAt := proto.GetDeletedAt().AsTime()
|
|
model.DeletedAt = &deletedAt
|
|
}
|
|
|
|
model.Deleted = proto.GetDeleted()
|
|
|
|
return &model
|
|
}
|