-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backend changes for post read status sync #212
Conversation
server/resolver/resolver.go
Outdated
DB *gorm.DB | ||
SignalChans *SignalChannels | ||
DB *gorm.DB | ||
RedisClient *utils.RedisClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this initialized anywhere?
server/graph/schema.graphqls
Outdated
postsId: [String!]! | ||
} | ||
|
||
input GetPostsReadStatusInput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does user call GetPostsReadStatus
?
server/graph/schema.graphqls
Outdated
@@ -166,6 +177,8 @@ type Mutation { | |||
addWeiboSubSource(input: AddWeiboSubSourceInput!): SubSource | |||
|
|||
syncUp(input: SeedStateInput): SeedState | |||
|
|||
markPostsAsRead(input: MarkPostsAsReadInput!): Boolean! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to use Boolean! as return value. Error means incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ardatan/graphql-tools#277
I tried to return nothing but seems like graphql doesn't allow it so a boolean was a work around
server/graph/signal.graphqls
Outdated
@@ -3,9 +3,11 @@ enum SignalType { | |||
# Instruct client side to pull seed state. This is the first signal send to | |||
# client side application. | |||
SEED_STATE | |||
READ_POST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POST_READ_STATUS
server/resolver/signal.resolvers.go
Outdated
) | ||
|
||
func (r *signalResolver) SignalPayload(ctx context.Context, obj *model.Signal) (*string, error) { | ||
panic(fmt.Errorf("not implemented")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
You need to copy from obj to output string, otherwise you won;t access it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we need set unread functionality, I will change it from string to a struct
utils/redis_utils.go
Outdated
|
||
var ctx = context.Background() | ||
|
||
func GetRedisClient() *RedisClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this function accessed anywhere?
server/resolver/schema.resolvers.go
Outdated
err := r.RedisClient.MarkPostsAsRead(input.PostsID, input.UserID) | ||
if err != nil { | ||
return false, err | ||
} | ||
return true, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you push signal+payload to all end user sessions?
server/resolver/schema.resolvers.go
Outdated
@@ -455,3 +467,13 @@ func (r *Resolver) Subscription() generated.SubscriptionResolver { return &subsc | |||
type mutationResolver struct{ *Resolver } | |||
type queryResolver struct{ *Resolver } | |||
type subscriptionResolver struct{ *Resolver } | |||
|
|||
// !!! WARNING !!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this unused code
utils/redis_utils.go
Outdated
"github.com/go-redis/redis/v8" | ||
) | ||
|
||
type RedisClient struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is more like a "ReadStatusSotre" instead of Redis Client, maybe we can pass in a real redis client as a dependency, and keep only the business logic in this struct.
utils/redis_utils.go
Outdated
})} | ||
} | ||
|
||
func PostKey(userId string, postId string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap this in a struct and have a ser/deser API so we can extend and reuse in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fix test error? |
b3d419d
to
753d30a
Compare
model/post.go
Outdated
@@ -97,4 +97,5 @@ type Post struct { | |||
DeduplicateId string `json:"deduplicate_id"` | |||
SemanticHashing string `json:"semantic_hashing"` | |||
Tag string `json:"tag"` | |||
IsRead bool `json:"is_read" gorm:"-"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is "-"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://gorm.io/docs/models.html#Field-Level-Permission
It is an ignored field
No description provided.