api: implemented get subreddit handler
This commit is contained in:
parent
c83387652b
commit
baf4ba686e
|
@ -3,6 +3,7 @@ package converts
|
|||
import (
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/tigorlazuardi/bluemage/go/api"
|
||||
"github.com/tigorlazuardi/bluemage/go/gen/jet/model"
|
||||
"github.com/tigorlazuardi/bluemage/go/gen/models"
|
||||
subreddits "github.com/tigorlazuardi/bluemage/go/gen/proto/subreddits/v1"
|
||||
)
|
||||
|
@ -27,12 +28,18 @@ import (
|
|||
// goverter:extend SubredditTypeToString
|
||||
// goverter:extend SubredditTypeToOmitString
|
||||
// goverter:extend SubredditsDisabledFilterToPtrBool
|
||||
// goverter:extend Int8ToSubredditDisabledFilter
|
||||
// goverter:extend StringToSubredditType
|
||||
type SubredditConverter interface {
|
||||
// goverter:ignore CreatedAt UpdatedAt CoverImageID
|
||||
CreateSubredditRequestToModelsSubredditSetter(*subreddits.CreateSubredditRequest) *models.SubredditSetter
|
||||
|
||||
// goverter:useZeroValueOnPointerInconsistency
|
||||
ProtoCountSubredditsRequestToAPICountSubredditsRequest(*subreddits.CountSubredditsRequest) api.CountSubredditsRequest
|
||||
|
||||
// goverter:ignore state sizeCache unknownFields
|
||||
// goverter:map CoverImageID CoverImageId
|
||||
JetSubredditToProtoGetSubredditResponse(model.Subreddits) *subreddits.Subreddit
|
||||
}
|
||||
|
||||
func SubredditTypeToString(subType subreddits.SubredditType) string {
|
||||
|
@ -58,3 +65,17 @@ func SubredditsDisabledFilterToPtrBool(filter subreddits.DisabledFilter) *bool {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -56,8 +56,16 @@ func (su *SubredditHandler) CreateSubreddit(ctx context.Context, request *connec
|
|||
// GetSubreddit returns a subreddit by its name.
|
||||
//
|
||||
// Returns error with connect.CodeNotFound if subreddit does not exist.
|
||||
func (su *SubredditHandler) GetSubreddit(_ context.Context, _ *connect.Request[subreddits.GetSubredditRequest]) (*connect.Response[subreddits.GetSubredditResponse], error) {
|
||||
panic("not implemented") // TODO: Implement
|
||||
func (su *SubredditHandler) GetSubreddit(ctx context.Context, request *connect.Request[subreddits.GetSubredditRequest]) (*connect.Response[subreddits.GetSubredditResponse], error) {
|
||||
data, err := su.API.GetSubreddit(ctx, request.Msg.Name)
|
||||
if err != nil {
|
||||
return nil, errs.IntoConnectError(err)
|
||||
}
|
||||
|
||||
resp := &subreddits.GetSubredditResponse{
|
||||
Subreddit: subredditConverter.JetSubredditToProtoGetSubredditResponse(data),
|
||||
}
|
||||
return connect.NewResponse(resp), nil
|
||||
}
|
||||
|
||||
// ListSubreddits returns a list of subreddits.
|
||||
|
|
|
@ -6,14 +6,14 @@ option go_package = "github.com/tigorlazuardi/bluemage/go/gen/proto/subreddits/v
|
|||
|
||||
message Subreddit {
|
||||
string name = 1;
|
||||
bool disable_scheduler = 2;
|
||||
bool disabled = 2;
|
||||
// type is never unspecified for this response.
|
||||
//
|
||||
// It's always either `SUBREDDIT_TYPE_SUBREDDIT`
|
||||
// or `SUBREDDIT_TYPE_USER`.
|
||||
SubredditType type = 3;
|
||||
string schedule = 4;
|
||||
uint32 countback = 5;
|
||||
int64 countback = 5;
|
||||
// cover_image_id is the id of an image that
|
||||
// acts as the cover for this subreddit.
|
||||
//
|
||||
|
@ -26,7 +26,7 @@ message Subreddit {
|
|||
// cover_image_id changes after every insert of
|
||||
// new images in that subreddit, so avoid
|
||||
// caching the image for too long.
|
||||
optional uint32 cover_image_id = 6;
|
||||
optional int32 cover_image_id = 6;
|
||||
int64 created_at = 7;
|
||||
int64 updated_at = 8;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue