From 6ea221da090f99ebeb723886e5a8263664f03ba1 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 1 Mar 2021 14:29:20 +0000 Subject: [PATCH] publish when a new post is created --- posts/handler/posts.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/posts/handler/posts.go b/posts/handler/posts.go index 93f0627..1ccc1ca 100644 --- a/posts/handler/posts.go +++ b/posts/handler/posts.go @@ -7,6 +7,7 @@ import ( "github.com/micro/micro/v3/service/errors" "github.com/micro/micro/v3/service/logger" "github.com/micro/micro/v3/service/model" + "github.com/micro/micro/v3/service" "github.com/gosimple/slug" proto "github.com/micro/services/posts/proto" @@ -130,6 +131,9 @@ func (p *Posts) savePost(ctx context.Context, oldPost, post *proto.Post) error { return err } if oldPost == nil { + // publish the post as an event + service.NewEvent("posts").Publish(ctx, post) + for _, tagName := range post.Tags { _, err := p.Tags.Add(ctx, &tags.AddRequest{ ResourceID: post.Id,