Bluemage/go/converts/converter.go

68 lines
1.6 KiB
Go

package converts
import (
"github.com/aarondl/opt/omit"
"github.com/tigorlazuardi/bluemage/go/gen/models"
device "github.com/tigorlazuardi/bluemage/go/gen/proto/device/v1"
)
// goverter:converter
// goverter:extend BoolToInt8
// goverter:extend Int8ToBool
// goverter:extend PtrBoolToOmitInt8
// goverter:extend PtrStringToOmitString
// goverter:extend PtrFloat64ToOmitFloat64
// goverter:extend PtrInt32ToOmitInt32
type DeviceConverter interface {
// goverter:ignore CreatedAt UpdatedAt R
// goverter:map Nsfw NSFW
CreateDeviceRequestToModelsDevice(*device.CreateDeviceRequest) *models.Device
// goverter:ignore state sizeCache unknownFields
ModelsDeviceToCreateDeviceResponse(*models.Device) *device.CreateDeviceResponse
// goverter:ignore state sizeCache unknownFields
// goverter:map NSFW Nsfw
ModelsDeviceToGetDeviceResponse(*models.Device) *device.GetDeviceResponse
// goverter:ignore Slug SingleFolderMode CreatedAt UpdatedAt
// goverter:map Nsfw NSFW
DeviceSetterProtoToModelsDeviceSetter(*device.DeviceSetter) *models.DeviceSetter
}
func BoolToInt8(b bool) int8 {
if b {
return 1
}
return 0
}
func PtrBoolToOmitInt8(b *bool) omit.Val[int8] {
if b == nil {
return omit.Val[int8]{}
}
v := *b
if v {
return omit.From(int8(1))
}
return omit.From(int8(0))
}
func PtrStringToOmitString(s *string) omit.Val[string] {
return omit.FromPtr(s)
}
func PtrFloat64ToOmitFloat64(f *float64) omit.Val[float64] {
return omit.FromPtr(f)
}
func PtrInt32ToOmitInt32(i *int32) omit.Val[int32] {
return omit.FromPtr(i)
}
func PtrInt64ToOmitInt64(i *int64) omit.Val[int64] {
return omit.FromPtr(i)
}
func Int8ToBool(i int8) bool {
return i > 0
}