discount/internal/utils/transfer/audit.go

51 lines
1021 B
Go
Raw Normal View History

2023-07-04 04:04:31 +00:00
package transfer
import (
"google.golang.org/protobuf/types/known/timestamppb"
2024-12-11 12:14:39 +00:00
"gitea.pena/PenaSide/discount/internal/models"
"gitea.pena/PenaSide/discount/internal/proto/discount"
2023-07-04 04:04:31 +00:00
)
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
}