103 lines
2.7 KiB
Go
103 lines
2.7 KiB
Go
|
package converts
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/tigorlazuardi/bluemage/go/api"
|
||
|
"github.com/tigorlazuardi/bluemage/go/gen/jet/model"
|
||
|
images "github.com/tigorlazuardi/bluemage/go/gen/proto/images/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 ImagesOrderByToString
|
||
|
// goverter:extend ImagesSortToAPISort
|
||
|
// goverter:extend ImagesNSFWToPtrBool
|
||
|
// goverter:extend ImagesBlacklistToPtrBool
|
||
|
// goverter:extend Int8ToImagesNSFW
|
||
|
// goverter:extend Int8ToImagesBlacklist
|
||
|
type ImageConverter interface {
|
||
|
// goverter:useZeroValueOnPointerInconsistency
|
||
|
// goverter:map Nsfw NSFW
|
||
|
ProtoListImagesRequestToAPIImagesRequest(*images.ListImagesRequest) api.ImageListRequest
|
||
|
|
||
|
// goverter:map ID Id
|
||
|
// goverter:map PostURL PostUrl
|
||
|
// goverter:map PostAuthorURL PostAuthorUrl
|
||
|
// goverter:map ImageOriginalURL ImageOriginalUrl
|
||
|
// goverter:ignore state sizeCache unknownFields
|
||
|
// goverter:useZeroValueOnPointerInconsistency
|
||
|
JetImageToProtoImage(model.Images) *images.Image
|
||
|
JetImagesToProtoImages([]model.Images) []*images.Image
|
||
|
}
|
||
|
|
||
|
func ImagesOrderByToString(order images.OrderBy) string {
|
||
|
if order == images.OrderBy_ORDER_BY_UNSPECIFIED {
|
||
|
return ""
|
||
|
}
|
||
|
field := strings.TrimPrefix(images.OrderBy_name[int32(order)], "ORDER_BY_")
|
||
|
field = strings.ToLower(field)
|
||
|
return field
|
||
|
}
|
||
|
|
||
|
func ImagesSortToAPISort(s images.Sort) api.Sort {
|
||
|
if s == images.Sort_SORT_DESCENDING {
|
||
|
return api.SortDesc
|
||
|
}
|
||
|
return api.SortAsc
|
||
|
}
|
||
|
|
||
|
func ImagesNSFWToPtrBool(n images.NSFW) *bool {
|
||
|
if n == images.NSFW_NSFW_UNSPECIFIED {
|
||
|
return nil
|
||
|
}
|
||
|
b := (n == images.NSFW_NSFW_TRUE)
|
||
|
return &b
|
||
|
}
|
||
|
|
||
|
func Int8ToImagesNSFW(i int8) images.NSFW {
|
||
|
switch i {
|
||
|
case 1:
|
||
|
return images.NSFW_NSFW_TRUE
|
||
|
case 0:
|
||
|
return images.NSFW_NSFW_FALSE
|
||
|
default:
|
||
|
return images.NSFW_NSFW_UNSPECIFIED
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func ImagesBlacklistToPtrBool(b images.Blacklist) *bool {
|
||
|
if b == images.Blacklist_BLACKLIST_UNSPECIFIED {
|
||
|
return nil
|
||
|
}
|
||
|
t := (b == images.Blacklist_BLACKLIST_TRUE)
|
||
|
return &t
|
||
|
}
|
||
|
|
||
|
func Int8ToImagesBlacklist(i int8) images.Blacklist {
|
||
|
switch i {
|
||
|
case 1:
|
||
|
return images.Blacklist_BLACKLIST_TRUE
|
||
|
case 0:
|
||
|
return images.Blacklist_BLACKLIST_FALSE
|
||
|
default:
|
||
|
return images.Blacklist_BLACKLIST_UNSPECIFIED
|
||
|
}
|
||
|
}
|