remove: tenantslug
This commit is contained in:
@@ -19,5 +19,5 @@ func (e *PostCreated) Marshal() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (e *PostCreated) Topic() string {
|
||||
return events.TopicPostCreated.String()
|
||||
return events.TopicPostCreated
|
||||
}
|
||||
|
||||
23
backend/app/events/publishers/post_deleted.go
Normal file
23
backend/app/events/publishers/post_deleted.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package publishers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"backend/app/events"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
)
|
||||
|
||||
var _ contracts.EventPublisher = (*UserRegister)(nil)
|
||||
|
||||
type PostDeleted struct {
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
func (e *PostDeleted) Marshal() ([]byte, error) {
|
||||
return json.Marshal(e)
|
||||
}
|
||||
|
||||
func (e *PostDeleted) Topic() string {
|
||||
return events.TopicPostDeleted
|
||||
}
|
||||
23
backend/app/events/publishers/post_updated.go
Normal file
23
backend/app/events/publishers/post_updated.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package publishers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"backend/app/events"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
)
|
||||
|
||||
var _ contracts.EventPublisher = (*PostUpdatedEvent)(nil)
|
||||
|
||||
type PostUpdatedEvent struct {
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
func (e *PostUpdatedEvent) Marshal() ([]byte, error) {
|
||||
return json.Marshal(e)
|
||||
}
|
||||
|
||||
func (e *PostUpdatedEvent) Topic() string {
|
||||
return events.TopicPostUpdated
|
||||
}
|
||||
@@ -19,5 +19,5 @@ func (e *UserRegister) Marshal() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (e *UserRegister) Topic() string {
|
||||
return events.TopicUserRegister.String()
|
||||
return events.TopicUserRegister
|
||||
}
|
||||
|
||||
@@ -29,18 +29,18 @@ type PostCreated struct {
|
||||
}
|
||||
|
||||
func (e *PostCreated) Prepare() error {
|
||||
e.log = logrus.WithField("module", "events.subscribers.user_register")
|
||||
e.log = logrus.WithField("module", "events.subscribers.post_created")
|
||||
return nil
|
||||
}
|
||||
|
||||
// PublishToTopic implements contracts.EventHandler.
|
||||
func (e *PostCreated) PublishToTopic() string {
|
||||
return events.TopicProcessed.String()
|
||||
return events.TopicProcessed
|
||||
}
|
||||
|
||||
// Topic implements contracts.EventHandler.
|
||||
func (e *PostCreated) Topic() string {
|
||||
return events.TopicPostCreated.String()
|
||||
return events.TopicPostCreated
|
||||
}
|
||||
|
||||
// Handler implements contracts.EventHandler.
|
||||
@@ -66,8 +66,6 @@ func (e *PostCreated) Handler(msg *message.Message) ([]*message.Message, error)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_ = video
|
||||
|
||||
job, err := e.job.Client()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
60
backend/app/events/subscribers/post_deleted.go
Normal file
60
backend/app/events/subscribers/post_deleted.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package subscribers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"backend/app/events"
|
||||
"backend/app/events/publishers"
|
||||
"backend/app/http/posts"
|
||||
"backend/providers/job"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ contracts.EventHandler = (*PostDeleted)(nil)
|
||||
|
||||
// @provider(event)
|
||||
type PostDeleted struct {
|
||||
log *logrus.Entry `inject:"false"`
|
||||
|
||||
postSvc *posts.Service
|
||||
job *job.Job
|
||||
}
|
||||
|
||||
func (e *PostDeleted) Prepare() error {
|
||||
e.log = logrus.WithField("module", "events.subscribers.post_deleted")
|
||||
return nil
|
||||
}
|
||||
|
||||
// PublishToTopic implements contracts.EventHandler.
|
||||
func (e *PostDeleted) PublishToTopic() string {
|
||||
return events.TopicProcessed
|
||||
}
|
||||
|
||||
// Topic implements contracts.EventHandler.
|
||||
func (e *PostDeleted) Topic() string {
|
||||
return events.TopicPostDeleted
|
||||
}
|
||||
|
||||
// Handler implements contracts.EventHandler.
|
||||
func (e *PostDeleted) Handler(msg *message.Message) ([]*message.Message, error) {
|
||||
var payload publishers.PostDeleted
|
||||
err := json.Unmarshal(msg.Payload, &payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.log.Infof("received event %s", msg.Payload)
|
||||
|
||||
post, err := e.postSvc.ForceGetPostByID(context.Background(), payload.ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get item by id: %d", payload.ID)
|
||||
}
|
||||
_ = post
|
||||
// TODO: handle post deletion
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
48
backend/app/events/subscribers/post_updated.go
Normal file
48
backend/app/events/subscribers/post_updated.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package subscribers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"backend/app/events"
|
||||
"backend/app/events/publishers"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ contracts.EventHandler = (*PostUpdatedSubscriber)(nil)
|
||||
|
||||
// @provider(event)
|
||||
type PostUpdatedSubscriber struct {
|
||||
log *logrus.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
func (e *PostUpdatedSubscriber) Prepare() error {
|
||||
e.log = logrus.WithField("module", "events.subscribers.PostUpdatedSubscriber")
|
||||
return nil
|
||||
}
|
||||
|
||||
// PublishToTopic implements contracts.EventHandler.
|
||||
func (e *PostUpdatedSubscriber) PublishToTopic() string {
|
||||
return events.TopicProcessed
|
||||
}
|
||||
|
||||
// Topic implements contracts.EventHandler.
|
||||
func (e *PostUpdatedSubscriber) Topic() string {
|
||||
return events.TopicPostUpdated
|
||||
}
|
||||
|
||||
// Handler implements contracts.EventHandler.
|
||||
func (e *PostUpdatedSubscriber) Handler(msg *message.Message) ([]*message.Message, error) {
|
||||
var payload publishers.PostUpdatedEvent
|
||||
err := json.Unmarshal(msg.Payload, &payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.log.Infof("received event %s", msg.Payload)
|
||||
|
||||
// TODO: handle post deletion
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package subscribers
|
||||
|
||||
import (
|
||||
"backend/app/http/posts"
|
||||
"backend/app/http/users"
|
||||
"backend/providers/event"
|
||||
"backend/providers/job"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom"
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
@@ -11,6 +13,55 @@ import (
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func(
|
||||
__event *event.PubSub,
|
||||
job *job.Job,
|
||||
postSvc *posts.Service,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &PostCreated{
|
||||
job: job,
|
||||
postSvc: postSvc,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
__event.Handle("handler:PostCreated", obj.Topic(), obj.PublishToTopic(), obj.Handler)
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
__event *event.PubSub,
|
||||
job *job.Job,
|
||||
postSvc *posts.Service,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &PostDeleted{
|
||||
job: job,
|
||||
postSvc: postSvc,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
__event.Handle("handler:PostDeleted", obj.Topic(), obj.PublishToTopic(), obj.Handler)
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
__event *event.PubSub,
|
||||
) (contracts.Initial, error) {
|
||||
obj := &PostUpdatedSubscriber{}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
__event.Handle("handler:PostUpdatedSubscriber", obj.Topic(), obj.PublishToTopic(), obj.Handler)
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
__event *event.PubSub,
|
||||
userSvc *users.Service,
|
||||
|
||||
@@ -31,12 +31,12 @@ func (e *UserRegister) Prepare() error {
|
||||
|
||||
// PublishToTopic implements contracts.EventHandler.
|
||||
func (e *UserRegister) PublishToTopic() string {
|
||||
return events.TopicProcessed.String()
|
||||
return events.TopicProcessed
|
||||
}
|
||||
|
||||
// Topic implements contracts.EventHandler.
|
||||
func (e *UserRegister) Topic() string {
|
||||
return events.TopicUserRegister.String()
|
||||
return events.TopicUserRegister
|
||||
}
|
||||
|
||||
// Handler implements contracts.EventHandler.
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
// Code generated by go-enum DO NOT EDIT.
|
||||
// Version: -
|
||||
// Revision: -
|
||||
// Build Date: -
|
||||
// Built By: -
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// TopicProcessed is a Topic of type Processed.
|
||||
TopicProcessed Topic = "event:processed"
|
||||
// TopicUserRegister is a Topic of type UserRegister.
|
||||
TopicUserRegister Topic = "user:register"
|
||||
// TopicPostCreated is a Topic of type PostCreated.
|
||||
TopicPostCreated Topic = "post:created"
|
||||
)
|
||||
|
||||
var ErrInvalidTopic = fmt.Errorf("not a valid Topic, try [%s]", strings.Join(_TopicNames, ", "))
|
||||
|
||||
var _TopicNames = []string{
|
||||
string(TopicProcessed),
|
||||
string(TopicUserRegister),
|
||||
string(TopicPostCreated),
|
||||
}
|
||||
|
||||
// TopicNames returns a list of possible string values of Topic.
|
||||
func TopicNames() []string {
|
||||
tmp := make([]string, len(_TopicNames))
|
||||
copy(tmp, _TopicNames)
|
||||
return tmp
|
||||
}
|
||||
|
||||
// TopicValues returns a list of the values for Topic
|
||||
func TopicValues() []Topic {
|
||||
return []Topic{
|
||||
TopicProcessed,
|
||||
TopicUserRegister,
|
||||
TopicPostCreated,
|
||||
}
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (x Topic) String() string {
|
||||
return string(x)
|
||||
}
|
||||
|
||||
// IsValid provides a quick way to determine if the typed value is
|
||||
// part of the allowed enumerated values
|
||||
func (x Topic) IsValid() bool {
|
||||
_, err := ParseTopic(string(x))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
var _TopicValue = map[string]Topic{
|
||||
"event:processed": TopicProcessed,
|
||||
"user:register": TopicUserRegister,
|
||||
"post:created": TopicPostCreated,
|
||||
}
|
||||
|
||||
// ParseTopic attempts to convert a string to a Topic.
|
||||
func ParseTopic(name string) (Topic, error) {
|
||||
if x, ok := _TopicValue[name]; ok {
|
||||
return x, nil
|
||||
}
|
||||
return Topic(""), fmt.Errorf("%s is %w", name, ErrInvalidTopic)
|
||||
}
|
||||
|
||||
var errTopicNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (x *Topic) Scan(value interface{}) (err error) {
|
||||
if value == nil {
|
||||
*x = Topic("")
|
||||
return
|
||||
}
|
||||
|
||||
// A wider range of scannable types.
|
||||
// driver.Value values at the top of the list for expediency
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
*x, err = ParseTopic(v)
|
||||
case []byte:
|
||||
*x, err = ParseTopic(string(v))
|
||||
case Topic:
|
||||
*x = v
|
||||
case *Topic:
|
||||
if v == nil {
|
||||
return errTopicNilPtr
|
||||
}
|
||||
*x = *v
|
||||
case *string:
|
||||
if v == nil {
|
||||
return errTopicNilPtr
|
||||
}
|
||||
*x, err = ParseTopic(*v)
|
||||
default:
|
||||
return errors.New("invalid type for Topic")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x Topic) Value() (driver.Value, error) {
|
||||
return x.String(), nil
|
||||
}
|
||||
|
||||
// Set implements the Golang flag.Value interface func.
|
||||
func (x *Topic) Set(val string) error {
|
||||
v, err := ParseTopic(val)
|
||||
*x = v
|
||||
return err
|
||||
}
|
||||
|
||||
// Get implements the Golang flag.Getter interface func.
|
||||
func (x *Topic) Get() interface{} {
|
||||
return *x
|
||||
}
|
||||
|
||||
// Type implements the github.com/spf13/pFlag Value interface.
|
||||
func (x *Topic) Type() string {
|
||||
return "Topic"
|
||||
}
|
||||
|
||||
type NullTopic struct {
|
||||
Topic Topic
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func NewNullTopic(val interface{}) (x NullTopic) {
|
||||
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||
_ = err // make any errcheck linters happy
|
||||
return
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (x *NullTopic) Scan(value interface{}) (err error) {
|
||||
if value == nil {
|
||||
x.Topic, x.Valid = Topic(""), false
|
||||
return
|
||||
}
|
||||
|
||||
err = x.Topic.Scan(value)
|
||||
x.Valid = (err == nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x NullTopic) Value() (driver.Value, error) {
|
||||
if !x.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
// driver.Value accepts int64 for int values.
|
||||
return string(x.Topic), nil
|
||||
}
|
||||
|
||||
type NullTopicStr struct {
|
||||
NullTopic
|
||||
}
|
||||
|
||||
func NewNullTopicStr(val interface{}) (x NullTopicStr) {
|
||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x NullTopicStr) Value() (driver.Value, error) {
|
||||
if !x.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return x.Topic.String(), nil
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package events
|
||||
|
||||
// swagger:enum Topic
|
||||
// ENUM(
|
||||
//
|
||||
// Processed = "event:processed"
|
||||
// UserRegister = "user:register"
|
||||
// PostCreated = "post:created"
|
||||
//
|
||||
// )
|
||||
type Topic string
|
||||
const (
|
||||
TopicProcessed = "event:processed"
|
||||
TopicUserRegister = "user:register"
|
||||
TopicPostCreated = "post:created"
|
||||
TopicPostDeleted = "post:deleted"
|
||||
)
|
||||
const TopicPostUpdated = "post_updated"
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
)
|
||||
|
||||
var _ contracts.EventPublisher = (*UserRegister)(nil)
|
||||
|
||||
type UserRegister struct {
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
func (e *UserRegister) Prepare() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal implements contracts.EventPublisher.
|
||||
func (e *UserRegister) Marshal() ([]byte, error) {
|
||||
return json.Marshal(e)
|
||||
}
|
||||
|
||||
// Topic implements contracts.EventHandler.
|
||||
func (e *UserRegister) Topic() string {
|
||||
return TopicUserRegister.String()
|
||||
}
|
||||
Reference in New Issue
Block a user