61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package converts
|
|
|
|
import (
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/tigorlazuardi/bluemage/go/api"
|
|
"github.com/tigorlazuardi/bluemage/go/gen/models"
|
|
subreddits "github.com/tigorlazuardi/bluemage/go/gen/proto/subreddits/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 SubredditTypeToString
|
|
// goverter:extend SubredditTypeToOmitString
|
|
// goverter:extend SubredditsDisabledFilterToPtrBool
|
|
type SubredditConverter interface {
|
|
// goverter:ignore CreatedAt UpdatedAt CoverImageID
|
|
CreateSubredditRequestToModelsSubredditSetter(*subreddits.CreateSubredditRequest) *models.SubredditSetter
|
|
|
|
// goverter:useZeroValueOnPointerInconsistency
|
|
ProtoCountSubredditsRequestToAPICountSubredditsRequest(*subreddits.CountSubredditsRequest) api.CountSubredditsRequest
|
|
}
|
|
|
|
func SubredditTypeToString(subType subreddits.SubredditType) string {
|
|
if subType == subreddits.SubredditType_SUBREDDIT_TYPE_USER {
|
|
return "user"
|
|
}
|
|
return "r"
|
|
}
|
|
|
|
func SubredditTypeToOmitString(subType subreddits.SubredditType) omit.Val[string] {
|
|
if subType == subreddits.SubredditType_SUBREDDIT_TYPE_USER {
|
|
return omit.From("user")
|
|
}
|
|
return omit.From("r")
|
|
}
|
|
|
|
func SubredditsDisabledFilterToPtrBool(filter subreddits.DisabledFilter) *bool {
|
|
switch filter {
|
|
case subreddits.DisabledFilter_DISABLED_FILTER_TRUE:
|
|
return boolPtr(true)
|
|
case subreddits.DisabledFilter_DISABLED_FILTER_FALSE:
|
|
return boolPtr(false)
|
|
}
|
|
return nil
|
|
}
|