Bluemage/go/converts/device.go

78 lines
2.4 KiB
Go
Raw Normal View History

package converts
2024-08-05 23:06:32 +07:00
import (
"strings"
"github.com/tigorlazuardi/bluemage/go/api"
"github.com/tigorlazuardi/bluemage/go/gen/jet/model"
2024-08-05 23:06:32 +07:00
"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 BoolToOmitInt8
// goverter:extend PtrStringToOmitString
// goverter:extend PtrFloat64ToOmitFloat64
// goverter:extend PtrInt32ToOmitInt32
// goverter:extend PtrInt64ToOmitInt64
// goverter:extend PtrIntToOmitInt
// goverter:extend PtrInt8ToOmitInt8
// goverter:extend IntToOmitInt
// goverter:extend Int8ToOmitInt8
// goverter:extend Int32ToOmitInt32
// goverter:extend Int64ToOmitInt64
// goverter:extend Float64ToOmitFloat64
// goverter:extend StringToOmitString
// goverter:extend DeviceDisabledFilterToPtrBool
// goverter:extend DeviceOrderByToString
// goverter:extend DeviceSortToAPISort
2024-08-05 23:06:32 +07:00
type DeviceConverter interface {
// goverter:ignore CreatedAt UpdatedAt
2024-08-05 23:06:32 +07:00
// goverter:map Nsfw NSFW
CreateDeviceRequestToModelsDeviceSetter(*device.CreateDeviceRequest) *models.DeviceSetter
2024-08-05 23:06:32 +07:00
// goverter:ignore state sizeCache unknownFields
ModelsDeviceToCreateDeviceResponse(*models.Device) *device.CreateDeviceResponse
// goverter:ignore state sizeCache unknownFields
// goverter:useZeroValueOnPointerInconsistency
JetModelDeviceToProtoDevice(model.Devices) *device.Device
// goverter:useZeroValueOnPointerInconsistency
ProtoListDevicesRequestToAPIListDevicesRequest(*device.ListDevicesRequest) api.ListDevicesRequest
// goverter:ignore Slug SingleFolderMode CreatedAt UpdatedAt
// goverter:map Nsfw NSFW
DeviceSetterProtoToModelsDeviceSetter(*device.DeviceSetter) *models.DeviceSetter
2024-08-05 23:06:32 +07:00
}
func DeviceDisabledFilterToPtrBool(f device.DisabledFilter) *bool {
switch f {
case device.DisabledFilter_DISABLED_FILTER_TRUE:
b := true
return &b
case device.DisabledFilter_DISABLED_FILTER_FALSE:
b := false
return &b
default:
return nil
2024-08-05 23:06:32 +07:00
}
}
func DeviceOrderByToString(order device.OrderBy) string {
if order == device.OrderBy_ORDER_BY_UNSPECIFIED {
return ""
}
field, _ := strings.CutPrefix(device.OrderBy_name[int32(order)], "ORDER_BY_")
field = strings.ToLower(field)
return field
}
func DeviceSortToAPISort(sort device.Sort) api.Sort {
if sort == device.Sort_SORT_DESCENDING {
return api.SortDesc
}
return api.SortDesc
2024-08-05 23:06:32 +07:00
}