Files
services/comments/handler/comments.go
Janos Dobronszki 40b71a9cf9 Autogenerate services.m3o.com (#37)
* Autogenerate services.m3o.com

* Openapi for all

* Gen

* Fix

* Whaat

* Fix dep

* Fix

* Hmm

* Install make

* Debug

* Debug 1

* Location -> locations

* Fix

* Intall protoc gen micro

* F

* F

* F

* Push

* Rename secret

* Fix npm install

* Fix script

* Fix v2

* Ignore errors

* Ignore v2

* F

* F

* F

* Docs index

* Add hugo theme

* Hugo tania fixes

* Change gen

* Change gen 2

* Install hugo

* Change gen

* Gen fix

* Change hugo install

* Change hugo install

* CNAME

* Change articles wording

* Tiny fix

* Fix gen

* Redoc it all

* Fix gen

* Fixing up protos

* Fix proto

* Fix gen

* Fix

* Trigger build

* Fix copy

* Openapi docs

* Flatten

* Changes

* No date vol2

* Changes

* Add make to chat

* Fixes

* Change

* api spec

* replace RSS

* fix link

* Dont continue on error

* increase the width

* use micro at master

* change box colours

* move some things

* Pushing new readmes to see how they look like

* Add skip file

* Readmes

* Nicer api link

* Remove stutter

* FIx mistake

* set service font weight

* Messages readme fix

* add other font bold

* Notes

* Remove post from url

* Revert "Remove post from url"

This reverts commit 5fea2c23d0bafa910f5dc4d4cc63f71f578530e3.

* move exampleSite to site

* replace exampleSite with site

* update readme

* use filename for post

* update index

* Add source urls

* set source as params

* set source as params

* Fix entries

* Generator in go

* Fixes to generator

* F

* Change doc gen

* FIx cname

* Fixing protos

* Change to makefiles

* Fix gen script

Co-authored-by: Asim Aslam <asim@aslam.me>
2021-01-19 16:59:25 +00:00

47 lines
1.1 KiB
Go

package handler
import (
"context"
"time"
"github.com/google/uuid"
"github.com/micro/dev/model"
"github.com/micro/micro/v3/service/store"
pb "github.com/micro/services/comments/proto"
)
type Comments struct {
comments model.Model
idIndex model.Index
postIndex model.Index
}
func NewComments() *Comments {
postIndex := model.ByEquality("post")
postIndex.Order.Type = model.OrderTypeDesc
postIndex.Order.FieldName = "created"
idIndex := model.ByEquality("id")
idIndex.Order.Type = model.OrderTypeUnordered
return &Comments{
comments: model.New(store.DefaultStore, "users", model.Indexes(postIndex), nil),
postIndex: postIndex,
idIndex: idIndex,
}
}
func (c *Comments) New(ctx context.Context, req *pb.NewRequest, rsp *pb.NewResponse) error {
return c.comments.Save(pb.Comment{
Id: uuid.New().String(),
Post: req.Post,
Author: req.Author,
Message: req.Message,
Created: time.Now().Unix(),
})
}
func (c *Comments) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListResponse) error {
return c.comments.List(c.postIndex.ToQuery(req.Post), &rsp.Comments)
}