From 78f9ad44221843b1341fca66c657468efb637f17 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Wed, 27 Jan 2021 16:46:26 +0000 Subject: [PATCH] Make posts service request timestamp field (#49) --- posts/handler/posts.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/posts/handler/posts.go b/posts/handler/posts.go index 4d9ba9b..c448633 100644 --- a/posts/handler/posts.go +++ b/posts/handler/posts.go @@ -61,10 +61,13 @@ func (p *Posts) Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.Sav Content: req.Content, Tags: req.Tags, Slug: postSlug, - Created: time.Now().Unix(), + Created: req.Timestamp, Metadata: req.Metadata, Image: req.Image, } + if post.Created == 0 { + post.Created = time.Now().Unix() + } err := p.savePost(ctx, nil, post) if err != nil { return errors.InternalServerError("proto.save.post-save", "Failed to save new post: %v", err.Error()) @@ -80,10 +83,13 @@ func (p *Posts) Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.Sav Slug: oldPost.Slug, Tags: oldPost.Tags, Created: oldPost.Created, - Updated: time.Now().Unix(), + Updated: req.Timestamp, Metadata: req.Metadata, Image: req.Image, } + if post.Created == 0 { + post.Created = time.Now().Unix() + } if len(req.Title) > 0 { post.Title = req.Title post.Slug = slug.Make(post.Title)