2024-08-11 10:23:20 +07:00
|
|
|
package converts
|
|
|
|
|
|
|
|
import (
|
2024-08-15 16:02:23 +07:00
|
|
|
"strings"
|
|
|
|
|
2024-08-13 14:26:19 +07:00
|
|
|
"github.com/aarondl/opt/omit"
|
2024-08-15 15:07:17 +07:00
|
|
|
"github.com/tigorlazuardi/bluemage/go/api"
|
2024-08-15 15:20:18 +07:00
|
|
|
"github.com/tigorlazuardi/bluemage/go/gen/jet/model"
|
2024-08-11 10:23:20 +07:00
|
|
|
"github.com/tigorlazuardi/bluemage/go/gen/models"
|
|
|
|
subreddits "github.com/tigorlazuardi/bluemage/go/gen/proto/subreddits/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// goverter:converter
|
2024-08-13 14:26:19 +07:00
|
|
|
// 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
|
2024-08-15 15:07:17 +07:00
|
|
|
// goverter:extend SubredditsDisabledFilterToPtrBool
|
2024-08-15 15:20:18 +07:00
|
|
|
// goverter:extend Int8ToSubredditDisabledFilter
|
|
|
|
// goverter:extend StringToSubredditType
|
2024-08-15 16:02:23 +07:00
|
|
|
// goverter:extend SubredditsOrderByToString
|
|
|
|
// goverter:extend SubredditsSortToString
|
2024-08-11 10:23:20 +07:00
|
|
|
type SubredditConverter interface {
|
2024-08-13 14:26:19 +07:00
|
|
|
// goverter:ignore CreatedAt UpdatedAt CoverImageID
|
|
|
|
CreateSubredditRequestToModelsSubredditSetter(*subreddits.CreateSubredditRequest) *models.SubredditSetter
|
2024-08-15 15:07:17 +07:00
|
|
|
|
|
|
|
// goverter:useZeroValueOnPointerInconsistency
|
|
|
|
ProtoCountSubredditsRequestToAPICountSubredditsRequest(*subreddits.CountSubredditsRequest) api.CountSubredditsRequest
|
2024-08-15 15:20:18 +07:00
|
|
|
|
|
|
|
// goverter:ignore state sizeCache unknownFields
|
|
|
|
// goverter:map CoverImageID CoverImageId
|
2024-08-15 16:02:23 +07:00
|
|
|
JetSubredditToProtoSubreddit(model.Subreddits) *subreddits.Subreddit
|
|
|
|
JetSubredditsToProtoSubreddits([]model.Subreddits) []*subreddits.Subreddit
|
|
|
|
|
|
|
|
// goverter:useZeroValueOnPointerInconsistency
|
|
|
|
ProtoListSubredditsRequestToAPIListSubredditsRequest(*subreddits.ListSubredditsRequest) api.ListSubredditsRequest
|
2024-08-11 10:23:20 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func SubredditTypeToString(subType subreddits.SubredditType) string {
|
|
|
|
if subType == subreddits.SubredditType_SUBREDDIT_TYPE_USER {
|
|
|
|
return "user"
|
|
|
|
}
|
|
|
|
return "r"
|
|
|
|
}
|
2024-08-13 14:26:19 +07:00
|
|
|
|
|
|
|
func SubredditTypeToOmitString(subType subreddits.SubredditType) omit.Val[string] {
|
|
|
|
if subType == subreddits.SubredditType_SUBREDDIT_TYPE_USER {
|
|
|
|
return omit.From("user")
|
|
|
|
}
|
2024-08-15 16:02:23 +07:00
|
|
|
|
2024-08-13 14:26:19 +07:00
|
|
|
return omit.From("r")
|
|
|
|
}
|
2024-08-15 15:07:17 +07:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-08-15 15:20:18 +07:00
|
|
|
|
|
|
|
func Int8ToSubredditDisabledFilter(i int8) subreddits.DisabledFilter {
|
|
|
|
if i == 1 {
|
|
|
|
return subreddits.DisabledFilter_DISABLED_FILTER_TRUE
|
|
|
|
}
|
|
|
|
return subreddits.DisabledFilter_DISABLED_FILTER_FALSE
|
|
|
|
}
|
|
|
|
|
|
|
|
func StringToSubredditType(s string) subreddits.SubredditType {
|
|
|
|
if s == "user" {
|
|
|
|
return subreddits.SubredditType_SUBREDDIT_TYPE_USER
|
|
|
|
}
|
|
|
|
return subreddits.SubredditType_SUBREDDIT_TYPE_SUBREDDIT
|
|
|
|
}
|
2024-08-15 16:02:23 +07:00
|
|
|
|
|
|
|
func SubredditsOrderByToString(order subreddits.OrderBy) string {
|
|
|
|
if order == subreddits.OrderBy_ORDER_BY_UNSPECIFIED {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
field, _ := strings.CutPrefix(subreddits.OrderBy_name[int32(order)], "ORDER_BY_")
|
|
|
|
field = strings.ToLower(field)
|
|
|
|
return field
|
|
|
|
}
|
|
|
|
|
|
|
|
func SubredditsSortToString(sort subreddits.Sort) api.Sort {
|
|
|
|
if sort == subreddits.Sort_SORT_DESCENDING {
|
|
|
|
return api.SortDesc
|
|
|
|
}
|
|
|
|
return api.SortAsc
|
|
|
|
}
|